Rev 4489: Add tests for push --strict against pending merges. in file:///home/vila/src/bzr/bugs/284038-push-strict/

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon Jun 29 08:42:15 BST 2009


At file:///home/vila/src/bzr/bugs/284038-push-strict/

------------------------------------------------------------
revno: 4489
revision-id: v.ladeuil+lp at free.fr-20090629074215-20obt2o5l57cvq72
parent: v.ladeuil+lp at free.fr-20090629071423-j2z48i7oy3mv1vig
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 284038-push-strict
timestamp: Mon 2009-06-29 09:42:15 +0200
message:
  Add tests for push --strict against pending merges.
  
  * tests/blackbox/test_push.py:
  (load_tests): Test push --strict for uncommitted changes and
  pending merges.
  (TestPushStrict): Helpers for --strict option tests.
  (TestPushStrictWithoutChanges, TestPushStrictWithChanges): Test
  the --strict option.
-------------- next part --------------
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py	2009-06-29 07:14:23 +0000
+++ b/bzrlib/tests/blackbox/test_push.py	2009-06-29 07:42:15 +0000
@@ -35,6 +35,28 @@
 from bzrlib.transport import memory
 
 
+def load_tests(standard_tests, module, loader):
+    """Multiply tests for the push command."""
+    result = loader.suiteClass()
+
+    # one for each king of change
+    changes_tests, remaining_tests = tests.split_suite_by_condition(
+        standard_tests, tests.condition_isinstance((
+                TestPushStrictWithChanges,
+                )))
+    changes_scenarios = [
+        ('uncommitted',
+         dict(_do_changes= TestPushStrictWithChanges.do_uncommitted_changes)),
+        ('pending_merges',
+         dict(_do_changes= TestPushStrictWithChanges.do_pending_merges)),
+        ]
+    tests.multiply_tests(changes_tests, changes_scenarios, result)
+    # No parametrization for the remaining tests
+    result.addTests(remaining_tests)
+
+    return result
+
+
 class TestPush(tests.TestCaseWithTransport):
 
     def test_push_error_on_vfs_http(self):
@@ -569,72 +591,108 @@
 class TestPushStrict(tests.TestCaseWithTransport):
 
     def make_local_branch_and_tree(self):
-        tree = self.make_branch_and_tree('local')
+        self.tree = self.make_branch_and_tree('local')
         self.build_tree_contents([('local/file', 'initial')])
-        tree.add('file')
-        tree.commit('adding file', rev_id='from-1')
-        return tree
-
-    def make_local_branch_and_tree_with_changes(self):
-        tree = self.make_local_branch_and_tree()
-        # Make some changes
-        self.build_tree_contents([('local/file', 'modified')])
-        return tree
-
-    def set_config_push_strict(self, tree, value):
+        self.tree.add('file')
+        self.tree.commit('adding file', rev_id='from-1')
+
+    def set_config_push_strict(self, value):
         # set config var (any of bazaar.conf, locations.conf, branch.conf
         # should do)
-        conf = tree.branch.get_config()
+        conf = self.tree.branch.get_config()
         conf.set_user_option('push_strict', value)
 
-    def assertPushFails(self, location, *args):
+    def assertPushFails(self, args):
         self.run_bzr_error(['Working tree ".*/local/"'
                             ' has uncommitted changes.$',],
-                           ['push', '../' + location] + list(args),
+                           ['push', '../to'] + args,
                            working_dir='local', retcode=3)
 
-    def assertPushSucceeds(self, location, *args):
-        self.run_bzr(['push', '../' + location] + list(args),
+    def assertPushSucceeds(self, args):
+        self.run_bzr(['push', '../to'] + args,
                      working_dir='local')
-        tree_to = workingtree.WorkingTree.open(location)
+        tree_to = workingtree.WorkingTree.open('to')
         repo_to = tree_to.branch.repository
         self.assertTrue(repo_to.has_revision('from-1'))
         self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
 
-    def test_push_default(self):
-        tree = self.make_local_branch_and_tree_with_changes()
-        self.assertPushFails('to')
+
+
+class TestPushStrictWithoutChanges(TestPushStrict):
+
+    def setUp(self):
+        super(TestPushStrictWithoutChanges, self).setUp()
+        self.make_local_branch_and_tree()
+
+    def test_push_default(self):
+        self.assertPushSucceeds([])
+
+    def test_push_strict(self):
+        self.assertPushSucceeds(['--strict'])
+
+    def test_push_no_strict(self):
+        self.assertPushSucceeds(['--no-strict'])
+
+    def test_push_config_var_strict(self):
+        self.set_config_push_strict('true')
+        self.assertPushSucceeds([])
+
+    def test_push_config_var_no_strict(self):
+        self.set_config_push_strict('false')
+        self.assertPushSucceeds([])
+
+
+class TestPushStrictWithChanges(TestPushStrict):
+
+    _do_changes = None # Set by load_tests
+
+    def setUp(self):
+        super(TestPushStrictWithChanges, self).setUp()
+        # FIXME: The following is a bit ugly, but I don't know how to bind the
+        # method properly, yet I want to define the method to call in
+        # load_tests(). -- vila 20090626
+        self._do_changes(self)
+
+    def do_uncommitted_changes(self):
+        self.make_local_branch_and_tree()
+        # Make a change without committing it
+        self.build_tree_contents([('local/file', 'modified')])
+
+    def do_pending_merges(self):
+        self.make_local_branch_and_tree()
+        # Create 'other' branch containing a new file
+        other_bzrdir = self.tree.bzrdir.sprout('other')
+        other_tree = other_bzrdir.open_workingtree()
+        self.build_tree_contents([('other/other-file', 'other')])
+        other_tree.add('other-file')
+        other_tree.commit('other commit', rev_id='other')
+        # Merge and revert, leaving a pending merge
+        self.tree.merge_from_branch(other_tree.branch)
+        self.tree.revert(filenames=['other-file'], backups=False)
+
+    def test_push_default(self):
+        self.assertPushFails([])
 
     def test_push_no_strict_with_changes(self):
-        tree = self.make_local_branch_and_tree_with_changes()
-        self.assertPushSucceeds('to', '--no-strict')
+        self.assertPushSucceeds(['--no-strict'])
 
     def test_push_strict_with_changes(self):
-        tree = self.make_local_branch_and_tree_with_changes()
-        self.assertPushFails('to', '--strict')
-
-    def test_push_strict_without_changes(self):
-        tree = self.make_local_branch_and_tree()
-        self.assertPushSucceeds('to', '--strict')
+        self.assertPushFails(['--strict'])
 
     def test_push_respect_config_var_strict(self):
-        tree = self.make_local_branch_and_tree_with_changes()
-        self.set_config_push_strict(tree, 'true')
-        self.assertPushFails('to')
+        self.set_config_push_strict('true')
+        self.assertPushFails([])
 
     def test_push_bogus_config_var_ignored(self):
-        tree = self.make_local_branch_and_tree_with_changes()
-        self.set_config_push_strict(tree, "I don't want you to be strict")
-        self.assertPushFails('to')
+        self.set_config_push_strict("I don't want you to be strict")
+        self.assertPushFails([])
 
     def test_push_no_strict_command_line_override_config(self):
-        tree = self.make_local_branch_and_tree_with_changes()
-        self.set_config_push_strict(tree, 'yES')
-        self.assertPushFails('to')
-        self.assertPushSucceeds('to', '--no-strict')
+        self.set_config_push_strict('yES')
+        self.assertPushFails([])
+        self.assertPushSucceeds(['--no-strict'])
 
     def test_push_strict_command_line_override_config(self):
-        tree = self.make_local_branch_and_tree_with_changes()
-        self.set_config_push_strict(tree, 'oFF')
-        self.assertPushFails('to', '--strict')
-        self.assertPushSucceeds('to')
+        self.set_config_push_strict('oFF')
+        self.assertPushFails(['--strict'])
+        self.assertPushSucceeds([])



More information about the bazaar-commits mailing list