Rev 5772: Merge config-abstract-store into config-concrete-stores resolving conflicts in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Apr 12 08:59:20 UTC 2011


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

------------------------------------------------------------
revno: 5772 [merge]
revision-id: v.ladeuil+lp at free.fr-20110412085920-pg10igf3pwkr0tl8
parent: v.ladeuil+lp at free.fr-20110412080407-isi0ke3tpobwqcie
parent: v.ladeuil+lp at free.fr-20110412085324-dq847htbdg2rb2ks
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-concrete-stores
timestamp: Tue 2011-04-12 10:59:20 +0200
message:
  Merge config-abstract-store into config-concrete-stores resolving conflicts
modified:
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-04-12 08:04:07 +0000
+++ b/bzrlib/config.py	2011-04-12 08:59:20 +0000
@@ -2138,6 +2138,9 @@
 class Store(object):
     """Abstract interface to persistent storage for configuration options."""
 
+    readonly_section_class = ReadOnlySection
+    mutable_section_class = MutableSection
+
     @property
     def loaded(self):
         raise NotImplementedError(self.loaded)
@@ -2145,6 +2148,17 @@
     def load(self):
         raise NotImplementedError(self.load)
 
+    def _load_from_string(self, str_or_unicode):
+        """Create a store from a string in configobj syntax.
+
+        :param str_or_unicode: A string representing the file content. This will
+            be encoded to suit store needs internally.
+
+        This is for tests and should not be used in production unless a
+        convincing use case can be demonstrated :)
+        """
+        raise NotImplementedError(self._load_from_string)
+
     def save(self):
         raise NotImplementedError(self.save)
 
@@ -2231,12 +2245,9 @@
         self.load()
         cobj = self._config_obj
         if cobj.scalars:
-
-# use self.readonly_section_kls
-
-            yield ReadOnlySection(None, cobj)
+            yield self.readonly_section_class(None, cobj)
         for section_name in cobj.sections:
-            yield ReadOnlySection(section_name, cobj[section_name])
+            yield self.readonly_section_class(section_name, cobj[section_name])
 
     def get_mutable_section(self, section_name=None):
         # We need a loaded store
@@ -2249,10 +2260,7 @@
             section = self._config_obj
         else:
             section = self._config_obj.setdefault(section_name, {})
-
-# use self.mutable_section_kls
-
-        return MutableSection(section_name, section)
+        return self.mutable_section_class(section_name, section)
 
 
 # Note that LockableConfigObjStore inherits from ConfigObjStore because we need

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-04-12 08:04:07 +0000
+++ b/bzrlib/tests/test_config.py	2011-04-12 08:59:20 +0000
@@ -1838,7 +1838,7 @@
 
 class TestConfigMutableSection(tests.TestCase):
 
-    # FIXME: Parametrize so that all sections (includind os.environ and the
+    # FIXME: Parametrize so that all sections (including os.environ and the
     # ones produced by Stores) run these tests -- vila 2011-04-01
 
     def test_set(self):
@@ -1951,6 +1951,10 @@
         self.assertLength(1, sections)
         self.assertSectionContent(('baz', {'foo': 'bar'}), sections[0])
 
+    def test_load_from_string_fails_for_non_empty_store(self):
+        store = self.get_store('foo.conf', 'foo=bar')
+        self.assertRaises(AssertionError, store._load_from_string, 'bar=baz')
+
 
 class TestMutableStore(TestStore):
 



More information about the bazaar-commits mailing list