Rev 5036: Fix imports in test_branch.py. in file:///home/vila/src/bzr/cleanup/test-imports/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Feb 8 09:39:51 GMT 2010
At file:///home/vila/src/bzr/cleanup/test-imports/
------------------------------------------------------------
revno: 5036
revision-id: v.ladeuil+lp at free.fr-20100208093951-095sr8zw9sea5moc
parent: v.ladeuil+lp at free.fr-20100208092342-bbpu63xic0qiwy1f
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: test-imports
timestamp: Mon 2010-02-08 10:39:51 +0100
message:
Fix imports in test_branch.py.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py 2010-02-05 13:24:47 +0000
+++ b/bzrlib/tests/test_branch.py 2010-02-08 09:39:51 +0000
@@ -22,60 +22,49 @@
also see this file.
"""
-from StringIO import StringIO
+from cStringIO import StringIO
from bzrlib import (
branch as _mod_branch,
bzrdir,
config,
errors,
+ tests,
trace,
+ transport,
urlutils,
)
-from bzrlib.branch import (
- Branch,
- BranchHooks,
- BranchFormat,
- BranchReferenceFormat,
- BzrBranch5,
- BzrBranchFormat5,
- BzrBranchFormat6,
- BzrBranchFormat7,
- PullResult,
- _run_with_write_locked_target,
- )
-from bzrlib.bzrdir import (BzrDirMetaFormat1, BzrDirMeta1,
- BzrDir, BzrDirFormat)
-from bzrlib.transport import get_transport
class TestDefaultFormat(tests.TestCase):
def test_default_format(self):
# update this if you change the default branch format
- self.assertIsInstance(BranchFormat.get_default_format(),
- BzrBranchFormat7)
+ self.assertIsInstance(_mod_branch.BranchFormat.get_default_format(),
+ _mod_branch.BzrBranchFormat7)
def test_default_format_is_same_as_bzrdir_default(self):
# XXX: it might be nice if there was only one place the default was
# set, but at the moment that's not true -- mbp 20070814 --
# https://bugs.launchpad.net/bzr/+bug/132376
- self.assertEqual(BranchFormat.get_default_format(),
- BzrDirFormat.get_default_format().get_branch_format())
+ self.assertEqual(
+ _mod_branch.BranchFormat.get_default_format(),
+ bzrdir.BzrDirFormat.get_default_format().get_branch_format())
def test_get_set_default_format(self):
# set the format and then set it back again
- old_format = BranchFormat.get_default_format()
- BranchFormat.set_default_format(SampleBranchFormat())
+ old_format = _mod_branch.BranchFormat.get_default_format()
+ _mod_branch.BranchFormat.set_default_format(SampleBranchFormat())
try:
# the default branch format is used by the meta dir format
# which is not the default bzrdir format at this point
- dir = BzrDirMetaFormat1().initialize('memory:///')
+ dir = bzrdir.BzrDirMetaFormat1().initialize('memory:///')
result = dir.create_branch()
self.assertEqual(result, 'A branch')
finally:
- BranchFormat.set_default_format(old_format)
- self.assertEqual(old_format, BranchFormat.get_default_format())
+ _mod_branch.BranchFormat.set_default_format(old_format)
+ self.assertEqual(old_format,
+ _mod_branch.BranchFormat.get_default_format())
class TestBranchFormat5(tests.TestCaseWithTransport):
@@ -83,20 +72,18 @@
def test_branch_format_5_uses_lockdir(self):
url = self.get_url()
- bzrdir = BzrDirMetaFormat1().initialize(url)
- bzrdir.create_repository()
- branch = bzrdir.create_branch()
+ bdir = bzrdir.BzrDirMetaFormat1().initialize(url)
+ bdir.create_repository()
+ branch = bdir.create_branch()
t = self.get_transport()
self.log("branch instance is %r" % branch)
- self.assert_(isinstance(branch, BzrBranch5))
+ self.assert_(isinstance(branch, _mod_branch.BzrBranch5))
self.assertIsDirectory('.', t)
self.assertIsDirectory('.bzr/branch', t)
self.assertIsDirectory('.bzr/branch/lock', t)
branch.lock_write()
- try:
- self.assertIsDirectory('.bzr/branch/lock/held', t)
- finally:
- branch.unlock()
+ self.addCleanup(branch.unlock)
+ self.assertIsDirectory('.bzr/branch/lock/held', t)
def test_set_push_location(self):
from bzrlib.config import (locations_config_filename,
@@ -125,7 +112,7 @@
# recursive section - that is, it appends the branch name.
-class SampleBranchFormat(BranchFormat):
+class SampleBranchFormat(_mod_branch.BranchFormat):
"""A sample format
this format is initializable, unsupported to aid in testing the
@@ -161,21 +148,21 @@
dir = format._matchingbzrdir.initialize(url)
dir.create_repository()
format.initialize(dir)
- found_format = BranchFormat.find_format(dir)
+ found_format = _mod_branch.BranchFormat.find_format(dir)
self.failUnless(isinstance(found_format, format.__class__))
- check_format(BzrBranchFormat5(), "bar")
+ check_format(_mod_branch.BzrBranchFormat5(), "bar")
def test_find_format_not_branch(self):
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
self.assertRaises(errors.NotBranchError,
- BranchFormat.find_format,
+ _mod_branch.BranchFormat.find_format,
dir)
def test_find_format_unknown_format(self):
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
SampleBranchFormat().initialize(dir)
self.assertRaises(errors.UnknownFormatError,
- BranchFormat.find_format,
+ _mod_branch.BranchFormat.find_format,
dir)
def test_register_unregister_format(self):
@@ -185,17 +172,17 @@
# make a branch
format.initialize(dir)
# register a format for it.
- BranchFormat.register_format(format)
+ _mod_branch.BranchFormat.register_format(format)
# which branch.Open will refuse (not supported)
self.assertRaises(errors.UnsupportedFormatError,
- Branch.open, self.get_url())
+ _mod_branch.Branch.open, self.get_url())
self.make_branch_and_tree('foo')
# but open_downlevel will work
self.assertEqual(
format.open(dir),
bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True))
# unregister the format
- BranchFormat.unregister_format(format)
+ _mod_branch.BranchFormat.unregister_format(format)
self.make_branch_and_tree('bar')
@@ -212,7 +199,7 @@
raise NotImplementedError(self.get_class)
def test_creation(self):
- format = BzrDirMetaFormat1()
+ format = bzrdir.BzrDirMetaFormat1()
format.set_branch_format(_mod_branch.BzrBranchFormat6())
branch = self.make_branch('a', format=format)
self.assertIsInstance(branch, self.get_class())
@@ -433,7 +420,7 @@
branch.lock_write()
branch.set_reference_info('file-id', 'path2', 'location2')
branch.unlock()
- doppelganger = Branch.open('branch')
+ doppelganger = _mod_branch.Branch.open('branch')
doppelganger.set_reference_info('file-id', 'path3', 'location3')
self.assertEqual(('path3', 'location3'),
branch.get_reference_info('file-id'))
@@ -443,14 +430,15 @@
def test_create_open_reference(self):
bzrdirformat = bzrdir.BzrDirMetaFormat1()
- t = get_transport(self.get_url('.'))
+ t = transport.get_transport(self.get_url('.'))
t.mkdir('repo')
dir = bzrdirformat.initialize(self.get_url('repo'))
dir.create_repository()
target_branch = dir.create_branch()
t.mkdir('branch')
branch_dir = bzrdirformat.initialize(self.get_url('branch'))
- made_branch = BranchReferenceFormat().initialize(branch_dir, target_branch)
+ made_branch = _mod_branch.BranchReferenceFormat().initialize(
+ branch_dir, target_branch)
self.assertEqual(made_branch.base, target_branch.base)
opened_branch = branch_dir.open_branch()
self.assertEqual(opened_branch.base, target_branch.base)
@@ -471,13 +459,14 @@
def test_constructor(self):
"""Check that creating a BranchHooks instance has the right defaults."""
- hooks = BranchHooks()
+ hooks = _mod_branch.BranchHooks()
self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks)
self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
- self.assertTrue("post_uncommit" in hooks, "post_uncommit not in %s" % hooks)
+ self.assertTrue("post_uncommit" in hooks,
+ "post_uncommit not in %s" % hooks)
self.assertTrue("post_change_branch_tip" in hooks,
"post_change_branch_tip not in %s" % hooks)
@@ -485,14 +474,14 @@
"""The installed hooks object should be a BranchHooks."""
# the installed hooks are saved in self._preserved_hooks.
self.assertIsInstance(self._preserved_hooks[_mod_branch.Branch][1],
- BranchHooks)
+ _mod_branch.BranchHooks)
class TestPullResult(tests.TestCase):
def test_pull_result_to_int(self):
# to support old code, the pull result can be used as an int
- r = PullResult()
+ r = _mod_branch.PullResult()
r.old_revno = 10
r.new_revno = 20
# this usage of results is not recommended for new code (because it
@@ -502,7 +491,7 @@
self.assertEqual(a, "10 revisions pulled")
def test_report_changed(self):
- r = PullResult()
+ r = _mod_branch.PullResult()
r.old_revid = "old-revid"
r.old_revno = 10
r.new_revid = "new-revid"
@@ -512,7 +501,7 @@
self.assertEqual("Now on revision 20.\n", f.getvalue())
def test_report_unchanged(self):
- r = PullResult()
+ r = _mod_branch.PullResult()
r.old_revid = "same-revid"
r.new_revid = "same-revid"
f = StringIO()
@@ -561,7 +550,7 @@
def test_success_unlocks(self):
lockable = _StubLockable(self._calls)
- result = _run_with_write_locked_target(
+ result = _mod_branch._run_with_write_locked_target(
lockable, self.func_that_returns_ok)
self.assertEqual('ok', result)
self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
@@ -569,19 +558,22 @@
def test_exception_unlocks_and_propagates(self):
lockable = _StubLockable(self._calls)
self.assertRaises(_ErrorFromCallable,
- _run_with_write_locked_target, lockable, self.func_that_raises)
+ _mod_branch._run_with_write_locked_target,
+ lockable, self.func_that_raises)
self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
def test_callable_succeeds_but_error_during_unlock(self):
lockable = _StubLockable(self._calls, unlock_exc=_ErrorFromUnlock())
self.assertRaises(_ErrorFromUnlock,
- _run_with_write_locked_target, lockable, self.func_that_returns_ok)
+ _mod_branch._run_with_write_locked_target,
+ lockable, self.func_that_returns_ok)
self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
def test_error_during_unlock_does_not_mask_original_error(self):
lockable = _StubLockable(self._calls, unlock_exc=_ErrorFromUnlock())
self.assertRaises(_ErrorFromCallable,
- _run_with_write_locked_target, lockable, self.func_that_raises)
+ _mod_branch._run_with_write_locked_target,
+ lockable, self.func_that_raises)
self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
More information about the bazaar-commits
mailing list