Rev 6126: Implements a stack registry with basic tests. in file:///home/vila/src/bzr/bugs/832036-stack-registry/

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon Sep 5 16:04:46 UTC 2011


At file:///home/vila/src/bzr/bugs/832036-stack-registry/

------------------------------------------------------------
revno: 6126
revision-id: v.ladeuil+lp at free.fr-20110905160446-9aihwyfudsplk7xm
parent: pqm at pqm.ubuntu.com-20110902124536-e8qhanwx2fkhdcwl
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 832036-stack-registry
timestamp: Mon 2011-09-05 18:04:46 +0200
message:
  Implements a stack registry with basic tests.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-09-02 08:34:51 +0000
+++ b/bzrlib/config.py	2011-09-05 16:04:46 +0000
@@ -3306,6 +3306,13 @@
         self.branch = branch
 
 
+class _StackRegistry(registry.Registry):
+    """Registry of Stack factories.
+
+    This registry is queried for a given key and provides a factory that accept
+    a context and build the appropriate Stack for this context.
+    """
+
 class cmd_config(commands.Command):
     __doc__ = """Display, set or remove a configuration option.
 

=== modified file 'bzrlib/library_state.py'
--- a/bzrlib/library_state.py	2011-03-29 09:50:04 +0000
+++ b/bzrlib/library_state.py	2011-09-05 16:04:46 +0000
@@ -69,8 +69,7 @@
         return self # This is bound to the 'as' clause in a with statement.
 
     def _start(self):
-        """Do all initialization.
-        """        
+        """Do all initialization."""
         # NB: This function tweaks so much global state it's hard to test it in
         # isolation within the same interpreter.  It's not reached on normal
         # in-process run_bzr calls.  If it's broken, we expect that
@@ -108,4 +107,4 @@
         bzrlib.ui.ui_factory = self._orig_ui
         global global_state
         global_state = self.saved_state
-        return False # propogate exceptions.
+        return False # propagate exceptions.

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-09-02 08:34:51 +0000
+++ b/bzrlib/tests/test_config.py	2011-09-05 16:04:46 +0000
@@ -3180,6 +3180,37 @@
         self.assertEquals(expected_location, matcher.location)
 
 
+class TestStackRegistry(tests.TestCase):
+
+    def setUp(self):
+        super(TestStackRegistry, self).setUp()
+        self.registry = config._StackRegistry()
+
+    def test_register_remove(self):
+        self.registry.register('test', config.Stack)
+        self.assertIs(config.Stack, self.registry.get('test'))
+        self.registry.remove('test')
+        self.assertRaises(KeyError, self.registry.get, 'test')
+
+    lazy_stack = config.Stack
+
+    def test_register_lazy_remove(self):
+        self.registry.register_lazy('test', self.__module__,
+                                    'TestStackRegistry.lazy_stack')
+        self.assertIs(self.lazy_stack, self.registry.get('test'))
+        self.registry.remove('test')
+        self.assertRaises(KeyError, self.registry.get, 'test')
+
+    def test_register_override(self):
+        self.registry.register('test', config.Stack)
+        self.assertIs(config.Stack, self.registry.get('test'))
+        self.registry.register('test', self.lazy_stack, override_existing=True)
+        self.assertIs(self.lazy_stack, self.registry.get('test'))
+
+
+# register override
+# get_all
+
 class TestStackGet(tests.TestCase):
 
     # FIXME: This should be parametrized for all known Stack or dedicated

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2011-08-19 22:34:02 +0000
+++ b/bzrlib/tests/test_selftest.py	2011-09-05 16:04:46 +0000
@@ -3162,7 +3162,7 @@
         result.stopTestRun()
         self.assertEqual(result._tests_leaking_threads_count, 0)
         self.assertEqual(result.leaks, [])
-        
+
     def test_thread_leak(self):
         """Ensure a thread that outlives the running of a test is reported
 



More information about the bazaar-commits mailing list