Rev 2561: Make debug.debug_flags be isolated for all tests. in sftp://rookery/~/public_html/baz2.0/debug-test-isolation
Robert Collins
robertc at robertcollins.net
Thu Jun 28 08:48:26 BST 2007
At sftp://rookery/~/public_html/baz2.0/debug-test-isolation
------------------------------------------------------------
revno: 2561
revision-id: robertc at robertcollins.net-20070628074823-cj7pcabpm2jrdi7m
parent: pqm at pqm.ubuntu.com-20070628070827-h5s313dg5tnag9vj
committer: Robert Collins <robertc at robertcollins.net>
branch nick: debug-test-isolation
timestamp: Thu 2007-06-28 17:48:23 +1000
message:
Make debug.debug_flags be isolated for all tests.
modified:
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2007-06-28 07:08:27 +0000
+++ b/bzrlib/tests/__init__.py 2007-06-28 07:48:23 +0000
@@ -752,6 +752,17 @@
self._benchcalls = []
self._benchtime = None
self._clear_hooks()
+ self._clear_debug_flags()
+
+ def _clear_debug_flags(self):
+ """Prevent externally set debug flags affecting tests.
+
+ Tests that want to use debug flags can just set them in the
+ debug_flags set during setup/teardown.
+ """
+ self._preserved_debug_flags = debug.debug_flags
+ debug.debug_flags = set()
+ self.addCleanup(self._restore_debug_flags)
def _clear_hooks(self):
# prevent hooks affecting tests
@@ -765,9 +776,6 @@
# reset all hooks to an empty instance of the appropriate type
bzrlib.branch.Branch.hooks = bzrlib.branch.BranchHooks()
bzrlib.smart.server.SmartTCPServer.hooks = bzrlib.smart.server.SmartServerHooks()
- # FIXME: Rather than constructing new objects like this, how about
- # having save() and clear() methods on the base Hook class? mbp
- # 20070416
def _silenceUI(self):
"""Turn off UI for duration of test"""
@@ -1108,6 +1116,9 @@
"""Set an environment variable, and reset it when finished."""
self.__old_env[name] = osutils.set_or_unset_env(name, newvalue)
+ def _restore_debug_flags(self):
+ debug.debug_flags = self._preserved_debug_flags
+
def _restoreEnvironment(self):
for name, value in self.__old_env.iteritems():
osutils.set_or_unset_env(name, value)
@@ -1269,15 +1280,10 @@
os.chdir(working_dir)
try:
- saved_debug_flags = frozenset(debug.debug_flags)
- debug.debug_flags.clear()
- try:
- result = self.apply_redirected(ui.ui_factory.stdin,
- stdout, stderr,
- bzrlib.commands.run_bzr_catch_errors,
- args)
- finally:
- debug.debug_flags.update(saved_debug_flags)
+ result = self.apply_redirected(ui.ui_factory.stdin,
+ stdout, stderr,
+ bzrlib.commands.run_bzr_catch_errors,
+ args)
finally:
logger.removeHandler(handler)
ui.ui_factory = old_ui_factory
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2007-06-18 13:55:14 +0000
+++ b/bzrlib/tests/test_selftest.py 2007-06-28 07:48:23 +0000
@@ -1128,6 +1128,13 @@
class TestTestCase(TestCase):
"""Tests that test the core bzrlib TestCase."""
+ def test_debug_flags_sanitised(self):
+ """The bzrlib debug flags should be sanitised by setUp."""
+ # we could set something and run a test that will check
+ # it gets santised, but this is probably sufficient for now:
+ # if someone runs the test with -Dsomething it will error.
+ self.assertEqual(set(), bzrlib.debug.debug_flags)
+
def inner_test(self):
# the inner child test
note("inner_test")
More information about the bazaar-commits
mailing list