Rev 4618: Fix test_stacking tests for 2a as a default format. The change to 2a exposed some actual bugs, both in tests and bzrdir/branch code. in http://bazaar.launchpad.net/~lifeless/bzr/test_stacking

Robert Collins robertc at robertcollins.net
Mon Aug 17 07:17:27 BST 2009


At http://bazaar.launchpad.net/~lifeless/bzr/test_stacking

------------------------------------------------------------
revno: 4618
revision-id: robertc at robertcollins.net-20090817061721-ztcjftsbqx370uq6
parent: pqm at pqm.ubuntu.com-20090817003227-g813yyjlq47j9qyb
committer: Robert Collins <robertc at robertcollins.net>
branch nick: test_stacking
timestamp: Mon 2009-08-17 16:17:21 +1000
message:
  Fix test_stacking tests for 2a as a default format. The change to 2a exposed some actual bugs, both in tests and bzrdir/branch code.
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2009-08-13 20:10:26 +0000
+++ b/bzrlib/branch.py	2009-08-17 06:17:21 +0000
@@ -1147,6 +1147,9 @@
         revision_id: if not None, the revision history in the new branch will
                      be truncated to end with revision_id.
         """
+        if (repository_policy is not None and
+            repository_policy.requires_stacking()):
+            to_bzrdir._format.require_stacking(_skip_repo=True)
         result = to_bzrdir.create_branch()
         result.lock_write()
         try:

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2009-08-14 09:31:37 +0000
+++ b/bzrlib/bzrdir.py	2009-08-17 06:17:21 +0000
@@ -3549,6 +3549,10 @@
             if self._require_stacking:
                 raise
 
+    def requires_stacking(self):
+        """Return True if this policy requires stacking."""
+        return self._stack_on is not None and self._require_stacking
+
     def _get_full_stack_on(self):
         """Get a fully-qualified URL for the stack_on location."""
         if self._stack_on is None:

=== modified file 'bzrlib/tests/per_branch/__init__.py'
--- a/bzrlib/tests/per_branch/__init__.py	2009-07-10 10:46:00 +0000
+++ b/bzrlib/tests/per_branch/__init__.py	2009-08-17 06:17:21 +0000
@@ -78,7 +78,9 @@
         return self.branch
 
     def make_branch(self, relpath, format=None):
-        repo = self.make_repository(relpath, format=format)
+        if format is not None:
+            return TestCaseWithBzrDir.make_branch(self, relpath, format)
+        repo = self.make_repository(relpath)
         # fixme RBC 20060210 this isnt necessarily a fixable thing,
         # Skipped is the wrong exception to raise.
         try:

=== modified file 'bzrlib/tests/per_branch/test_stacking.py'
--- a/bzrlib/tests/per_branch/test_stacking.py	2009-08-14 13:55:30 +0000
+++ b/bzrlib/tests/per_branch/test_stacking.py	2009-08-17 06:17:21 +0000
@@ -278,14 +278,28 @@
         self.assertRaises((errors.NotStacked, errors.UnstackableBranchFormat),
                           cloned_bzrdir.open_branch().get_stacked_on_url)
 
+    def make_stacked_on_matching(self, source):
+        if source.repository.supports_rich_root():
+            if source.repository._format.supports_chks:
+                format = "2a"
+            else:
+                format = "1.9-rich-root"
+        else:
+            format = "1.9"
+        return self.make_branch('stack-on', format)
+
     def test_sprout_stacking_policy_handling(self):
         """Obey policy where possible, ignore otherwise."""
-        stack_on = self.make_branch('stack-on')
+        if isinstance(self.branch_format, branch.BzrBranchFormat4):
+            raise TestNotApplicable('Branch format 4 does not autoupgrade.')
+        source = self.make_branch('source')
+        stack_on = self.make_stacked_on_matching(source)
         parent_bzrdir = self.make_bzrdir('.', format='default')
         parent_bzrdir.get_config().set_default_stack_on('stack-on')
-        source = self.make_branch('source')
         target = source.bzrdir.sprout('target').open_branch()
-        if self.branch_format.supports_stacking():
+        # When we sprout we upgrade the branch when there is a default stack_on
+        # set by a config *and* the targeted branch supports stacking.
+        if stack_on._format.supports_stacking():
             self.assertEqual('../stack-on', target.get_stacked_on_url())
         else:
             self.assertRaises(
@@ -293,13 +307,17 @@
 
     def test_clone_stacking_policy_handling(self):
         """Obey policy where possible, ignore otherwise."""
+        if isinstance(self.branch_format, branch.BzrBranchFormat4):
+            raise TestNotApplicable('Branch format 4 does not autoupgrade.')
         self.thisFailsStrictLockCheck()
-        stack_on = self.make_branch('stack-on')
+        source = self.make_branch('source')
+        stack_on = self.make_stacked_on_matching(source)
         parent_bzrdir = self.make_bzrdir('.', format='default')
         parent_bzrdir.get_config().set_default_stack_on('stack-on')
-        source = self.make_branch('source')
         target = source.bzrdir.clone('target').open_branch()
-        if self.branch_format.supports_stacking():
+        # When we clone we upgrade the branch when there is a default stack_on
+        # set by a config *and* the targeted branch supports stacking.
+        if stack_on._format.supports_stacking():
             self.assertEqual('../stack-on', target.get_stacked_on_url())
         else:
             self.assertRaises(
@@ -309,13 +327,15 @@
         """Obey policy where possible, ignore otherwise."""
         if isinstance(self.branch_format, branch.BzrBranchFormat4):
             raise TestNotApplicable('Branch format 4 is not usable via HPSS.')
-        stack_on = self.make_branch('stack-on')
+        source = self.make_branch('source')
+        stack_on = self.make_stacked_on_matching(source)
         parent_bzrdir = self.make_bzrdir('.', format='default')
         parent_bzrdir.get_config().set_default_stack_on('stack-on')
-        source = self.make_branch('source')
         url = self.make_smart_server('target').base
         target = source.bzrdir.sprout(url).open_branch()
-        if self.branch_format.supports_stacking():
+        # When we sprout we upgrade the branch when there is a default stack_on
+        # set by a config *and* the targeted branch supports stacking.
+        if stack_on._format.supports_stacking():
             self.assertEqual('../stack-on', target.get_stacked_on_url())
         else:
             self.assertRaises(
@@ -352,10 +372,10 @@
         # repository boundaries.  however, i didn't actually get this test to
         # fail on that code. -- mbp
         # see https://bugs.launchpad.net/bzr/+bug/252821
-        if not self.branch_format.supports_stacking():
+        stack_on = self.make_branch_and_tree('stack-on')
+        if not stack_on.branch._format.supports_stacking():
             raise TestNotApplicable("%r does not support stacking"
                 % self.branch_format)
-        stack_on = self.make_branch_and_tree('stack-on')
         text_lines = ['line %d blah blah blah\n' % i for i in range(20)]
         self.build_tree_contents([('stack-on/a', ''.join(text_lines))])
         stack_on.add('a')




More information about the bazaar-commits mailing list