Rev 5799: Isolate the assertions in a mixin. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon Jun 13 16:27:45 UTC 2011


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

------------------------------------------------------------
revno: 5799
revision-id: v.ladeuil+lp at free.fr-20110613162745-s081jt019glzvsp2
parent: v.ladeuil+lp at free.fr-20110613153854-ssjab2rc9c532tqr
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-hooks
timestamp: Mon 2011-06-13 18:27:45 +0200
message:
  Isolate the assertions in a mixin.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-06-13 15:38:54 +0000
+++ b/bzrlib/tests/test_config.py	2011-06-13 16:27:45 +0000
@@ -1906,11 +1906,7 @@
         self.assertIs(None, bzrdir_config.get_default_stack_on())
 
 
-class TestOldConfigHooks(tests.TestCaseWithTransport):
-
-    def setUp(self):
-        super(TestOldConfigHooks, self).setUp()
-        create_configs_with_file_option(self)
+class TestOldConfigHooksMixin(object):
 
     def assertGetHook(self, conf, name, value):
         calls = []
@@ -1923,6 +1919,63 @@
         self.assertLength(1, calls)
         self.assertEquals((conf, name, value), calls[0])
 
+    def assertSetHook(self, conf, name, value):
+        calls = []
+        def hook(*args):
+            calls.append(args)
+        config.ConfigHooks.install_named_hook('old_set', hook, None)
+        self.assertLength(0, calls)
+        conf.set_user_option(name, value)
+        self.assertLength(1, calls)
+        # We can't assert the conf object below as different configs use
+        # different means to implement set_user_option and we care only about
+        # coverage here.
+        self.assertEquals((name, value), calls[0][1:])
+
+    def assertRemoveHook(self, conf, name, section_name=None):
+        calls = []
+        def hook(*args):
+            calls.append(args)
+        config.ConfigHooks.install_named_hook('old_remove', hook, None)
+        self.assertLength(0, calls)
+        conf.remove_user_option(name, section_name)
+        self.assertLength(1, calls)
+        # We can't assert the conf object below as different configs use
+        # different means to implement remove_user_option and we care only about
+        # coverage here.
+        self.assertEquals((name,), calls[0][1:])
+
+    def assertLoadHook(self, name, conf_class, *conf_args):
+        calls = []
+        def hook(*args):
+            calls.append(args)
+        config.ConfigHooks.install_named_hook('old_load', hook, None)
+        self.assertLength(0, calls)
+        # Build a config
+        conf = conf_class(*conf_args)
+        # Access an option to trigger a load
+        conf.get_user_option(name)
+        self.assertLength(1, calls)
+        # Since we can't assert about conf, we just use the number of calls ;-/
+
+    def assertSaveHook(self, conf):
+        calls = []
+        def hook(*args):
+            calls.append(args)
+        config.ConfigHooks.install_named_hook('old_save', hook, None)
+        self.assertLength(0, calls)
+        # Setting an option triggers a save
+        conf.set_user_option('foo', 'bar')
+        self.assertLength(1, calls)
+        # Since we can't assert about conf, we just use the number of calls ;-/
+
+
+class TestOldConfigHooks(tests.TestCaseWithTransport, TestOldConfigHooksMixin):
+
+    def setUp(self):
+        super(TestOldConfigHooks, self).setUp()
+        create_configs_with_file_option(self)
+
     def test_get_hook_bazaar(self):
         self.assertGetHook(self.bazaar_config, 'file', 'bazaar')
 
@@ -1934,19 +1987,6 @@
         self.branch_config.set_user_option('file2', 'branch')
         self.assertGetHook(self.branch_config, 'file2', 'branch')
 
-    def assertSetHook(self, conf, name, value):
-        calls = []
-        def hook(*args):
-            calls.append(args)
-        config.ConfigHooks.install_named_hook('old_set', hook, None)
-        self.assertLength(0, calls)
-        conf.set_user_option(name, value)
-        self.assertLength(1, calls)
-        # We can't assert the conf object below as different configs use
-        # different means to implement set_user_option and we care only about
-        # coverage here.
-        self.assertEquals((name, value), calls[0][1:])
-
     def test_set_hook_bazaar(self):
         self.assertSetHook(self.bazaar_config, 'foo', 'bazaar')
 
@@ -1956,19 +1996,6 @@
     def test_set_hook_branch(self):
         self.assertSetHook(self.branch_config, 'foo', 'branch')
 
-    def assertRemoveHook(self, conf, name, section_name=None):
-        calls = []
-        def hook(*args):
-            calls.append(args)
-        config.ConfigHooks.install_named_hook('old_remove', hook, None)
-        self.assertLength(0, calls)
-        conf.remove_user_option(name, section_name)
-        self.assertLength(1, calls)
-        # We can't assert the conf object below as different configs use
-        # different means to implement remove_user_option and we care only about
-        # coverage here.
-        self.assertEquals((name,), calls[0][1:])
-
     def test_remove_hook_bazaar(self):
         self.assertRemoveHook(self.bazaar_config, 'file')
 
@@ -1979,19 +2006,6 @@
     def test_remove_hook_branch(self):
         self.assertRemoveHook(self.branch_config, 'file')
 
-    def assertLoadHook(self, name, conf_class, *conf_args):
-        calls = []
-        def hook(*args):
-            calls.append(args)
-        config.ConfigHooks.install_named_hook('old_load', hook, None)
-        self.assertLength(0, calls)
-        # Build a config
-        conf = conf_class(*conf_args)
-        # Access an option to trigger a load
-        conf.get_user_option(name)
-        self.assertLength(1, calls)
-        # Since we can't assert about conf, we just use the number of calls ;-/
-
     def test_load_hook_bazaar(self):
         self.assertLoadHook('file', config.GlobalConfig)
 
@@ -2001,17 +2015,6 @@
     def test_load_hook_branch(self):
         self.assertLoadHook('file', config.BranchConfig, self.tree.branch)
 
-    def assertSaveHook(self, conf):
-        calls = []
-        def hook(*args):
-            calls.append(args)
-        config.ConfigHooks.install_named_hook('old_save', hook, None)
-        self.assertLength(0, calls)
-        # Setting an option triggers a save
-        conf.set_user_option('foo', 'bar')
-        self.assertLength(1, calls)
-        # Since we can't assert about conf, we just use the number of calls ;-/
-
     def test_save_hook_bazaar(self):
         self.assertSaveHook(self.bazaar_config)
 



More information about the bazaar-commits mailing list