← Back to team overview

configglue team mailing list archive

[Merge] lp:~ricardokirkner/configglue/refactor-options-listoption into lp:configglue

 

Ricardo Kirkner has proposed merging lp:~ricardokirkner/configglue/refactor-options-listoption into lp:configglue with lp:~ricardokirkner/configglue/refactor-options-dictoption as a prerequisite.

Requested reviews:
  Configglue developers (configglue)

For more details, see:
https://code.launchpad.net/~ricardokirkner/configglue/refactor-options-listoption/+merge/64445
-- 
https://code.launchpad.net/~ricardokirkner/configglue/refactor-options-listoption/+merge/64445
Your team Configglue developers is requested to review the proposed merge of lp:~ricardokirkner/configglue/refactor-options-listoption into lp:configglue.
=== modified file 'configglue/inischema/glue.py'
--- configglue/inischema/glue.py	2011-06-13 18:55:57 +0000
+++ configglue/inischema/glue.py	2011-06-13 18:55:57 +0000
@@ -30,7 +30,7 @@
     BoolOption,
     ConfigSection,
     IntOption,
-    LinesConfigOption,
+    ListOption,
     Schema,
     StringOption,
 )
@@ -61,7 +61,7 @@
     parser2option = {'unicode': StringOption,
                      'int': IntOption,
                      'bool': BoolOption,
-                     'lines': LinesConfigOption}
+                     'lines': ListOption}
 
     class MySchema(Schema):
         pass

=== modified file 'configglue/pyschema/schema.py'
--- configglue/pyschema/schema.py	2011-06-13 18:55:57 +0000
+++ configglue/pyschema/schema.py	2011-06-13 18:55:57 +0000
@@ -30,6 +30,7 @@
     'IntConfigOption',
     'IntOption',
     'LinesConfigOption',
+    'ListOption',
     'Schema',
     'StringConfigOption',
     'StringOption',
@@ -74,7 +75,7 @@
     """
 
     def __init__(self):
-        self.includes = LinesConfigOption(item=StringOption())
+        self.includes = ListOption(item=StringOption())
         self._sections = {}
         # add section and options to the schema
         for name, item in get_config_objects(self.__class__):
@@ -338,7 +339,7 @@
         return isinstance(value, int)
 
 
-class LinesConfigOption(ConfigOption):
+class ListOption(ConfigOption):
     """A ConfigOption that is parsed into a list of objects
 
     All items in the list need to be of the same type.  The 'item' constructor
@@ -356,7 +357,7 @@
 
     def __init__(self, name='', item=None, raw=False, default=NO_DEFAULT,
         fatal=False, help='', action='store', remove_duplicates=False):
-        super(LinesConfigOption, self).__init__(name=name, raw=raw,
+        super(ListOption, self).__init__(name=name, raw=raw,
             default=default, fatal=fatal, help=help, action=action)
         self.item = item
         self.require_parser = item.require_parser
@@ -606,3 +607,7 @@
 
 class DictConfigOption(DictOption):
     __metaclass__ = DeprecatedOption
+
+
+class LinesConfigOption(ListOption):
+    __metaclass__ = DeprecatedOption

=== modified file 'doc/ref/schemas/options.rst'
--- doc/ref/schemas/options.rst	2011-06-13 18:55:57 +0000
+++ doc/ref/schemas/options.rst	2011-06-13 18:55:57 +0000
@@ -118,21 +118,21 @@
 
 An integer.
 
-``LinesConfigOption``
+``ListOption``
 ---------------------
 
-.. class:: LinesConfigOption(item, [remove_duplicates=False, **attributes])
+.. class:: ListOption(item, [remove_duplicates=False, **attributes])
 
 A list of items.
 
-.. attribute:: LinesConfigOption.item
+.. attribute:: ListOption.item
 
     *Required*.
 
     List elements will be parsed as being of this type. Should be an
     instance of a subclass of :class:`~configglue.pyschema.schema.ConfigOption`.
 
-.. attribute:: LinesConfigOption.remove_duplicates
+.. attribute:: ListOption.remove_duplicates
 
     *Optional*.
 

=== modified file 'doc/topics/config-file.rst'
--- doc/topics/config-file.rst	2011-06-13 18:55:57 +0000
+++ doc/topics/config-file.rst	2011-06-13 18:55:57 +0000
@@ -76,7 +76,7 @@
 Lists
 -----
 
-For specifying the value of a :class:`~configglue.pyschema.schema.LinesConfigOption`,
+For specifying the value of a :class:`~configglue.pyschema.schema.ListOption`,
 you just put each value on a different line, as shown::
 
     my_list = 1

=== modified file 'doc/topics/schemas.rst'
--- doc/topics/schemas.rst	2011-06-13 18:55:57 +0000
+++ doc/topics/schemas.rst	2011-06-13 18:55:57 +0000
@@ -70,8 +70,8 @@
 
 Each option takes a certain set of option-specific arguments (documented in
 the :ref:`schema option reference <schema-option-types>`). For example,
-:class:`~configglue.pyschema.schema.LinesConfigOption` (and its subclasses)
-require a :attr:`~configglue.pyschema.schema.LinesConfigOption.item` argument
+:class:`~configglue.pyschema.schema.ListOption` (and its subclasses)
+require a :attr:`~configglue.pyschema.schema.ListOption.item` argument
 which specifies the type of the items contained in the list.
 
 There's also a set of common arguments available to all option types. All are

=== modified file 'tests/pyschema/test_parser.py'
--- tests/pyschema/test_parser.py	2011-06-13 18:55:57 +0000
+++ tests/pyschema/test_parser.py	2011-06-13 18:55:57 +0000
@@ -46,7 +46,7 @@
     ConfigSection,
     DictOption,
     IntOption,
-    LinesConfigOption,
+    ListOption,
     Schema,
     StringOption,
     TupleConfigOption,
@@ -299,7 +299,7 @@
 
     def test_get_interpolation_keys_lines(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(item=StringOption())
+            foo = ListOption(item=StringOption())
         config = StringIO("[__main__]\nfoo=%(bar)s\n    %(baz)s")
         expected = ('%(bar)s\n%(baz)s', set(['bar', 'baz']))
 
@@ -310,7 +310,7 @@
 
     def test_get_interpolation_keys_tuple_lines(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(item=TupleConfigOption(2))
+            foo = ListOption(item=TupleConfigOption(2))
         config = StringIO(
             "[__main__]\nfoo=%(bar)s,%(bar)s\n    %(baz)s,%(baz)s")
         expected = ('%(bar)s,%(bar)s\n%(baz)s,%(baz)s',
@@ -587,7 +587,7 @@
 
     def test_multiple_extra_sections(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(
+            foo = ListOption(
                 item=DictOption(spec={'bar': IntOption()}))
 
         config = StringIO('[__main__]\nfoo=d1\n    d2\n    d3\n'
@@ -653,7 +653,7 @@
 
     def test_multi_file_dict_list_config(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(
+            foo = ListOption(
                 item=DictOption(spec={
                     'bar': IntOption(),
                     'baz': IntOption(),
@@ -1020,7 +1020,7 @@
 
     def test_extra_sections_when_lines_dict_with_nested_dicts(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(
+            foo = ListOption(
                 item=DictOption(item=DictOption()))
 
         config = StringIO("""
@@ -1049,7 +1049,7 @@
     def test_extra_sections_when_dict_with_nested_lines_dicts(self):
         class MySchema(Schema):
             foo = DictOption(
-                item=LinesConfigOption(item=DictOption()))
+                item=ListOption(item=DictOption()))
 
         config = StringIO("""
 [__main__]
@@ -1072,9 +1072,9 @@
 
     def test_extra_sections_when_lines_dict_with_nested_lines_dicts(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(
+            foo = ListOption(
                 item=DictOption(
-                    item=LinesConfigOption(item=DictOption())))
+                    item=ListOption(item=DictOption())))
 
         config = StringIO("""
 [__main__]
@@ -1107,7 +1107,7 @@
 
     def test_multiple_extra_sections(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(
+            foo = ListOption(
                 item=DictOption(spec={'bar': IntOption()}))
 
         config = StringIO('[__main__]\nfoo=d1\n    d2\n    d3\n'

=== modified file 'tests/pyschema/test_schema.py'
--- tests/pyschema/test_schema.py	2011-06-13 18:55:57 +0000
+++ tests/pyschema/test_schema.py	2011-06-13 18:55:57 +0000
@@ -30,6 +30,7 @@
     IntConfigOption,
     IntOption,
     LinesConfigOption,
+    ListOption,
     Schema,
     StringConfigOption,
     StringOption,
@@ -48,13 +49,13 @@
                 bar = IntOption()
 
             class froo(ConfigSection):
-                twaddle = LinesConfigOption(item=BoolOption())
+                twaddle = ListOption(item=BoolOption())
 
         class MyThirdSchema(Schema):
             bar = IntOption()
 
             class froo(ConfigSection):
-                twaddle = LinesConfigOption(item=BoolOption())
+                twaddle = ListOption(item=BoolOption())
 
         schema = MySchema()
         names = set(s.name for s in schema.sections())
@@ -404,10 +405,12 @@
     cls = BoolConfigOption
 
 
-class TestLinesConfigOption(unittest.TestCase):
+class TestListOption(unittest.TestCase):
+    cls = ListOption
+
     def test_parse_int_lines(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(item=IntOption())
+            foo = self.cls(item=IntOption())
 
         config = StringIO("[__main__]\nfoo = 42\n 43\n 44")
         expected_values = {'__main__': {'foo': [42, 43, 44]}}
@@ -418,7 +421,7 @@
 
     def test_parse_bool_lines(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(item=BoolOption())
+            foo = self.cls(item=BoolOption())
 
         schema = MySchema()
         config = StringIO("[__main__]\nfoo = tRuE\n No\n 0\n 1")
@@ -429,7 +432,7 @@
 
     def test_parse_bool_empty_lines(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(item=BoolOption())
+            foo = self.cls(item=BoolOption())
 
         schema = MySchema()
         config = StringIO("[__main__]\nfoo =")
@@ -440,7 +443,7 @@
 
     def test_parse_bool_invalid_lines(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(item=BoolOption())
+            foo = self.cls(item=BoolOption())
 
         schema = MySchema()
         config = StringIO("[__main__]\nfoo = bla")
@@ -454,13 +457,12 @@
         self.assertRaises(ValueError, parser.values)
 
     def test_default(self):
-        opt = LinesConfigOption(item=IntOption())
+        opt = self.cls(item=IntOption())
         self.assertEqual(opt.default, [])
 
     def test_remove_duplicates(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(item=StringOption(),
-                                    remove_duplicates=True)
+            foo = self.cls(item=StringOption(), remove_duplicates=True)
 
         schema = MySchema()
         config = StringIO("[__main__]\nfoo = bla\n blah\n bla")
@@ -471,8 +473,7 @@
 
     def test_remove_dict_duplicates(self):
         class MyOtherSchema(Schema):
-            foo = LinesConfigOption(item=DictOption(),
-                                    remove_duplicates=True)
+            foo = self.cls(item=DictOption(), remove_duplicates=True)
 
         schema = MyOtherSchema()
         config = StringIO("[__main__]\nfoo = bla\n bla\n[bla]\nbar = baz")
@@ -482,14 +483,18 @@
                           parser.values())
 
     def test_validate_list(self):
-        opt = LinesConfigOption(item=IntOption())
+        opt = self.cls(item=IntOption())
         self.assertEqual(opt.validate([]), True)
 
     def test_validate_nonlist(self):
-        opt = LinesConfigOption(item=IntOption())
+        opt = self.cls(item=IntOption())
         self.assertEqual(opt.validate(''), False)
 
 
+class TestLinesConfigOption(TestListOption):
+    cls = LinesConfigOption
+
+
 class TestTupleConfigOption(unittest.TestCase):
     def test_init(self):
         opt = TupleConfigOption(length=2)
@@ -735,10 +740,10 @@
     cls = DictConfigOption
 
 
-class TestLinesOfDictOption(unittest.TestCase):
+class TestListOfDictOption(unittest.TestCase):
     def test_parse_lines_of_dict(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(item=DictOption(
+            foo = ListOption(item=DictOption(
                 spec={
                     'bar': StringOption(),
                     'baz': IntOption(),
@@ -802,7 +807,7 @@
 class TestListOfTuples(unittest.TestCase):
     def setUp(self):
         class MySchema(Schema):
-            foo = LinesConfigOption(item=TupleConfigOption(length=3))
+            foo = ListOption(item=TupleConfigOption(length=3))
 
         schema = MySchema()
         self.parser = SchemaConfigParser(schema)


Follow ups