← Back to team overview

configglue team mailing list archive

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

 

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

Requested reviews:
  Configglue developers (configglue)

For more details, see:
https://code.launchpad.net/~ricardokirkner/configglue/refactor-options-tupleoption/+merge/64447
-- 
https://code.launchpad.net/~ricardokirkner/configglue/refactor-options-tupleoption/+merge/64447
Your team Configglue developers is requested to review the proposed merge of lp:~ricardokirkner/configglue/refactor-options-tupleoption into lp:configglue.
=== modified file 'configglue/pyschema/schema.py'
--- configglue/pyschema/schema.py	2011-06-13 18:56:07 +0000
+++ configglue/pyschema/schema.py	2011-06-13 18:56:08 +0000
@@ -35,6 +35,7 @@
     'StringConfigOption',
     'StringOption',
     'TupleConfigOption',
+    'TupleOption',
 ]
 
 NO_DEFAULT = object()
@@ -433,7 +434,7 @@
         return isinstance(value, basestring)
 
 
-class TupleConfigOption(ConfigOption):
+class TupleOption(ConfigOption):
     """A ConfigOption that is parsed into a fixed-size tuple of strings.
 
     The number of items in the tuple should be specified with the 'length'
@@ -443,7 +444,7 @@
 
     def __init__(self, name='', length=0, raw=False, default=NO_DEFAULT,
         fatal=False, help='', action='store'):
-        super(TupleConfigOption, self).__init__(name=name, raw=raw,
+        super(TupleOption, self).__init__(name=name, raw=raw,
             default=default, fatal=fatal, help=help, action=action)
         self.length = length
 
@@ -611,3 +612,7 @@
 
 class LinesConfigOption(ListOption):
     __metaclass__ = DeprecatedOption
+
+
+class TupleConfigOption(TupleOption):
+    __metaclass__ = DeprecatedOption

=== modified file 'doc/ref/schemas/options.rst'
--- doc/ref/schemas/options.rst	2011-06-13 18:56:07 +0000
+++ doc/ref/schemas/options.rst	2011-06-13 18:56:08 +0000
@@ -154,14 +154,14 @@
     instead of just leaving it as the string 'None'.
 
 
-``TupleConfigOption``
+``TupleOption``
 ---------------------
 
-.. class:: TupleConfigOption([length=0, **attributes])
+.. class:: TupleOption([length=0, **attributes])
 
 A tuple of elements.
 
-.. attribute:: TupleConfigOption.length
+.. attribute:: TupleOption.length
 
     *Optional*.
 

=== modified file 'doc/topics/config-file.rst'
--- doc/topics/config-file.rst	2011-06-13 18:56:07 +0000
+++ doc/topics/config-file.rst	2011-06-13 18:56:08 +0000
@@ -66,7 +66,7 @@
 Tuples
 ------
 
-For specifying the value of a :class:`~configglue.pyschema.schema.TupleConfigOption`,
+For specifying the value of a :class:`~configglue.pyschema.schema.TupleOption`,
 you just put all the values in the same line, separated by `,`, as shown::
 
     my_tuple = 1, 2, 3

=== modified file 'tests/pyschema/test_parser.py'
--- tests/pyschema/test_parser.py	2011-06-13 18:56:07 +0000
+++ tests/pyschema/test_parser.py	2011-06-13 18:56:08 +0000
@@ -49,7 +49,7 @@
     ListOption,
     Schema,
     StringOption,
-    TupleConfigOption,
+    TupleOption,
 )
 
 
@@ -288,7 +288,7 @@
 
     def test_get_interpolation_keys_tuple(self):
         class MySchema(Schema):
-            foo = TupleConfigOption(2)
+            foo = TupleOption(2)
         config = StringIO("[__main__]\nfoo=%(bar)s,%(baz)s")
         expected = ('%(bar)s,%(baz)s', set(['bar', 'baz']))
 
@@ -310,7 +310,7 @@
 
     def test_get_interpolation_keys_tuple_lines(self):
         class MySchema(Schema):
-            foo = ListOption(item=TupleConfigOption(2))
+            foo = ListOption(item=TupleOption(2))
         config = StringIO(
             "[__main__]\nfoo=%(bar)s,%(bar)s\n    %(baz)s,%(baz)s")
         expected = ('%(bar)s,%(bar)s\n%(baz)s,%(baz)s',
@@ -341,7 +341,7 @@
 
     def test_interpolate_value_duplicate_key(self):
         class MySchema(Schema):
-            foo = TupleConfigOption(2)
+            foo = TupleOption(2)
         config = StringIO(
             "[__noschema__]\nbar=4\n[__main__]\nfoo=%(bar)s,%(bar)s")
         expected_value = '4,4'
@@ -353,7 +353,7 @@
 
     def test_interpolate_value_invalid_key(self):
         class MySchema(Schema):
-            foo = TupleConfigOption(2)
+            foo = TupleOption(2)
         config = StringIO("[other]\nbar=4\n[__main__]\nfoo=%(bar)s,%(bar)s")
         expected_value = None
 
@@ -364,7 +364,7 @@
 
     def test_interpolate_value_no_keys(self):
         class MySchema(Schema):
-            foo = TupleConfigOption(2)
+            foo = TupleOption(2)
         config = StringIO("[__main__]\nfoo=%(bar)s,%(bar)s")
 
         mock_get_interpolation_keys = Mock(return_value=('%(bar)s', None))

=== modified file 'tests/pyschema/test_schema.py'
--- tests/pyschema/test_schema.py	2011-06-13 18:56:07 +0000
+++ tests/pyschema/test_schema.py	2011-06-13 18:56:08 +0000
@@ -35,6 +35,7 @@
     StringConfigOption,
     StringOption,
     TupleConfigOption,
+    TupleOption,
     get_config_objects,
 )
 
@@ -495,19 +496,21 @@
     cls = LinesConfigOption
 
 
-class TestTupleConfigOption(unittest.TestCase):
+class TestTupleOption(unittest.TestCase):
+    cls = TupleOption
+
     def test_init(self):
-        opt = TupleConfigOption(length=2)
+        opt = self.cls(length=2)
         self.assertEqual(opt.length, 2)
 
     def test_init_no_length(self):
-        opt = TupleConfigOption()
+        opt = self.cls()
         self.assertEqual(opt.length, 0)
         self.assertEqual(opt.default, ())
 
     def test_parse_no_length(self):
         class MySchema(Schema):
-            foo = TupleConfigOption()
+            foo = self.cls()
 
         config = StringIO('[__main__]\nfoo=1,2,3,4')
         expected_values = {'__main__': {'foo': ('1', '2', '3', '4')}}
@@ -517,7 +520,7 @@
 
     def test_parse_tuple(self):
         class MySchema(Schema):
-            foo = TupleConfigOption(length=4)
+            foo = self.cls(length=4)
 
         config = StringIO('[__main__]\nfoo = 1, 2, 3, 4')
         expected_values = {'__main__': {'foo': ('1', '2', '3', '4')}}
@@ -537,18 +540,22 @@
         self.assertRaises(ValueError, parser.values)
 
     def test_default(self):
-        opt = TupleConfigOption(length=2)
+        opt = self.cls(length=2)
         self.assertEqual(opt.default, ())
 
     def test_validate_tuple(self):
-        opt = TupleConfigOption(length=2)
+        opt = self.cls(length=2)
         self.assertEqual(opt.validate(()), True)
 
     def test_validate_nontuple(self):
-        opt = TupleConfigOption(length=2)
+        opt = self.cls(length=2)
         self.assertEqual(opt.validate(0), False)
 
 
+class TestTupleConfigOption(TupleOption):
+    cls = TupleConfigOption
+
+
 class TestDictOption(unittest.TestCase):
     cls = DictOption
 
@@ -807,7 +814,7 @@
 class TestListOfTuples(unittest.TestCase):
     def setUp(self):
         class MySchema(Schema):
-            foo = ListOption(item=TupleConfigOption(length=3))
+            foo = ListOption(item=TupleOption(length=3))
 
         schema = MySchema()
         self.parser = SchemaConfigParser(schema)


Follow ups