[pypy-svn] r32792 - in pypy/branch/even-more-config/pypy/config: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Sun Oct 1 18:53:56 CEST 2006
Author: cfbolz
Date: Sun Oct 1 18:53:53 2006
New Revision: 32792
Modified:
pypy/branch/even-more-config/pypy/config/config.py
pypy/branch/even-more-config/pypy/config/test/test_config.py
pypy/branch/even-more-config/pypy/config/test/test_pypyoption.py
Log:
Don't allow the changing of options, once set, at all.
Modified: pypy/branch/even-more-config/pypy/config/config.py
==============================================================================
--- pypy/branch/even-more-config/pypy/config/config.py (original)
+++ pypy/branch/even-more-config/pypy/config/config.py Sun Oct 1 18:53:53 2006
@@ -24,6 +24,7 @@
for name, value in overrides.iteritems():
subconfig, name = self._cfgimpl_get_by_path(name)
setattr(subconfig, name, value)
+ subconfig._cfgimpl_value_owners[name] = 'default'
def __setattr__(self, name, value):
if self._cfgimpl_frozen and getattr(self, name) != value:
@@ -45,11 +46,9 @@
child = getattr(self._cfgimpl_descr, name)
oldowner = self._cfgimpl_value_owners[child._name]
oldvalue = getattr(self, name)
- if oldowner == 'required':
- if oldvalue != value:
- raise ValueError('can not override value %s for option %s' %
- (value, name))
- return
+ if oldvalue != value and oldowner != "default":
+ raise ValueError('can not override value %s for option %s' %
+ (value, name))
child.setoption(self, value)
self._cfgimpl_value_owners[name] = who
@@ -156,7 +155,7 @@
raise NotImplemented('abstract base class')
class ChoiceOption(Option):
- def __init__(self, name, doc, values, default, requires=None,
+ def __init__(self, name, doc, values, default=None, requires=None,
cmdline=DEFAULT_OPTION_NAME):
super(ChoiceOption, self).__init__(name, doc, cmdline)
self.values = values
@@ -174,7 +173,7 @@
super(ChoiceOption, self).setoption(config, value)
def validate(self, value):
- return value in self.values
+ return value is None or value in self.values
def add_optparse_option(self, argnames, parser, config):
def _callback(option, opt_str, value, parser, *args, **kwargs):
@@ -195,6 +194,9 @@
requires=requires,
cmdline=cmdline)
+ def validate(self, value):
+ return isinstance(value, bool)
+
def add_optparse_option(self, argnames, parser, config):
def _callback(option, opt_str, value, parser, *args, **kwargs):
try:
@@ -205,6 +207,7 @@
action='callback',
callback=_callback, *argnames)
+
class IntOption(Option):
def __init__(self, name, doc, default=0, cmdline=DEFAULT_OPTION_NAME):
super(IntOption, self).__init__(name, doc, cmdline)
Modified: pypy/branch/even-more-config/pypy/config/test/test_config.py
==============================================================================
--- pypy/branch/even-more-config/pypy/config/test/test_config.py (original)
+++ pypy/branch/even-more-config/pypy/config/test/test_config.py Sun Oct 1 18:53:53 2006
@@ -12,10 +12,15 @@
wantref_option = BoolOption('wantref', 'Test requires', default=False,
requires=[('gc.name', 'ref')])
+ wantframework_option = BoolOption('wantframework', 'Test requires',
+ default=False,
+ requires=[('gc.name', 'framework')])
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('pypy', '', [gcgroup, booloption, objspaceoption,
- wantref_option, intoption])
+ wantref_option,
+ wantframework_option,
+ intoption])
return descr
def test_base_config():
@@ -46,12 +51,11 @@
py.test.raises(ValueError, 'config.int = "hello"')
py.test.raises(ValueError, 'config.gc.float = None')
- # test whether the gc.name is set to 'ref' when wantref is true (note that
- # the current value of gc.name is 'framework')
- config.wantref = True
+ config = Config(descr, bool=False)
assert config.gc.name == 'ref'
- py.test.raises(ValueError, 'config.gc.name = "framework"')
- config.gc.name = "ref"
+ config.wantframework = True
+ py.test.raises(ValueError, 'config.gc.name = "ref"')
+ config.gc.name = "framework"
def test_annotator_folding():
from pypy.translator.interactive import Translation
@@ -113,6 +117,9 @@
assert config.gc.name == 'framework'
+
+ config = Config(descr)
+ parser = to_optparse(config, ['gc.name'])
(options, args) = parser.parse_args(args=['-g ref'])
assert config.gc.name == 'ref'
@@ -211,11 +218,11 @@
config = Config(descr)
assert config.getpaths() == ['gc.name', 'gc.dummy', 'gc.float', 'bool',
- 'objspace', 'wantref', 'int']
+ 'objspace', 'wantref', 'wantframework', 'int']
assert config.gc.getpaths() == ['name', 'dummy', 'float']
assert config.getpaths(include_groups=True) == [
'gc', 'gc.name', 'gc.dummy', 'gc.float',
- 'bool', 'objspace', 'wantref', 'int']
+ 'bool', 'objspace', 'wantref', 'wantframework', 'int']
def test_none():
dummy1 = BoolOption('dummy1', 'doc dummy', default=False, cmdline=None)
@@ -258,3 +265,20 @@
config.s.backend = "cli"
assert config.s.type_system == "oo"
+def test_choice_with_no_default():
+ descr = OptionDescription("test", "", [
+ ChoiceOption("backend", "", ["c", "llvm"])])
+ config = Config(descr)
+ assert config.backend is None
+ config.backend = "c"
+
+def test_overrides_are_defaults():
+ descr = OptionDescription("test", "", [
+ BoolOption("b1", "", default=False, requires=[("b2", False)]),
+ BoolOption("b2", "", default=False),
+ ])
+ config = Config(descr, b2=True)
+ assert config.b2
+ config.b1 = True
+ assert not config.b2
+ print config._cfgimpl_value_owners
Modified: pypy/branch/even-more-config/pypy/config/test/test_pypyoption.py
==============================================================================
--- pypy/branch/even-more-config/pypy/config/test/test_pypyoption.py (original)
+++ pypy/branch/even-more-config/pypy/config/test/test_pypyoption.py Sun Oct 1 18:53:53 2006
@@ -14,8 +14,9 @@
conf.objspace.std.withsmallint = True
assert not conf.objspace.std.withprebuiltint
+ conf = Config(pypy_optiondescription)
conf.objspace.std.withprebuiltint = True
- assert not conf.objspace.std.withsmallint
+ py.test.raises(ValueError, "conf.objspace.std.withsmallint = True")
def test_objspace_incopatibilities():
conf = Config(pypy_optiondescription)
More information about the Pypy-commit
mailing list