configglue team mailing list archive
-
configglue team
-
Mailing list archive
-
Message #00185
[Merge] lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue
Ricardo Kirkner has proposed merging lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue.
Requested reviews:
Configglue developers (configglue)
For more details, see:
https://code.launchpad.net/~ricardokirkner/configglue/parse-default-dict-value/+merge/65840
fix bug in parsing extra sections
--
https://code.launchpad.net/~ricardokirkner/configglue/parse-default-dict-value/+merge/65840
Your team Configglue developers is requested to review the proposed merge of lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue.
=== modified file 'configglue/pyschema/parser.py'
--- configglue/pyschema/parser.py 2011-06-23 17:03:25 +0000
+++ configglue/pyschema/parser.py 2011-06-24 21:53:26 +0000
@@ -15,6 +15,7 @@
#
###############################################################################
+import ast
import codecs
import collections
import copy
@@ -339,22 +340,29 @@
is_dict_option = isinstance(option_obj, DictOption)
is_dict_lines_option = (hasattr(option_obj, 'item') and
isinstance(option_obj.item, DictOption))
- is_default_value = unicode(option_obj.default) == value
+ is_default_value = value == option_obj.to_string(
+ option_obj.default)
# avoid adding implicit sections for dict default value
- if ((is_dict_option or is_dict_lines_option) and
- not is_default_value):
- sections = value.split()
- self.extra_sections.update(set(sections))
-
- if is_dict_option:
- base = option_obj
- else:
- base = option_obj.item
-
- for name in sections:
- nested = base.get_extra_sections(name, self)
- self.extra_sections.update(set(nested))
+ if (is_dict_option or is_dict_lines_option):
+ try:
+ is_default_value = (
+ ast.literal_eval(value) == option_obj.default)
+ except:
+ is_default_value = False
+
+ if not is_default_value:
+ sections = value.split()
+ self.extra_sections.update(set(sections))
+
+ if is_dict_option:
+ base = option_obj
+ else:
+ base = option_obj.item
+
+ for name in sections:
+ nested = base.get_extra_sections(name, self)
+ self.extra_sections.update(set(nested))
if is_default_value:
value = option_obj.default
=== modified file 'configglue/tests/pyschema/test_parser.py'
--- configglue/tests/pyschema/test_parser.py 2011-06-23 17:35:58 +0000
+++ configglue/tests/pyschema/test_parser.py 2011-06-24 21:53:26 +0000
@@ -667,6 +667,18 @@
extra_sections = parser.extra_sections
self.assertEqual(expected_sections, extra_sections)
+ def test_extra_sections_dict_default_value(self):
+ """Test parse dict with default value."""
+ class MySchema(Schema):
+ foo = DictOption(spec={
+ 'bar': IntOption(),
+ 'baz': BoolOption()})
+
+ parser = SchemaConfigParser(MySchema())
+ parser.parse('__main__', 'foo', "{'bar': 0, 'baz': False}")
+
+ self.assertEqual(parser.extra_sections, set([]))
+
def test_multiple_extra_sections(self):
"""Test parsing multiple extra sections."""
class MySchema(Schema):
Follow ups
-
[Merge] lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue
From: noreply, 2011-06-27
-
[Merge] lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue
From: Ricardo Kirkner, 2011-06-27
-
Re: [Merge] lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue
From: Ricardo Kirkner, 2011-06-27
-
[Merge] lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue
From: Ubuntu One Auto Pilot, 2011-06-27
-
Re: [Merge] lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue
From: Ubuntu One Auto Pilot, 2011-06-27
-
[Merge] lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue
From: Ricardo Kirkner, 2011-06-27
-
Re: [Merge] lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue
From: David Owen, 2011-06-27
-
Re: [Merge] lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue
From: Michael Nelson, 2011-06-27
-
[Merge] lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue
From: Ricardo Kirkner, 2011-06-27
-
[Merge] lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue
From: Ricardo Kirkner, 2011-06-24
-
[Merge] lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue
From: Ricardo Kirkner, 2011-06-24
-
[Merge] lp:~ricardokirkner/configglue/parse-default-dict-value into lp:configglue
From: Ricardo Kirkner, 2011-06-24