Rev 4882: Cleanup tests and tweak the text displayed. in file:///home/vila/src/bzr/reviews/update-feedback/

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon Dec 14 15:51:36 GMT 2009


At file:///home/vila/src/bzr/reviews/update-feedback/

------------------------------------------------------------
revno: 4882
revision-id: v.ladeuil+lp at free.fr-20091214155136-rf4nkqvxda9oiw4u
parent: nmb at wartburg.edu-20091214030108-xvyzwqptc1136fxy
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: update-feedback
timestamp: Mon 2009-12-14 16:51:36 +0100
message:
  Cleanup tests and tweak the text displayed.
  
  * bzrlib/tests/blackbox/test_update.py:
  Fix imports and replace the assertContainsRe with assertEqualDiff
  to make the test clearer, more robust and easier to debug.
  
  * bzrlib/tests/commands/test_update.py: 
  Fix imports.
  
  * bzrlib/tests/blackbox/test_filtered_view_ops.py: 
  Fix imports and strange accesses to base class methods.
  (TestViewTreeOperations.test_view_on_update): Avoid os.chdir()
  call, simplify string matching assertions.
  
  * bzrlib/builtins.py:
  (cmd_update.run): Fix spurious space, get rid of the final '/' for
  the base path, don't add a final period (it's a legal char in a
  path and would be annoying for people that like to copy/paste).
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-12-12 20:07:06 +0000
+++ b/bzrlib/builtins.py	2009-12-14 15:51:36 +0000
@@ -1404,7 +1404,8 @@
         else:
             tree.lock_tree_write()
             branch_location = tree.branch.base
-        branch_location = urlutils.unescape_for_display(branch_location,
+        # get rid of the final '/' and be ready for display
+        branch_location = urlutils.unescape_for_display(branch_location[:-1],
                                                         self.outf.encoding)
         try:
             existing_pending_merges = tree.get_parent_ids()[1:]
@@ -1415,8 +1416,8 @@
                 if master is None or last_rev == _mod_revision.ensure_null(
                     master.last_revision()):
                     revno = tree.branch.revision_id_to_revno(last_rev)
-                    note("Tree is up to date at revision %d of branch %s." % 
-                         (revno, branch_location))
+                    note('Tree is up to date at revision %d of branch %s'
+                         % (revno, branch_location))
                     return 0
             view_info = _get_view_info_for_change_reporter(tree)
             conflicts = tree.update(
@@ -1424,7 +1425,7 @@
                 view_info=view_info), possible_transports=possible_transports)
             revno = tree.branch.revision_id_to_revno(
                 _mod_revision.ensure_null(tree.last_revision()))
-            note('Updated to revision %d of branch %s.' %
+            note('Updated to revision %d of branch %s' %
                  (revno, branch_location))
             if tree.get_parent_ids()[1:] != existing_pending_merges:
                 note('Your local commits will now show as pending merges with '

=== modified file 'bzrlib/tests/blackbox/test_filtered_view_ops.py'
--- a/bzrlib/tests/blackbox/test_filtered_view_ops.py	2009-12-12 20:07:06 +0000
+++ b/bzrlib/tests/blackbox/test_filtered_view_ops.py	2009-12-14 15:51:36 +0000
@@ -18,19 +18,20 @@
 
 import os
 
-from bzrlib import bzrdir
-from bzrlib.tests import TestCaseWithTransport
-from bzrlib.workingtree import WorkingTree
-
-
-class TestViewFileOperations(TestCaseWithTransport):
+from bzrlib import (
+    bzrdir,
+    osutils,
+    tests,
+    )
+
+
+class TestViewFileOperations(tests.TestCaseWithTransport):
 
     def make_abc_tree_with_ab_view(self):
         # we need to use a specific format because the default format
         # doesn't support views yet
         format = bzrdir.format_registry.make_bzrdir('development6-rich-root')
-        wt = TestCaseWithTransport.make_branch_and_tree(self, '.',
-            format=format)
+        wt = self.make_branch_and_tree( '.', format=format)
         self.build_tree(['a', 'b', 'c'])
         wt.views.set_view('my', ['a', 'b'])
         return wt
@@ -152,15 +153,14 @@
         self.assertEquals('b', out_lines[1])
 
 
-class TestViewTreeOperationss(TestCaseWithTransport):
+class TestViewTreeOperations(tests.TestCaseWithTransport):
 
     def make_abc_tree_and_clone_with_ab_view(self):
         # we need to use a specific format because the default format
         # doesn't support views yet
         format = bzrdir.format_registry.make_bzrdir('development6-rich-root')
         # Build the first tree
-        wt1 = TestCaseWithTransport.make_branch_and_tree(self, 'tree_1',
-            format=format)
+        wt1 = self.make_branch_and_tree('tree_1', format=format)
         self.build_tree(['tree_1/a', 'tree_1/b', 'tree_1/c'])
         wt1.add(['a', 'b', 'c'])
         wt1.commit("adding a b c")
@@ -186,15 +186,16 @@
 
     def test_view_on_update(self):
         tree_1, tree_2 = self.make_abc_tree_and_clone_with_ab_view()
-        os.chdir("tree_2")
-        self.run_bzr("bind ../tree_1")
-        out, err = self.run_bzr('update')
-        self.assertStartsWith(err, 
-            "Operating on whole tree but only reporting on 'my' view.\n"
-            " M  a\n"
-            "All changes applied successfully.\n")
-        self.assertContainsRe(err, "Updated to revision 2 of branch .*.")
-        self.assertEqualDiff("", out)
+        self.run_bzr("bind ../tree_1", working_dir='tree_2')
+        out, err = self.run_bzr('update', working_dir='tree_2')
+        self.assertEqualDiff(
+            """Operating on whole tree but only reporting on 'my' view.
+ M  a
+All changes applied successfully.
+Updated to revision 2 of branch %s
+""" % osutils.pathjoin(self.test_dir, 'tree_1'),
+            err)
+        self.assertEqual("", out)
 
     def test_view_on_merge(self):
         tree_1, tree_2 = self.make_abc_tree_and_clone_with_ab_view()
@@ -203,4 +204,4 @@
             "Operating on whole tree but only reporting on 'my' view.\n"
             " M  a\n"
             "All changes applied successfully.\n", err)
-        self.assertEqualDiff("", out)
+        self.assertEqual("", out)

=== modified file 'bzrlib/tests/blackbox/test_update.py'
--- a/bzrlib/tests/blackbox/test_update.py	2009-12-14 03:01:08 +0000
+++ b/bzrlib/tests/blackbox/test_update.py	2009-12-14 15:51:36 +0000
@@ -18,21 +18,27 @@
 
 """Tests for the update command of bzr."""
 
-import os, re
-
-from bzrlib import branch, bzrdir
-from bzrlib.tests.blackbox import ExternalBase
-from bzrlib.workingtree import WorkingTree
-from bzrlib.osutils import pathjoin
-
-
-class TestUpdate(ExternalBase):
+import os
+import re
+
+from bzrlib import (
+    branch,
+    bzrdir,
+    osutils,
+    tests,
+    urlutils,
+    workingtree,
+    )
+
+
+class TestUpdate(tests.TestCaseWithTransport):
 
     def test_update_standalone_trivial(self):
         self.make_branch_and_tree('.')
         out, err = self.run_bzr('update')
-        self.assertContainsRe(err, 'Tree is up to date at revision 0'
-                                   ' of branch %s.' % re.escape(self.test_dir))
+        self.assertEqual(
+            'Tree is up to date at revision 0 of branch %s\n' % self.test_dir,
+            err)
         self.assertEqual('', out)
 
     def test_update_quiet(self):
@@ -44,26 +50,27 @@
     def test_update_standalone_trivial_with_alias_up(self):
         self.make_branch_and_tree('.')
         out, err = self.run_bzr('up')
-        self.assertContainsRe(err, 'Tree is up to date at revision 0'
-                                   ' of branch %s.' % re.escape(self.test_dir))
+        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
+                         % self.test_dir,
+                         err)
         self.assertEqual('', out)
 
     def test_update_up_to_date_light_checkout(self):
         self.make_branch_and_tree('branch')
         self.run_bzr('checkout --lightweight branch checkout')
         out, err = self.run_bzr('update checkout')
-        branch_path = pathjoin(self.test_dir, 'branch/')
-        self.assertContainsRe(err, 'Tree is up to date at revision 0'
-                                   ' of branch %s.' % re.escape(branch_path))
+        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
+                         % osutils.pathjoin(self.test_dir, 'branch'),
+                         err)
         self.assertEqual('', out)
 
     def test_update_up_to_date_checkout(self):
         self.make_branch_and_tree('branch')
         self.run_bzr('checkout branch checkout')
         out, err = self.run_bzr('update checkout')
-        branch_path = pathjoin(self.test_dir, 'branch/')
-        self.assertContainsRe(err, 'Tree is up to date at revision 0'
-                                   ' of branch %s.' % re.escape(branch_path))
+        self.assertEqual('Tree is up to date at revision 0 of branch %s\n'
+                         % osutils.pathjoin(self.test_dir, 'branch'),
+                         err)
         self.assertEqual('', out)
 
     def test_update_out_of_date_standalone_tree(self):
@@ -78,11 +85,11 @@
         # now branch should be out of date
         out,err = self.run_bzr('update branch')
         self.assertEqual('', out)
-        self.assertContainsRe(err, '\+N  file')
-        self.assertContainsRe(err, 'All changes applied successfully.')
-        branch_path = pathjoin(self.test_dir, 'branch/')
-        self.assertContainsRe(err, 'Updated to revision 1 of branch %s.' %
-                                    re.escape(branch_path))
+        self.assertEqualDiff("""+N  file
+All changes applied successfully.
+Updated to revision 1 of branch %s
+""" % osutils.pathjoin(self.test_dir, 'branch',),
+                         err)
         self.failUnlessExists('branch/file')
 
     def test_update_out_of_date_light_checkout(self):
@@ -95,11 +102,11 @@
         self.run_bzr('commit -m add-file checkout')
         # now checkout2 should be out of date
         out,err = self.run_bzr('update checkout2')
-        self.assertContainsRe(err, '\+N  file')
-        self.assertContainsRe(err, r'All changes applied successfully\.')
-        branch_path = pathjoin(self.test_dir, 'branch/')
-        self.assertContainsRe(err, r'Updated to revision 1 of branch %s.' %
-                                     re.escape(branch_path))
+        self.assertEqualDiff('''+N  file
+All changes applied successfully.
+Updated to revision 1 of branch %s
+''' % osutils.pathjoin(self.test_dir, 'branch',),
+                         err)
         self.assertEqual('', out)
 
     def test_update_conflicts_returns_2(self):
@@ -121,12 +128,12 @@
         a_file.write('Bar')
         a_file.close()
         out,err = self.run_bzr('update checkout2', retcode=1)
-        self.assertContainsRe(err, 'M  file')
-        self.assertContainsRe(err, '1 conflicts encountered.')
-        branch_path = pathjoin(self.test_dir, 'branch/')
-        self.assertContainsRe(err, 'Updated to revision 2 of branch %s.' %
-                                    re.escape(branch_path))
-        self.assertContainsRe(err, 'Text conflict in file\n')
+        self.assertEqualDiff(''' M  file
+Text conflict in file
+1 conflicts encountered.
+Updated to revision 2 of branch %s
+''' % osutils.pathjoin(self.test_dir, 'branch',),
+                         err)
         self.assertEqual('', out)
 
     def test_smoke_update_checkout_bound_branch_local_commits(self):
@@ -136,11 +143,11 @@
         # make a bound branch
         self.run_bzr('checkout master child')
         # get an object form of child
-        child = WorkingTree.open('child')
+        child = workingtree.WorkingTree.open('child')
         # check that out
         self.run_bzr('checkout --lightweight child checkout')
         # get an object form of the checkout to manipulate
-        wt = WorkingTree.open('checkout')
+        wt = workingtree.WorkingTree.open('checkout')
         # change master
         a_file = file('master/file', 'wt')
         a_file.write('Foo')
@@ -163,13 +170,14 @@
         # get all three files and a pending merge.
         out, err = self.run_bzr('update checkout')
         self.assertEqual('', out)
-        self.assertContainsRe(err, '\+N  file')
-        self.assertContainsRe(err, '\+N  file_b')
-        branch_path = pathjoin(self.test_dir, 'master/')
-        self.assertContainsRe(err, 'Updated to revision 1 of branch %s.' %
-                                    re.escape(branch_path))
-        self.assertContainsRe(err, 'Your local commits will now show as'
-                                   ' pending merges')
+        self.assertEqualDiff("""+N  file
+All changes applied successfully.
++N  file_b
+All changes applied successfully.
+Updated to revision 1 of branch %s
+Your local commits will now show as pending merges with 'bzr status', and can be committed with 'bzr commit'.
+""" % osutils.pathjoin(self.test_dir, 'master',),
+                         err)
         self.assertEqual([master_tip, child_tip], wt.get_parent_ids())
         self.failUnlessExists('checkout/file')
         self.failUnlessExists('checkout/file_b')
@@ -215,11 +223,11 @@
         # merges, because they were real merges
         out, err = self.run_bzr('update')
         self.assertEqual('', out)
-        self.assertContainsRe(err, 'All changes applied successfully.')
-        branch_path = pathjoin(self.test_dir, 'master/')
-        self.assertContainsRe(err, 'Updated to revision 2 of branch %s.' %
-                                    re.escape(branch_path))
-        self.assertContainsRe(err, r'\+N  file3')
+        self.assertEqualDiff('''+N  file3
+All changes applied successfully.
+Updated to revision 2 of branch %s
+''' % osutils.pathjoin(self.test_dir, 'master',),
+                         err)
         # The pending merges should still be there
         self.assertEqual(['o2'], checkout1.get_parent_ids()[1:])
 

=== modified file 'bzrlib/tests/commands/test_update.py'
--- a/bzrlib/tests/commands/test_update.py	2009-12-12 20:07:06 +0000
+++ b/bzrlib/tests/commands/test_update.py	2009-12-14 15:51:36 +0000
@@ -18,8 +18,9 @@
 from bzrlib import (
     branch,
     builtins,
+    tests,
     )
-from bzrlib.tests import transport_util, StringIOWrapper
+from bzrlib.tests import transport_util
 
 
 class TestUpdate(transport_util.TestCaseWithConnectionHookedTransport):
@@ -37,7 +38,7 @@
 
         update = builtins.cmd_update()
         # update needs the encoding from outf to print URLs
-        update.outf = StringIOWrapper()
+        update.outf = tests.StringIOWrapper()
         # update calls it 'dir' where other commands calls it 'directory'
         update.run(dir='local')
         self.assertEquals(1, len(self.connections))



More information about the bazaar-commits mailing list