Rev 5776: All stores should provide _load_from_string to reuse the existing tests. in file:///home/vila/src/bzr/experimental/config/

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


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

------------------------------------------------------------
revno: 5776
revision-id: v.ladeuil+lp at free.fr-20110412083317-l3b3yyhls0fu4fvn
parent: v.ladeuil+lp at free.fr-20110412082311-vj3tc4ssxw3qsj4w
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-abstract-store
timestamp: Tue 2011-04-12 10:33:17 +0200
message:
  All stores should provide _load_from_string to reuse the existing tests.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-04-12 07:26:36 +0000
+++ b/bzrlib/config.py	2011-04-12 08:33:17 +0000
@@ -2138,6 +2138,9 @@
 class Store(object):
     """Abstract interface to persistent storage for configuration options."""
 
+    readonly_section_class = None
+    mutable_section_class = None
+
     @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)
 

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-04-12 08:23:11 +0000
+++ b/bzrlib/tests/test_config.py	2011-04-12 08:33:17 +0000
@@ -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