Rev 5756: Use proper ReadOnly sections in ConfigObjStore.get_sections(). in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Apr 5 15:08:41 UTC 2011


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

------------------------------------------------------------
revno: 5756
revision-id: v.ladeuil+lp at free.fr-20110405150841-c9rj2kpcwrp7gfad
parent: v.ladeuil+lp at free.fr-20110404173437-qksec0538jc7496g
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-abstract-store
timestamp: Tue 2011-04-05 17:08:41 +0200
message:
  Use proper ReadOnly sections in ConfigObjStore.get_sections().
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-04-04 17:34:37 +0000
+++ b/bzrlib/config.py	2011-04-05 15:08:41 +0000
@@ -2124,9 +2124,9 @@
         self.load()
         cobj = self._config_obj
         if cobj.scalars:
-            yield None, dict([(k, cobj[k]) for k in cobj.scalars])
+            yield ReadOnlySection(None, cobj)
         for section_name in cobj.sections:
-            yield section_name, dict(cobj[section_name])
+            yield ReadOnlySection(section_name, cobj[section_name])
 
     def set_option(self, name, value, section_name=None):
         # We need a loaded store

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-04-04 17:34:37 +0000
+++ b/bzrlib/tests/test_config.py	2011-04-05 15:08:41 +0000
@@ -1947,21 +1947,30 @@
         store.load()
         self.assertEquals([], list(store.get_sections()))
 
+    def assertSectionContent(self, expected, section):
+        """Assert that some options have the proper values in a section."""
+        expected_name, expected_options = expected
+        self.assertEquals(expected_name, section.id)
+        self.assertEquals(
+            expected_options,
+            dict([(k, section.get(k)) for k in expected_options.keys()]))
+
     def test_get_default_section(self):
         store = self.get_store('foo.conf', 'foo=bar')
         sections = list(store.get_sections())
         self.assertLength(1, sections)
-        self.assertEquals((None, {'foo': 'bar'}), sections[0])
+        self.assertSectionContent((None, {'foo': 'bar'}), sections[0])
 
     def test_get_named_section(self):
         store = self.get_store('foo.conf', '[baz]\nfoo=bar')
         sections = list(store.get_sections())
         self.assertLength(1, sections)
-        self.assertEquals(('baz', {'foo': 'bar'}), sections[0])
+        self.assertSectionContent(('baz', {'foo': 'bar'}), sections[0])
 
     def test_get_embedded_sections(self):
         # A more complicated example (which also shows that section names and
         # option names share the same name space...)
+        # FIXME: This is really specific to ConfigObjStore -- vila 2011-04-05
         store = self.get_store('foo.conf', '''
 foo=bar
 l=1,2
@@ -1978,14 +1987,16 @@
         self.assertLength(4, sections)
         # The default section has no name.
         # List values are provided as lists
-        self.assertEquals((None, {'foo': 'bar', 'l': ['1', '2']}), sections[0])
-        self.assertEquals(('DEFAULT', {'foo_in_DEFAULT': 'foo_DEFAULT'}),
-                          sections[1])
-        self.assertEquals(('bar', {'foo_in_bar': 'barbar'}), sections[2])
+        self.assertSectionContent((None, {'foo': 'bar', 'l': ['1', '2']}),
+                                  sections[0])
+        self.assertSectionContent(
+            ('DEFAULT', {'foo_in_DEFAULT': 'foo_DEFAULT'}), sections[1])
+        self.assertSectionContent(
+            ('bar', {'foo_in_bar': 'barbar'}), sections[2])
         # sub sections are provided as embedded dicts.
-        self.assertEquals(('baz', {'foo_in_baz': 'barbaz',
-                                   'qux': {'foo_in_qux': 'quux'}}),
-                          sections[3])
+        self.assertSectionContent(
+            ('baz', {'foo_in_baz': 'barbaz', 'qux': {'foo_in_qux': 'quux'}}),
+            sections[3])
 
     def test_set_option_in_default_section(self):
         store = self.get_store('foo.conf', '')



More information about the bazaar-commits mailing list