← Back to team overview

configglue team mailing list archive

[Merge] lp:~ricardokirkner/configglue/partial-section-overrides into lp:configglue

 

Ricardo Kirkner has proposed merging lp:~ricardokirkner/configglue/partial-section-overrides into lp:configglue.

Commit message:
fixed reading same section from multiple files overrides whole section

Requested reviews:
  Configglue developers (configglue)

For more details, see:
https://code.launchpad.net/~ricardokirkner/configglue/partial-section-overrides/+merge/175115
-- 
https://code.launchpad.net/~ricardokirkner/configglue/partial-section-overrides/+merge/175115
Your team Configglue developers is requested to review the proposed merge of lp:~ricardokirkner/configglue/partial-section-overrides into lp:configglue.
=== modified file 'configglue/parser.py'
--- configglue/parser.py	2013-07-15 12:25:48 +0000
+++ configglue/parser.py	2013-07-16 20:03:38 +0000
@@ -289,7 +289,11 @@
             sub_parser._location = self._location
             sub_parser.read(filenames)
             # update current parser with those values
-            self._sections.update(sub_parser._sections)
+            for section, options in sub_parser._sections.items():
+                if section in self._sections:
+                    self._sections[section].update(options)
+                else:
+                    self._sections[section] = options
 
             self._basedir = old_basedir
 

=== modified file 'configglue/tests/test_parser.py'
--- configglue/tests/test_parser.py	2013-07-15 18:04:20 +0000
+++ configglue/tests/test_parser.py	2013-07-16 20:03:38 +0000
@@ -1004,6 +1004,48 @@
         self.parser.read(files)
         self.assertEqual(self.parser.values(), {'__main__': {'foo': 'bar'}})
 
+    def test_interpolate_using_noschema_from_multiple_files(self):
+        """Test interpolation across files."""
+        def setup_config():
+            folder = tempfile.mkdtemp()
+            self.addCleanup(shutil.rmtree, folder)
+
+            f = codecs.open("%s/first.cfg" % folder, 'w',
+                            encoding=CONFIG_FILE_ENCODING)
+            config = textwrap.dedent(
+                """
+                [__noschema__]
+                bar = 42
+                [one]
+                foo = %(bar)s
+                """)
+            f.write(config)
+            f.close()
+
+            f = codecs.open("%s/second.cfg" % folder, 'w',
+                            encoding=CONFIG_FILE_ENCODING)
+            f.write("[__main__]\nincludes = third.cfg")
+            f.close()
+
+            f = codecs.open("%s/third.cfg" % folder, 'w',
+                            encoding=CONFIG_FILE_ENCODING)
+            f.write("[__noschema__]\nbaz = 3")
+            f.close()
+
+            files = ["%s/first.cfg" % folder, "%s/second.cfg" % folder]
+            return files, folder
+
+        class MySchema(Schema):
+            class one(Section):
+                foo = IntOption()
+
+        files, folder = setup_config()
+        expected_values = {'one': {'foo': 42}}
+
+        parser = SchemaConfigParser(MySchema())
+        parser.read(files)
+        self.assertEqual(parser.values(), expected_values)
+
     def test_read_utf8_encoded_file(self):
         # create config file
         fp, filename = tempfile.mkstemp()


Follow ups