configglue team mailing list archive
-
configglue team
-
Mailing list archive
-
Message #00097
[Merge] lp:~ricardokirkner/configglue/refactor-options-booloption into lp:configglue
Ricardo Kirkner has proposed merging lp:~ricardokirkner/configglue/refactor-options-booloption into lp:configglue with lp:~ricardokirkner/configglue/refactor-options-intoption as a prerequisite.
Requested reviews:
Configglue developers (configglue)
For more details, see:
https://code.launchpad.net/~ricardokirkner/configglue/refactor-options-booloption/+merge/64438
--
https://code.launchpad.net/~ricardokirkner/configglue/refactor-options-booloption/+merge/64438
Your team Configglue developers is requested to review the proposed merge of lp:~ricardokirkner/configglue/refactor-options-booloption into lp:configglue.
=== modified file 'configglue/inischema/glue.py'
--- configglue/inischema/glue.py 2011-06-13 18:48:33 +0000
+++ configglue/inischema/glue.py 2011-06-13 18:48:33 +0000
@@ -27,7 +27,7 @@
from configglue.pyschema.glue import schemaconfigglue
from configglue.pyschema.parser import SchemaConfigParser
from configglue.pyschema.schema import (
- BoolConfigOption,
+ BoolOption,
ConfigSection,
IntOption,
LinesConfigOption,
@@ -60,7 +60,7 @@
parser2option = {'unicode': StringOption,
'int': IntOption,
- 'bool': BoolConfigOption,
+ 'bool': BoolOption,
'lines': LinesConfigOption}
class MySchema(Schema):
=== modified file 'configglue/pyschema/schema.py'
--- configglue/pyschema/schema.py 2011-06-13 18:48:33 +0000
+++ configglue/pyschema/schema.py 2011-06-13 18:48:33 +0000
@@ -22,6 +22,7 @@
__all__ = [
'BoolConfigOption',
+ 'BoolOption',
'ConfigOption',
'ConfigSection',
'DictConfigOption',
@@ -289,7 +290,7 @@
return str(value)
-class BoolConfigOption(ConfigOption):
+class BoolOption(ConfigOption):
"""A ConfigOption that is parsed into a bool"""
def _get_default(self):
@@ -596,3 +597,7 @@
class IntConfigOption(IntOption):
__metaclass__ = DeprecatedOption
+
+
+class BoolConfigOption(BoolOption):
+ __metaclass__ = DeprecatedOption
=== modified file 'doc/howto/custom-schema-options.rst'
--- doc/howto/custom-schema-options.rst 2011-06-13 18:48:33 +0000
+++ doc/howto/custom-schema-options.rst 2011-06-13 18:48:33 +0000
@@ -9,7 +9,7 @@
The :doc:`schema reference </topics/schemas>` documentation explains how to
use configglue's standard option classes --
-:class:`~configglue.pyschema.schema.BoolConfigOption`,
+:class:`~configglue.pyschema.schema.BoolOption`,
:class:`~configglue.pyschema.schema.IntOption`, etc. For many purposes,
those classes are all you'll need. Sometimes, though, the configglue version
won't meet your precise requirements, or you'll want to use a option that is
=== modified file 'doc/intro/quickstart.rst'
--- doc/intro/quickstart.rst 2011-06-13 18:48:33 +0000
+++ doc/intro/quickstart.rst 2011-06-13 18:48:33 +0000
@@ -29,7 +29,7 @@
# create the schema
class MySchema(pyschema.Schema):
foo = pyschema.IntOption()
- bar = pyschema.BoolConfigOption()
+ bar = pyschema.BoolOption()
# read the configuration files
scp = pyschema.SchemaConfigParser(MySchema())
@@ -74,7 +74,7 @@
class MySchema(pyschema.Schema):
foo = pyschema.IntOption()
- bar = pyschema.BoolConfigOption()
+ bar = pyschema.BoolOption()
#. Create a parser for that schema
@@ -130,7 +130,7 @@
# create the schema
class MySchema(pyschema.Schema):
foo = pyschema.IntOption()
- bar = pyschema.BoolConfigOption()
+ bar = pyschema.BoolOption()
# glue everything together
glue = pyschema.configglue(MySchema, ['config.ini'])
=== modified file 'doc/ref/schemas/options.rst'
--- doc/ref/schemas/options.rst 2011-06-13 18:48:33 +0000
+++ doc/ref/schemas/options.rst 2011-06-13 18:48:33 +0000
@@ -104,10 +104,10 @@
.. currentmodule:: configglue.pyschema.schema
-``BoolConfigOption``
+``BoolOption``
--------------------
-.. class:: BoolConfigOption([**attributes])
+.. class:: BoolOption([**attributes])
A true/false option.
=== modified file 'doc/topics/config-file.rst'
--- doc/topics/config-file.rst 2011-06-13 18:48:33 +0000
+++ doc/topics/config-file.rst 2011-06-13 18:48:33 +0000
@@ -106,7 +106,7 @@
class MySchema(pyschema.Schema):
my_dict = pyschema.DictConfigOption(
spec={'foo': pyschema.IntOption(),
- 'bar': pyschema.BoolConfigOption()})
+ 'bar': pyschema.BoolOption()})
`my_dict` would be parsed as::
=== modified file 'doc/topics/schemas.rst'
--- doc/topics/schemas.rst 2011-06-13 18:48:33 +0000
+++ doc/topics/schemas.rst 2011-06-13 18:48:33 +0000
@@ -152,7 +152,7 @@
class BaseSchema(pyschema.Schema):
option1 = pyschema.IntOption()
class section1(pyschema.ConfigSection):
- option1 = pyschema.BoolConfigOption()
+ option1 = pyschema.BoolOption()
class ChildSchema(BaseSchema):
@@ -173,7 +173,7 @@
option1 = pyschema.IntOption()
option2 = pyschema.IntOption()
class section1(pyschema.ConfigSection):
- option1 = pyschema.BoolConfigOption()
+ option1 = pyschema.BoolOption()
option2 = IntOption()
=== modified file 'tests/pyschema/test_parser.py'
--- tests/pyschema/test_parser.py 2011-06-13 18:48:33 +0000
+++ tests/pyschema/test_parser.py 2011-06-13 18:48:33 +0000
@@ -42,7 +42,7 @@
SchemaValidationError,
)
from configglue.pyschema.schema import (
- BoolConfigOption,
+ BoolOption,
ConfigSection,
DictConfigOption,
IntOption,
@@ -179,7 +179,7 @@
def test_basic_interpolate(self):
class MySchema(Schema):
foo = StringOption()
- bar = BoolConfigOption()
+ bar = BoolOption()
config = StringIO('[__main__]\nbar=%(foo)s\nfoo=True')
parser = SchemaConfigParser(MySchema())
parser.readfp(config, 'my.cfg')
@@ -189,7 +189,7 @@
def test_interpolate_missing_option(self):
class MySchema(Schema):
foo = StringOption()
- bar = BoolConfigOption()
+ bar = BoolOption()
section = '__main__'
option = 'foo'
@@ -202,7 +202,7 @@
def test_interpolate_too_deep(self):
class MySchema(Schema):
foo = StringOption()
- bar = BoolConfigOption()
+ bar = BoolOption()
section = '__main__'
option = 'foo'
@@ -215,7 +215,7 @@
def test_interpolate_incomplete_format(self):
class MySchema(Schema):
foo = StringOption()
- bar = BoolConfigOption()
+ bar = BoolOption()
section = '__main__'
option = 'foo'
@@ -277,7 +277,7 @@
def test_get_interpolation_keys_bool(self):
class MySchema(Schema):
- foo = BoolConfigOption()
+ foo = BoolOption()
config = StringIO("[__main__]\nfoo=%(bar)s")
expected = ('%(bar)s', set(['bar']))
@@ -534,7 +534,7 @@
def test_default_values(self):
class MySchema(Schema):
- foo = BoolConfigOption(default=True)
+ foo = BoolOption(default=True)
class bar(ConfigSection):
baz = IntOption()
@@ -747,7 +747,7 @@
def test_set_non_string(self):
class MySchema(Schema):
foo = IntOption()
- bar = BoolConfigOption()
+ bar = BoolOption()
parser = SchemaConfigParser(MySchema())
parser.parse_all()
=== modified file 'tests/pyschema/test_schema.py'
--- tests/pyschema/test_schema.py 2011-06-13 18:48:33 +0000
+++ tests/pyschema/test_schema.py 2011-06-13 18:48:33 +0000
@@ -22,6 +22,7 @@
from configglue.pyschema.parser import SchemaConfigParser
from configglue.pyschema.schema import (
BoolConfigOption,
+ BoolOption,
ConfigOption,
ConfigSection,
DictConfigOption,
@@ -39,20 +40,20 @@
class TestSchema(unittest.TestCase):
def test_sections(self):
class MySchema(Schema):
- foo = BoolConfigOption()
+ foo = BoolOption()
class MyOtherSchema(Schema):
class web(ConfigSection):
bar = IntOption()
class froo(ConfigSection):
- twaddle = LinesConfigOption(item=BoolConfigOption())
+ twaddle = LinesConfigOption(item=BoolOption())
class MyThirdSchema(Schema):
bar = IntOption()
class froo(ConfigSection):
- twaddle = LinesConfigOption(item=BoolConfigOption())
+ twaddle = LinesConfigOption(item=BoolOption())
schema = MySchema()
names = set(s.name for s in schema.sections())
@@ -69,7 +70,7 @@
def test_schema_validation(self):
class BorkenSchema(Schema):
class __main__(ConfigSection):
- foo = BoolConfigOption()
+ foo = BoolOption()
class SomeSchema(Schema):
class mysection(ConfigSection):
@@ -83,7 +84,7 @@
def test_names(self):
class MySchema(Schema):
- foo = BoolConfigOption()
+ foo = BoolOption()
class bar(ConfigSection):
baz = IntOption()
@@ -97,7 +98,7 @@
def test_options(self):
class MySchema(Schema):
- foo = BoolConfigOption()
+ foo = BoolOption()
class bar(ConfigSection):
baz = IntOption()
@@ -356,10 +357,12 @@
cls = IntConfigOption
-class TestBoolConfigOption(unittest.TestCase):
+class TestBoolOption(unittest.TestCase):
+ cls = BoolOption
+
def test_parse_bool(self):
class MySchema(Schema):
- foo = BoolConfigOption()
+ foo = self.cls()
config = StringIO("[__main__]\nfoo = Yes")
expected_values = {'__main__': {'foo': True}}
@@ -384,18 +387,22 @@
self.assertRaises(ValueError, parser.values)
def test_default(self):
- opt = BoolConfigOption()
+ opt = self.cls()
self.assertEqual(opt.default, False)
def test_validate_bool(self):
- opt = BoolConfigOption()
+ opt = self.cls()
self.assertEqual(opt.validate(False), True)
def test_validate_nonbool(self):
- opt = BoolConfigOption()
+ opt = self.cls()
self.assertEqual(opt.validate(''), False)
+class TestBoolConfigOption(TestBoolOption):
+ cls = BoolConfigOption
+
+
class TestLinesConfigOption(unittest.TestCase):
def test_parse_int_lines(self):
class MySchema(Schema):
@@ -410,7 +417,7 @@
def test_parse_bool_lines(self):
class MySchema(Schema):
- foo = LinesConfigOption(item=BoolConfigOption())
+ foo = LinesConfigOption(item=BoolOption())
schema = MySchema()
config = StringIO("[__main__]\nfoo = tRuE\n No\n 0\n 1")
@@ -421,7 +428,7 @@
def test_parse_bool_empty_lines(self):
class MySchema(Schema):
- foo = LinesConfigOption(item=BoolConfigOption())
+ foo = LinesConfigOption(item=BoolOption())
schema = MySchema()
config = StringIO("[__main__]\nfoo =")
@@ -432,7 +439,7 @@
def test_parse_bool_invalid_lines(self):
class MySchema(Schema):
- foo = LinesConfigOption(item=BoolConfigOption())
+ foo = LinesConfigOption(item=BoolOption())
schema = MySchema()
config = StringIO("[__main__]\nfoo = bla")
@@ -542,7 +549,7 @@
self.assertEqual(opt.spec, {})
self.assertEqual(opt.strict, False)
- spec = {'a': IntOption(), 'b': BoolConfigOption()}
+ spec = {'a': IntOption(), 'b': BoolOption()}
opt = DictConfigOption(spec=spec)
self.assertEqual(opt.spec, spec)
self.assertEqual(opt.strict, False)
@@ -576,7 +583,7 @@
foo = DictConfigOption(spec={
'bar': StringOption(),
'baz': IntOption(),
- 'bla': BoolConfigOption(),
+ 'bla': BoolOption(),
})
config = StringIO("""[__main__]
@@ -600,7 +607,7 @@
foo = DictConfigOption(spec={
'bar': StringOption(),
'baz': IntOption(),
- 'bla': BoolConfigOption(),
+ 'bla': BoolOption(),
})
config = StringIO("""[__main__]
@@ -728,7 +735,7 @@
spec={
'bar': StringOption(),
'baz': IntOption(),
- 'bla': BoolConfigOption(),
+ 'bla': BoolOption(),
}))
config = StringIO("""[__main__]
@@ -758,7 +765,7 @@
def test_parse_dict_with_dicts(self):
innerspec = {'bar': StringOption(),
'baz': IntOption(),
- 'bla': BoolConfigOption(),
+ 'bla': BoolOption(),
}
spec = {'name': StringOption(),
'size': IntOption(),
Follow ups