142
142
'BZREMAIL': None, # may still be present in the environment
143
143
'EMAIL': 'jrandom@example.com', # set EMAIL as bzr does not guess
144
144
'BZR_PROGRESS_BAR': None,
145
# This should trap leaks to ~/.bzr.log. This occurs when tests use TestCase
146
# as a base class instead of TestCaseInTempDir. Tests inheriting from
147
# TestCase should not use disk resources, BZR_LOG is one.
148
'BZR_LOG': '/you-should-use-TestCaseInTempDir-if-you-need-a-log-file',
146
149
'BZR_PLUGIN_PATH': None,
147
150
'BZR_DISABLE_PLUGINS': None,
148
151
'BZR_PLUGINS_AT': None,
989
992
# is addressed -- vila 20110219
990
993
self.overrideAttr(config, '_expand_default_value', None)
991
994
self._log_files = set()
995
# Each key in the ``_counters`` dict holds a value for a different
996
# counter. When the test ends, addDetail() should be used to output the
997
# counter values. This happens in install_counter_hook().
999
if 'config_stats' in selftest_debug_flags:
1000
self._install_config_stats_hooks()
993
1002
def debug(self):
994
1003
# debug a frame up.
1011
1020
if name in details:
1012
1021
del details[name]
1023
def install_counter_hook(self, hooks, name, counter_name=None):
1024
"""Install a counting hook.
1026
Any hook can be counted as long as it doesn't need to return a value.
1028
:param hooks: Where the hook should be installed.
1030
:param name: The hook name that will be counted.
1032
:param counter_name: The counter identifier in ``_counters``, defaults
1035
_counters = self._counters # Avoid closing over self
1036
if counter_name is None:
1038
if _counters.has_key(counter_name):
1039
raise AssertionError('%s is already used as a counter name'
1041
_counters[counter_name] = 0
1042
self.addDetail(counter_name, content.Content(content.UTF8_TEXT,
1043
lambda: ['%d' % (_counters[counter_name],)]))
1044
def increment_counter(*args, **kwargs):
1045
_counters[counter_name] += 1
1046
label = 'count %s calls' % (counter_name,)
1047
hooks.install_named_hook(name, increment_counter, label)
1048
self.addCleanup(hooks.uninstall_named_hook, name, label)
1050
def _install_config_stats_hooks(self):
1051
"""Install config hooks to count hook calls.
1054
for hook_name in ('get', 'set', 'remove', 'load', 'save'):
1055
self.install_counter_hook(config.ConfigHooks, hook_name,
1056
'config.%s' % (hook_name,))
1058
# The OldConfigHooks are private and need special handling to protect
1059
# against recursive tests (tests that run other tests), so we just do
1060
# manually what registering them into _builtin_known_hooks will provide
1062
self.overrideAttr(config, 'OldConfigHooks', config._OldConfigHooks())
1063
for hook_name in ('get', 'set', 'remove', 'load', 'save'):
1064
self.install_counter_hook(config.OldConfigHooks, hook_name,
1065
'old_config.%s' % (hook_name,))
1014
1067
def _clear_debug_flags(self):
1015
1068
"""Prevent externally set debug flags affecting tests.
1654
1707
def _finishLogFile(self):
1655
1708
"""Finished with the log file.
1657
Close the file and delete it, unless setKeepLogfile was called.
1710
Close the file and delete it.
1659
1712
if trace._trace_file:
1660
1713
# flush the log file, to get all content
2275
2328
class TestCaseWithMemoryTransport(TestCase):
2276
2329
"""Common test class for tests that do not need disk resources.
2278
Tests that need disk resources should derive from TestCaseWithTransport.
2331
Tests that need disk resources should derive from TestCaseInTempDir
2332
orTestCaseWithTransport.
2280
2334
TestCaseWithMemoryTransport sets the TEST_ROOT variable for all bzr tests.
2282
For TestCaseWithMemoryTransport the test_home_dir is set to the name of
2336
For TestCaseWithMemoryTransport the ``test_home_dir`` is set to the name of
2283
2337
a directory which does not exist. This serves to help ensure test isolation
2284
is preserved. test_dir is set to the TEST_ROOT, as is cwd, because they
2285
must exist. However, TestCaseWithMemoryTransport does not offer local
2286
file defaults for the transport in tests, nor does it obey the command line
2338
is preserved. ``test_dir`` is set to the TEST_ROOT, as is cwd, because they
2339
must exist. However, TestCaseWithMemoryTransport does not offer local file
2340
defaults for the transport in tests, nor does it obey the command line
2287
2341
override, so tests that accidentally write to the common directory should
2290
:cvar TEST_ROOT: Directory containing all temporary directories, plus
2291
a .bzr directory that stops us ascending higher into the filesystem.
2344
:cvar TEST_ROOT: Directory containing all temporary directories, plus a
2345
``.bzr`` directory that stops us ascending higher into the filesystem.
2294
2348
TEST_ROOT = None
2619
2673
OVERRIDE_PYTHON = 'python'
2676
super(TestCaseInTempDir, self).setUp()
2677
# Remove the protection set in isolated_environ, we have a proper
2678
# access to disk resources now.
2679
self.overrideEnv('BZR_LOG', None)
2621
2681
def check_file_contents(self, filename, expect):
2622
2682
self.log("check contents of file %s" % filename)
2623
2683
f = file(filename)