Rev 5808: Some more doc and tests. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Jun 16 10:10:54 UTC 2011


At file:///home/vila/src/bzr/experimental/config/

------------------------------------------------------------
revno: 5808
revision-id: v.ladeuil+lp at free.fr-20110616101054-c6ijva2wpnjh6ijy
parent: v.ladeuil+lp at free.fr-20110616083746-crq83yskjaxbbu7i
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: selftest-config-stats
timestamp: Thu 2011-06-16 12:10:54 +0200
message:
  Some more doc and tests.
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2011-06-16 07:51:46 +0000
+++ b/bzrlib/tests/__init__.py	2011-06-16 10:10:54 +0000
@@ -989,6 +989,9 @@
         # is addressed -- vila 20110219
         self.overrideAttr(config, '_expand_default_value', None)
         self._log_files = set()
+        # Each key in the ``_counters`` dict holds a value for a different
+        # counter. When the test ends, subunit addDetail() should be used to
+        # output the counter values. This happens in install_counter_hook().
         self._counters = {}
         if 'config_stats' in selftest_debug_flags:
             self._install_config_stats_hooks()

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2011-05-27 13:49:19 +0000
+++ b/bzrlib/tests/test_selftest.py	2011-06-16 10:10:54 +0000
@@ -43,6 +43,7 @@
     branchbuilder,
     bzrdir,
     errors,
+    hooks,
     lockdir,
     memorytree,
     osutils,
@@ -3559,3 +3560,40 @@
 
     def test_mutiple_excludes(self):
         self.assertTestList(['c'], '-x', 'a', '-x', 'b')
+
+
+class TestCounterHooks(tests.TestCase, SelfTestHelper):
+
+    _test_needs_features = [features.subunit]
+
+    def setUp(self):
+        super(TestCounterHooks, self).setUp()
+        class Test(tests.TestCase):
+
+            def setUp(self):
+                super(Test, self).setUp()
+                self.hooks = hooks.Hooks()
+                self.hooks.add_hook('myhook', 'Foo bar blah', (2,4))
+                self.install_counter_hook(self.hooks, 'myhook')
+
+            def no_hook(self):
+                pass
+
+            def run_hook_once(self):
+                for hook in self.hooks['myhook']:
+                    hook(self)
+        self.test_class = Test
+
+    def assertHookCalls(self, expected_calls, test_name):
+        test = self.test_class(test_name)
+        result = unittest.TestResult()
+        test.run(result)
+        self.assertTrue(hasattr(test, '_counters'))
+        self.assertTrue(test._counters.has_key('myhook'))
+        self.assertEquals(expected_calls, test._counters['myhook'])
+
+    def test_no_hook(self):
+        self.assertHookCalls(0, 'no_hook')
+
+    def test_run_hook_once(self):
+        self.assertHookCalls(1, 'run_hook_once')



More information about the bazaar-commits mailing list