Rev 5807: Merge gz implementation avoiding some cycles in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Jun 16 08:37:46 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5807 [merge]
revision-id: v.ladeuil+lp at free.fr-20110616083746-crq83yskjaxbbu7i
parent: v.ladeuil+lp at free.fr-20110615203507-3f8tfdo120rku7jg
parent: gzlist at googlemail.com-20110616075146-8kgjvih0oa6b0crs
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: selftest-config-stats
timestamp: Thu 2011-06-16 10:37:46 +0200
message:
Merge gz implementation avoiding some cycles
modified:
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2011-06-15 20:33:07 +0000
+++ b/bzrlib/tests/__init__.py 2011-06-16 07:51:46 +0000
@@ -989,7 +989,7 @@
# is addressed -- vila 20110219
self.overrideAttr(config, '_expand_default_value', None)
self._log_files = set()
- self._init_counters()
+ self._counters = {}
if 'config_stats' in selftest_debug_flags:
self._install_config_stats_hooks()
@@ -1014,19 +1014,6 @@
if name in details:
del details[name]
- def _init_counters(self):
- """Setup a dict to collect various counters.
-
- Each key in the dict holds a value for a different counter. When the
- test ends, subunit addDetail API is used to output the counter values.
- """
- self._counters = {}
- def add_counter_details():
- for k, v in self._counters.iteritems():
- self.addDetail('%s' % (k,), content.text_content('%s' % (v,)))
- self._counters = None
- self.addCleanup(add_counter_details)
-
def install_counter_hook(self, hooks, name, counter_name=None):
"""Install a counting hook.
@@ -1039,18 +1026,19 @@
:param counter_name: The counter identifier in ``_counters``, defaults
to ``name``.
"""
+ _counters = self._counters # Avoid closing over self
if counter_name is None:
counter_name = name
- if self._counters.has_key(counter_name):
+ if _counters.has_key(counter_name):
raise AssertionError('%s is already used as a counter name'
% (counter_name,))
- self._counters[counter_name] = 0
- def increment_counter():
- # We can't do that in a lambda...
- self._counters[counter_name] += 1
+ _counters[counter_name] = 0
+ self.addDetail(counter_name, content.Content(content.UTF8_TEXT,
+ lambda: ['%d' % (_counters[counter_name],)]))
+ def increment_counter(*args, **kwargs):
+ _counters[counter_name] += 1
label = 'count %s calls' % (counter_name,)
- hooks.install_named_hook(
- name, lambda *args, **kwargs: increment_counter(), label)
+ hooks.install_named_hook(name, increment_counter, label)
self.addCleanup(hooks.uninstall_named_hook, name, label)
def _install_config_stats_hooks(self):
More information about the bazaar-commits
mailing list