~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/TransportUtil.py

  • Committer: Vincent Ladeuil
  • Date: 2007-06-06 08:42:07 UTC
  • mto: (2485.8.44 bzr.connection.sharing)
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070606084207-6fa0f02eadtezlrf
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
    def setUp(self):
57
57
        super(TestCaseWithConnectionHookedTransport, self).setUp()
 
58
        self._hooks_installed = False
 
59
 
 
60
        def cleanup():
 
61
            # Be nice and reset hooks if the test writer forgot about them
 
62
            if self._hooks_installed:
 
63
                self.reset_hooks()
 
64
 
 
65
        self.addCleanup(cleanup)
 
66
        self.connections = []
 
67
 
 
68
    def install_hooks(self):
58
69
        ConnectionHookedTransport.hooks.install_hook('_set_connection',
59
70
                                                     self.set_connection_hook)
60
71
        # Make our instrumented transport the default ftp transport
61
72
        register_transport('ftp://', ConnectionHookedTransport)
62
 
 
63
 
        def cleanup():
64
 
            InstrumentedTransport.hooks = TransportHooks()
65
 
            unregister_transport('ftp://', ConnectionHookedTransport)
66
 
 
67
 
        self.addCleanup(cleanup)
68
 
        self.connections = []
 
73
        self._hooks_installed = True
 
74
 
 
75
    def reset_hooks(self):
 
76
        InstrumentedTransport.hooks = TransportHooks()
 
77
        unregister_transport('ftp://', ConnectionHookedTransport)
 
78
        self._hooks_installed = False
69
79
 
70
80
    def reset_connections(self):
71
81
        self.connections = []