989
989
# is addressed -- vila 20110219
990
990
self.overrideAttr(config, '_expand_default_value', None)
991
991
self._log_files = set()
992
# Each key in the ``_counters`` dict holds a value for a different
993
# counter. When the test ends, addDetail() should be used to output the
994
# counter values. This happens in install_counter_hook().
996
if 'config_stats' in selftest_debug_flags:
997
self._install_config_stats_hooks()
994
1000
# debug a frame up.
1011
1017
if name in details:
1012
1018
del details[name]
1020
def install_counter_hook(self, hooks, name, counter_name=None):
1021
"""Install a counting hook.
1023
Any hook can be counted as long as it doesn't need to return a value.
1025
:param hooks: Where the hook should be installed.
1027
:param name: The hook name that will be counted.
1029
:param counter_name: The counter identifier in ``_counters``, defaults
1032
_counters = self._counters # Avoid closing over self
1033
if counter_name is None:
1035
if _counters.has_key(counter_name):
1036
raise AssertionError('%s is already used as a counter name'
1038
_counters[counter_name] = 0
1039
self.addDetail(counter_name, content.Content(content.UTF8_TEXT,
1040
lambda: ['%d' % (_counters[counter_name],)]))
1041
def increment_counter(*args, **kwargs):
1042
_counters[counter_name] += 1
1043
label = 'count %s calls' % (counter_name,)
1044
hooks.install_named_hook(name, increment_counter, label)
1045
self.addCleanup(hooks.uninstall_named_hook, name, label)
1047
def _install_config_stats_hooks(self):
1048
"""Install config hooks to count hook calls.
1051
for hook_name in ('get', 'set', 'remove', 'load', 'save'):
1052
self.install_counter_hook(config.ConfigHooks, hook_name,
1053
'config.%s' % (hook_name,))
1055
# The OldConfigHooks are private and need special handling to protect
1056
# against recursive tests (tests that run other tests), so we just do
1057
# manually what registering them into _builtin_known_hooks will provide
1059
self.overrideAttr(config, 'OldConfigHooks', config._OldConfigHooks())
1060
for hook_name in ('get', 'set', 'remove', 'load', 'save'):
1061
self.install_counter_hook(config.OldConfigHooks, hook_name,
1062
'old_config.%s' % (hook_name,))
1014
1064
def _clear_debug_flags(self):
1015
1065
"""Prevent externally set debug flags affecting tests.