Rev 3579: Expose the branch building framework to the test suite. in http://bzr.arbash-meinel.com/branches/bzr/1.7-dev/branch_builder

John Arbash Meinel john at arbash-meinel.com
Tue Jul 22 20:21:57 BST 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.7-dev/branch_builder

------------------------------------------------------------
revno: 3579
revision-id: john at arbash-meinel.com-20080722192052-vc2cqzcih8j0lbct
parent: john at arbash-meinel.com-20080722190601-03b3otlcafrwpty5
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: branch_builder
timestamp: Tue 2008-07-22 14:20:52 -0500
message:
  Expose the branch building framework to the test suite.
  
  This way you can do 'self.make_branch_builder()' in lieu of all the other
  ways we used to do so.
-------------- next part --------------
=== modified file 'bzrlib/branchbuilder.py'
--- a/bzrlib/branchbuilder.py	2008-07-22 18:57:57 +0000
+++ b/bzrlib/branchbuilder.py	2008-07-22 19:20:52 +0000
@@ -47,8 +47,10 @@
             transport.mkdir('.')
         if format is None:
             format = 'default'
+        if isinstance(format, str):
+            format = bzrdir.format_registry.make_bzrdir(format)
         self._branch = bzrdir.BzrDir.create_branch_convenience(transport.base,
-            format=bzrdir.format_registry.make_bzrdir(format))
+            format=format)
 
     def build_commit(self):
         """Build a commit on the branch."""

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2008-07-21 08:58:33 +0000
+++ b/bzrlib/tests/__init__.py	2008-07-22 19:20:52 +0000
@@ -49,6 +49,7 @@
 
 
 from bzrlib import (
+    branchbuilder,
     bzrdir,
     debug,
     errors,
@@ -1993,6 +1994,11 @@
         b = self.make_branch(relpath, format=format)
         return memorytree.MemoryTree.create_on_branch(b)
 
+    def make_branch_builder(self, relpath, format=None):
+        url = self.get_url(relpath)
+        tran = get_transport(url)
+        return branchbuilder.BranchBuilder(get_transport(url), format=format)
+
     def overrideEnvironmentForTesting(self):
         os.environ['HOME'] = self.test_home_dir
         os.environ['BZR_HOME'] = self.test_home_dir

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2008-07-17 03:06:11 +0000
+++ b/bzrlib/tests/test_selftest.py	2008-07-22 19:20:52 +0000
@@ -26,6 +26,7 @@
 
 import bzrlib
 from bzrlib import (
+    branchbuilder,
     bzrdir,
     errors,
     memorytree,
@@ -547,6 +548,34 @@
         self.assertEqual(format.repository_format.__class__,
             tree.branch.repository._format.__class__)
 
+    def test_make_branch_builder(self):
+        builder = self.make_branch_builder('dir')
+        self.assertIsInstance(builder, branchbuilder.BranchBuilder)
+        # Guard against regression into MemoryTransport leaking
+        # files to disk instead of keeping them in memory.
+        self.failIf(osutils.lexists('dir'))
+
+    def test_make_branch_builder_with_format(self):
+        format = bzrdir.BzrDirMetaFormat1()
+        format.repository_format = weaverepo.RepositoryFormat7()
+        builder = self.make_branch_builder('dir', format=format)
+        the_branch = builder.get_branch()
+        # Guard against regression into MemoryTransport leaking
+        # files to disk instead of keeping them in memory.
+        self.failIf(osutils.lexists('dir'))
+        self.assertEqual(format.repository_format.__class__,
+                         the_branch.repository._format.__class__)
+
+    def test_make_branch_builder_with_format_name(self):
+        builder = self.make_branch_builder('dir', format='knit')
+        the_branch = builder.get_branch()
+        # Guard against regression into MemoryTransport leaking
+        # files to disk instead of keeping them in memory.
+        self.failIf(osutils.lexists('dir'))
+        dir_format = bzrdir.format_registry.make_bzrdir('knit')
+        self.assertEqual(dir_format.repository_format.__class__,
+                         the_branch.repository._format.__class__)
+
     def test_safety_net(self):
         """No test should modify the safety .bzr directory.
 



More information about the bazaar-commits mailing list