Rev 2521: Fix test suite to provide a better debugging experience. in file:///v/home/vila/src/experimental/reuse.transports/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Jun 6 09:42:09 BST 2007
At file:///v/home/vila/src/experimental/reuse.transports/
------------------------------------------------------------
revno: 2521
revision-id: v.ladeuil+lp at free.fr-20070606084207-6fa0f02eadtezlrf
parent: v.ladeuil+lp at free.fr-20070605155212-k2za98dhobeikxhn
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: reuse.transports
timestamp: Wed 2007-06-06 10:42:07 +0200
message:
Fix test suite to provide a better debugging experience.
* bzrlib/tests/TransportUtil.py:
(TestCaseWithConnectionHookedTransport.setUp.cleanup): hooks are
installed on demand but always reset if installed.
(TestCaseWithConnectionHookedTransport.install_hooks,
TestCaseWithConnectionHookedTransport.reset_hooks): New methods
giving a finer control on when hooks are active.
* bzrlib/tests/commands/test_push.py:
(TestPush.test_push): Install hooks when necessary.
* bzrlib/tests/commands/test_pull.py:
(TestPull.test_pull): Install hooks when necessary.
* bzrlib/tests/commands/test_missing.py:
(TestMissing.test_missing): Install hooks when necessary.
* bzrlib/tests/commands/test_merge.py:
(TestMerge.test_merge): Install hooks when necessary.
* bzrlib/tests/commands/test_init_repository.py:
(TestInitRepository.setUp): Install hooks when necessary.
* bzrlib/tests/commands/test_init.py:
(TestInit.setUp): Install hooks when necessary.
* bzrlib/tests/commands/test_checkout.pyL
(TestCheckout.test_checkout): Install hooks when necessary.
* bzrlib/tests/commands/test_cat.py:
(TestCat.test_cat): Install hooks when necessary.
* bzrlib/tests/commands/test_branch.py:
(TestBranch.setUp): Install hooks when necessary.
modified:
bzrlib/tests/TransportUtil.py transportutil.py-20070525113600-5v2igk89s8fensom-1
bzrlib/tests/commands/test_branch.py test_branch.py-20070520173042-ou3a796w3xn1y8ps-1
bzrlib/tests/commands/test_cat.py test_cat.py-20070525170351-vg2apsfb5j413913-1
bzrlib/tests/commands/test_checkout.py test_checkout.py-20070525151718-vm7ligd5px5dtmda-1
bzrlib/tests/commands/test_init.py test_init.py-20070514074921-audbcdd8o56dpame-1
bzrlib/tests/commands/test_init_repository.py test_init_repository-20070525163812-87xw0678ky573l27-1
bzrlib/tests/commands/test_merge.py test_merge.py-20070525163813-v8yfs5wu77hjsx0o-1
bzrlib/tests/commands/test_missing.py test_missing.py-20070525171057-qr1z4sleurlp9b5v-1
bzrlib/tests/commands/test_pull.py test_pull.py-20070525144918-cgmunk4ici2krjnd-1
bzrlib/tests/commands/test_push.py test_push.py-20070525122003-gc1ob0ea0nueoqgj-1
-------------- next part --------------
=== modified file 'bzrlib/tests/TransportUtil.py'
--- a/bzrlib/tests/TransportUtil.py 2007-06-03 15:52:19 +0000
+++ b/bzrlib/tests/TransportUtil.py 2007-06-06 08:42:07 +0000
@@ -55,17 +55,27 @@
def setUp(self):
super(TestCaseWithConnectionHookedTransport, self).setUp()
+ self._hooks_installed = False
+
+ def cleanup():
+ # Be nice and reset hooks if the test writer forgot about them
+ if self._hooks_installed:
+ self.reset_hooks()
+
+ self.addCleanup(cleanup)
+ self.connections = []
+
+ def install_hooks(self):
ConnectionHookedTransport.hooks.install_hook('_set_connection',
self.set_connection_hook)
# Make our instrumented transport the default ftp transport
register_transport('ftp://', ConnectionHookedTransport)
-
- def cleanup():
- InstrumentedTransport.hooks = TransportHooks()
- unregister_transport('ftp://', ConnectionHookedTransport)
-
- self.addCleanup(cleanup)
- self.connections = []
+ self._hooks_installed = True
+
+ def reset_hooks(self):
+ InstrumentedTransport.hooks = TransportHooks()
+ unregister_transport('ftp://', ConnectionHookedTransport)
+ self._hooks_installed = False
def reset_connections(self):
self.connections = []
=== modified file 'bzrlib/tests/commands/test_branch.py'
--- a/bzrlib/tests/commands/test_branch.py 2007-06-03 15:52:19 +0000
+++ b/bzrlib/tests/commands/test_branch.py 2007-06-06 08:42:07 +0000
@@ -24,8 +24,8 @@
def setUp(self):
super(TestBranch, self).setUp()
self.make_branch_and_tree('branch')
- # make_branch_and_tree create one connection
- self.reset_connections()
+ self.install_hooks()
+ self.addCleanup(self.reset_hooks)
def test_branch_remote_local(self):
cmd = cmd_branch()
=== modified file 'bzrlib/tests/commands/test_cat.py'
--- a/bzrlib/tests/commands/test_cat.py 2007-06-03 15:52:19 +0000
+++ b/bzrlib/tests/commands/test_cat.py 2007-06-06 08:42:07 +0000
@@ -36,12 +36,13 @@
def test_cat(self):
wt1 = self.make_branch_and_tree('branch')
- # make_branch_and_tree create one connection
- self.reset_connections()
file('branch/foo', 'wb').write('foo')
wt1.add('foo')
wt1.commit('add foo')
+ self.install_hooks()
+ self.addCleanup(self.reset_hooks)
+
cmd = cmd_cat()
cmd.run(self.get_url() + '/branch/foo')
self.assertEquals(1, len(self.connections))
=== modified file 'bzrlib/tests/commands/test_checkout.py'
--- a/bzrlib/tests/commands/test_checkout.py 2007-06-03 15:52:19 +0000
+++ b/bzrlib/tests/commands/test_checkout.py 2007-06-06 08:42:07 +0000
@@ -22,8 +22,9 @@
def test_checkout(self):
self.make_branch_and_tree('branch1')
- # make_branch_and_tree create one connection
- self.reset_connections()
+
+ self.install_hooks()
+ self.addCleanup(self.reset_hooks)
cmd = cmd_checkout()
cmd.run(self.get_url() + '/branch1', 'local')
=== modified file 'bzrlib/tests/commands/test_init.py'
--- a/bzrlib/tests/commands/test_init.py 2007-05-25 11:38:40 +0000
+++ b/bzrlib/tests/commands/test_init.py 2007-06-06 08:42:07 +0000
@@ -20,6 +20,11 @@
class TestInit(TestCaseWithConnectionHookedTransport):
+ def setUp(self):
+ super(TestInit, self).setUp()
+ self.install_hooks()
+ self.addCleanup(self.reset_hooks)
+
def test_init(self):
cmd = cmd_init()
cmd.run(self.get_url())
=== modified file 'bzrlib/tests/commands/test_init_repository.py'
--- a/bzrlib/tests/commands/test_init_repository.py 2007-05-25 16:39:29 +0000
+++ b/bzrlib/tests/commands/test_init_repository.py 2007-06-06 08:42:07 +0000
@@ -20,6 +20,11 @@
class TestInitRepository(TestCaseWithConnectionHookedTransport):
+ def setUp(self):
+ super(TestInitRepository, self).setUp()
+ self.install_hooks()
+ self.addCleanup(self.reset_hooks)
+
def test_init_repository(self):
cmd = cmd_init_repository()
cmd.run(self.get_url())
=== modified file 'bzrlib/tests/commands/test_merge.py'
--- a/bzrlib/tests/commands/test_merge.py 2007-06-03 15:52:19 +0000
+++ b/bzrlib/tests/commands/test_merge.py 2007-06-06 08:42:07 +0000
@@ -27,8 +27,9 @@
wt2 = self.make_branch_and_tree('branch2')
wt2.pull(wt1.branch)
wt2.commit('empty commit too')
- # make_branch_and_tree calls have created connections
- self.reset_connections()
+
+ self.install_hooks()
+ self.addCleanup(self.reset_hooks)
cmd = cmd_merge()
# We don't care about the ouput but 'outf' should be defined
=== modified file 'bzrlib/tests/commands/test_missing.py'
--- a/bzrlib/tests/commands/test_missing.py 2007-06-03 15:52:19 +0000
+++ b/bzrlib/tests/commands/test_missing.py 2007-06-06 08:42:07 +0000
@@ -27,8 +27,9 @@
wt2 = self.make_branch_and_tree('branch2')
wt2.pull(wt1.branch)
wt2.commit('empty commit too')
- # make_branch_and_tree calls have created connections
- self.reset_connections()
+
+ self.install_hooks()
+ self.addCleanup(self.reset_hooks)
cmd = cmd_missing()
# We don't care about the ouput but 'outf' should be defined
=== modified file 'bzrlib/tests/commands/test_pull.py'
--- a/bzrlib/tests/commands/test_pull.py 2007-06-03 15:52:19 +0000
+++ b/bzrlib/tests/commands/test_pull.py 2007-06-06 08:42:07 +0000
@@ -25,8 +25,9 @@
wt1 = self.make_branch_and_tree('branch1')
tip = wt1.commit('empty commit')
wt2 = self.make_branch_and_tree('branch2')
- # make_branch_and_tree calls have created connections
- self.reset_connections()
+
+ self.install_hooks()
+ self.addCleanup(self.reset_hooks)
cmd = cmd_pull()
# We don't care about the ouput but 'outf' should be defined
=== modified file 'bzrlib/tests/commands/test_push.py'
--- a/bzrlib/tests/commands/test_push.py 2007-06-03 15:52:19 +0000
+++ b/bzrlib/tests/commands/test_push.py 2007-06-06 08:42:07 +0000
@@ -22,8 +22,10 @@
def test_push(self):
self.make_branch_and_tree('branch')
- # make_branch_and_tree create one connection
- self.reset_connections()
+
+ self.install_hooks()
+ self.addCleanup(self.reset_hooks)
+
cmd = cmd_push()
cmd.run(self.get_url() + '/remote', directory='branch')
self.assertEquals(1, len(self.connections))
More information about the bazaar-commits
mailing list