everything in src for packaging purposes
This commit is contained in:
@ -1,13 +0,0 @@
|
||||
"""automatically sets the PYTHONPATH before running the unit tests
|
||||
|
||||
This is supposed to be used in development mode (i.e. testing from a fresh
|
||||
checkout)
|
||||
"""
|
||||
|
||||
from os.path import dirname, abspath, join, normpath
|
||||
import sys
|
||||
|
||||
HERE = dirname(abspath(__file__))
|
||||
PATH = normpath(join(HERE, '..'))
|
||||
if PATH not in sys.path:
|
||||
sys.path.insert(1, PATH)
|
@ -1,104 +0,0 @@
|
||||
#this test is much more to test that **it's there** and answers attribute access
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from config import *
|
||||
from option import *
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False)
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
def test_base_config():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
assert cfg.dummy == False
|
||||
dm = cfg.unwrap_from_path('dummy')
|
||||
assert dm._name == 'dummy'
|
||||
|
||||
def test_reset_value():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
assert cfg.gc.dummy == False
|
||||
cfg.gc.dummy = True
|
||||
assert cfg.gc.dummy == True
|
||||
cfg.gc.dummy = None
|
||||
|
||||
def test_base_config_and_groups():
|
||||
descr = make_description()
|
||||
# overrides the booloption default value
|
||||
config = Config(descr, bool=False)
|
||||
assert config.gc.name == 'ref'
|
||||
assert config.bool == False
|
||||
nm = config.unwrap_from_path('gc.name')
|
||||
assert nm._name == 'name'
|
||||
gc = config.unwrap_from_path('gc')
|
||||
assert gc._name == 'gc'
|
||||
nm = config.unwrap_from_name('name')
|
||||
assert nm._name == 'name'
|
||||
|
||||
def test_base_config_in_a_tree():
|
||||
"how options are organized into a tree"
|
||||
descr = make_description()
|
||||
config = Config(descr, bool=False)
|
||||
|
||||
assert config.gc.name == 'ref'
|
||||
config.gc.name = 'framework'
|
||||
assert config.gc.name == 'framework'
|
||||
assert getattr(config, "gc.name") == 'framework'
|
||||
|
||||
assert config.objspace == 'std'
|
||||
config.objspace = 'thunk'
|
||||
assert config.objspace == 'thunk'
|
||||
|
||||
assert config.gc.float == 2.3
|
||||
assert config.int == 0
|
||||
config.gc.float = 3.4
|
||||
config.int = 123
|
||||
assert config.gc.float == 3.4
|
||||
assert config.int == 123
|
||||
|
||||
assert not config.wantref
|
||||
|
||||
assert config.str == "abc"
|
||||
config.str = "def"
|
||||
assert config.str == "def"
|
||||
|
||||
raises(AttributeError, 'config.gc.foo = "bar"')
|
||||
|
||||
config = Config(descr, bool=False)
|
||||
assert config.gc.name == 'ref'
|
||||
config.wantframework = True
|
||||
|
||||
def test_config_values():
|
||||
"_cfgimpl_values appears to be a simple dict"
|
||||
descr = make_description()
|
||||
config = Config(descr, bool=False)
|
||||
config.set(dummy=False)
|
||||
assert config.gc._cfgimpl_values == {'dummy': False, 'float': 2.3, 'name': 'ref'}
|
||||
|
||||
def test_cfgimpl_get_home_by_path():
|
||||
descr = make_description()
|
||||
config = Config(descr, bool=False)
|
||||
assert config._cfgimpl_get_home_by_path('gc.dummy')[1] == 'dummy'
|
||||
assert config._cfgimpl_get_home_by_path('dummy')[1] == 'dummy'
|
||||
assert config.getpaths(include_groups=False) == ['gc.name', 'gc.dummy', 'gc.float', 'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||
assert config.getpaths(include_groups=True) == ['gc', 'gc.name', 'gc.dummy', 'gc.float', 'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
@ -1,167 +0,0 @@
|
||||
"configuration objects global API"
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from config import *
|
||||
from option import *
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Tests', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test', default=False)
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
def test_compare_configs():
|
||||
"config object comparison"
|
||||
descr = make_description()
|
||||
conf1 = Config(descr)
|
||||
conf2 = Config(descr, wantref=True)
|
||||
assert conf1 != conf2
|
||||
assert hash(conf1) != hash(conf2)
|
||||
assert conf1.getkey() != conf2.getkey()
|
||||
conf1.wantref = True
|
||||
assert conf1 == conf2
|
||||
assert hash(conf1) == hash(conf2)
|
||||
assert conf1.getkey() == conf2.getkey()
|
||||
# ____________________________________________________________
|
||||
|
||||
def test_iter_config():
|
||||
"iteration on config object"
|
||||
s = StrOption("string", "", default="string")
|
||||
s2 = StrOption("string2", "", default="string2")
|
||||
descr = OptionDescription("options", "", [s,s2])
|
||||
config = Config(descr)
|
||||
assert [(name, value) for name, value in config] == \
|
||||
[('string', 'string'), ('string2', 'string2')]
|
||||
|
||||
def test_iter_subconfig():
|
||||
"iteration on config sub object"
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
for (name, value), (gname, gvalue) in \
|
||||
zip(conf.gc, [("name", "ref"), ("dummy", False)]):
|
||||
assert name == gname
|
||||
assert value == gvalue
|
||||
#____________________________________________________________
|
||||
def test_getpaths():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
|
||||
assert config.getpaths() == ['gc.name', 'gc.dummy', 'gc.float', 'bool',
|
||||
'objspace', 'wantref', 'str', 'wantframework',
|
||||
'int', 'boolop']
|
||||
assert config.getpaths() == descr.getpaths()
|
||||
assert config.gc.getpaths() == ['name', 'dummy', 'float']
|
||||
assert config.gc.getpaths() == descr.gc.getpaths()
|
||||
assert config.getpaths(include_groups=True) == [
|
||||
'gc', 'gc.name', 'gc.dummy', 'gc.float',
|
||||
'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||
|
||||
assert config.getpaths(True) == descr.getpaths(True)
|
||||
|
||||
def test_getpaths_with_hidden():
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
booloption.hide()
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False)
|
||||
|
||||
descr = OptionDescription('tiramisu', '', [booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
|
||||
config = Config(descr)
|
||||
result = ['objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||
assert config.getpaths() == result
|
||||
r2 = ['bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||
assert config.getpaths(allpaths=True) == r2
|
||||
|
||||
def test_str():
|
||||
descr = make_description()
|
||||
c = Config(descr)
|
||||
print c # does not crash
|
||||
|
||||
def test_dir():
|
||||
descr = make_description()
|
||||
c = Config(descr)
|
||||
print dir(c)
|
||||
|
||||
def test_make_dict():
|
||||
"serialization of the whole config to a dict"
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
BoolOption("a", "", default=False)]),
|
||||
IntOption("int", "", default=42)])
|
||||
config = Config(descr)
|
||||
d = make_dict(config)
|
||||
assert d == {"s1.a": False, "int": 42}
|
||||
config.int = 43
|
||||
config.s1.a = True
|
||||
d = make_dict(config)
|
||||
assert d == {"s1.a": True, "int": 43}
|
||||
d2 = make_dict(config, flatten=True)
|
||||
assert d2 == {'a': True, 'int': 43}
|
||||
|
||||
def test_delattr():
|
||||
"delattr, means suppression of an option in a config"
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
BoolOption("a", "", default=False)]),
|
||||
IntOption("int", "", default=42)])
|
||||
c = Config(descr)
|
||||
c.int = 45
|
||||
assert c.int == 45
|
||||
del c.int
|
||||
assert c.int == 42
|
||||
c.int = 45
|
||||
assert c.int == 45
|
||||
|
||||
#def test_validator():
|
||||
# "validates the integrity of an option towards a whole configuration"
|
||||
# def my_validator_1(config):
|
||||
# assert config is c
|
||||
|
||||
# def my_validator_2(config):
|
||||
# assert config is c
|
||||
# raise ConflictConfigError
|
||||
|
||||
# descr = OptionDescription("opt", "", [
|
||||
# BoolOption('booloption1', 'option test1', default=False,
|
||||
# validator=my_validator_1),
|
||||
# BoolOption('booloption2', 'option test2', default=False,
|
||||
# validator=my_validator_2),
|
||||
# BoolOption('booloption4', 'option test4', default=False,
|
||||
# ),
|
||||
# ])
|
||||
# c = Config(descr)
|
||||
# c.booloption1 = True
|
||||
## raises(ConfigError, "c.booloption2 = True")
|
||||
## assert c.booloption2 is False
|
||||
## raises(ConfigError, "c.booloption3 = True")
|
||||
# assert c.booloption2 is False
|
||||
# c.booloption4 = True
|
||||
# assert c.booloption2 is False
|
||||
# c.booloption2 = False
|
||||
# assert c.booloption2 is False
|
||||
#
|
@ -1,258 +0,0 @@
|
||||
#just a proof of concept with a lot of options and option groups
|
||||
import autopath
|
||||
from config import *
|
||||
from option import *
|
||||
|
||||
all_modules = ['amon', 'sphynx', 'zephir']
|
||||
|
||||
example__optiondescription = OptionDescription("objspace", "Object Space Options", [
|
||||
ChoiceOption("name", "Object Space name",
|
||||
["std", "flow", "thunk", "dump", "taint"],
|
||||
"std"),
|
||||
|
||||
OptionDescription("opcodes", "opcodes to enable in the interpreter", [
|
||||
BoolOption("CALL_LIKELY_BUILTIN", "emit a special bytecode for likely calls to builtin functions",
|
||||
default=False,
|
||||
requires=[("translation.stackless", False)]),
|
||||
BoolOption("CALL_METHOD", "emit a special bytecode for expr.name()",
|
||||
default=False),
|
||||
]),
|
||||
|
||||
BoolOption("nofaking", "disallow faking in the object space",
|
||||
default=False,
|
||||
requires=[
|
||||
("objspace.usemodules.posix", True),
|
||||
("objspace.usemodules.time", True),
|
||||
("objspace.usemodules.errno", True)],
|
||||
),
|
||||
|
||||
OptionDescription("usemodules", "Which Modules should be used", [
|
||||
BoolOption(modname, "use module %s" % (modname, ),
|
||||
default=True,
|
||||
requires= ['amon'],
|
||||
)
|
||||
for modname in all_modules]),
|
||||
|
||||
BoolOption("allworkingmodules", "use as many working modules as possible",
|
||||
default=True,
|
||||
),
|
||||
|
||||
BoolOption("translationmodules",
|
||||
"use only those modules that are needed to run translate.py on pypy",
|
||||
default=False,
|
||||
),
|
||||
|
||||
BoolOption("geninterp", "specify whether geninterp should be used",
|
||||
default=True),
|
||||
|
||||
BoolOption("logbytecodes",
|
||||
"keep track of bytecode usage",
|
||||
default=False),
|
||||
|
||||
BoolOption("usepycfiles", "Write and read pyc files when importing",
|
||||
default=True),
|
||||
|
||||
BoolOption("lonepycfiles", "Import pyc files with no matching py file",
|
||||
default=False,
|
||||
requires=[("objspace.usepycfiles", True)]),
|
||||
|
||||
StrOption("soabi",
|
||||
"Tag to differentiate extension modules built for different Python interpreters",
|
||||
default=None),
|
||||
|
||||
BoolOption("honor__builtins__",
|
||||
"Honor the __builtins__ key of a module dictionary",
|
||||
default=False),
|
||||
|
||||
BoolOption("disable_call_speedhacks",
|
||||
"make sure that all calls go through space.call_args",
|
||||
default=False),
|
||||
|
||||
BoolOption("timing",
|
||||
"timing of various parts of the interpreter (simple profiling)",
|
||||
default=False),
|
||||
|
||||
OptionDescription("std", "Standard Object Space Options", [
|
||||
BoolOption("withtproxy", "support transparent proxies",
|
||||
default=True),
|
||||
|
||||
BoolOption("withsmallint", "use tagged integers",
|
||||
default=False,
|
||||
requires=[("objspace.std.withprebuiltint", False),
|
||||
("translation.taggedpointers", True)]),
|
||||
|
||||
BoolOption("withprebuiltint", "prebuild commonly used int objects",
|
||||
default=False),
|
||||
|
||||
IntOption("prebuiltintfrom", "lowest integer which is prebuilt",
|
||||
default=-5),
|
||||
|
||||
IntOption("prebuiltintto", "highest integer which is prebuilt",
|
||||
default=100),
|
||||
|
||||
BoolOption("withstrjoin", "use strings optimized for addition",
|
||||
default=False),
|
||||
|
||||
BoolOption("withstrslice", "use strings optimized for slicing",
|
||||
default=False),
|
||||
|
||||
BoolOption("withstrbuf", "use strings optimized for addition (ver 2)",
|
||||
default=False),
|
||||
|
||||
BoolOption("withprebuiltchar",
|
||||
"use prebuilt single-character string objects",
|
||||
default=False),
|
||||
|
||||
BoolOption("sharesmallstr",
|
||||
"always reuse the prebuilt string objects "
|
||||
"(the empty string and potentially single-char strings)",
|
||||
default=False),
|
||||
|
||||
BoolOption("withrope", "use ropes as the string implementation",
|
||||
default=False,
|
||||
requires=[("objspace.std.withstrslice", False),
|
||||
("objspace.std.withstrjoin", False),
|
||||
("objspace.std.withstrbuf", False)],
|
||||
),
|
||||
|
||||
BoolOption("withropeunicode", "use ropes for the unicode implementation",
|
||||
default=False,
|
||||
requires=[("objspace.std.withrope", True)]),
|
||||
|
||||
BoolOption("withcelldict",
|
||||
"use dictionaries that are optimized for being used as module dicts",
|
||||
default=False,
|
||||
requires=[("objspace.opcodes.CALL_LIKELY_BUILTIN", False),
|
||||
("objspace.honor__builtins__", False)]),
|
||||
|
||||
BoolOption("withdictmeasurement",
|
||||
"create huge files with masses of information "
|
||||
"about dictionaries",
|
||||
default=False),
|
||||
|
||||
BoolOption("withmapdict",
|
||||
"make instances really small but slow without the JIT",
|
||||
default=False,
|
||||
requires=[("objspace.std.getattributeshortcut", True),
|
||||
("objspace.std.withtypeversion", True),
|
||||
]),
|
||||
|
||||
BoolOption("withrangelist",
|
||||
"enable special range list implementation that does not "
|
||||
"actually create the full list until the resulting "
|
||||
"list is mutated",
|
||||
default=False),
|
||||
|
||||
BoolOption("withtypeversion",
|
||||
"version type objects when changing them",
|
||||
default=False,
|
||||
# weakrefs needed, because of get_subclasses()
|
||||
requires=[("translation.rweakref", True)]),
|
||||
|
||||
BoolOption("withmethodcache",
|
||||
"try to cache method lookups",
|
||||
default=False,
|
||||
requires=[("objspace.std.withtypeversion", True),
|
||||
("translation.rweakref", True)]),
|
||||
BoolOption("withmethodcachecounter",
|
||||
"try to cache methods and provide a counter in __pypy__. "
|
||||
"for testing purposes only.",
|
||||
default=False,
|
||||
requires=[("objspace.std.withmethodcache", True)]),
|
||||
IntOption("methodcachesizeexp",
|
||||
" 2 ** methodcachesizeexp is the size of the of the method cache ",
|
||||
default=11),
|
||||
BoolOption("optimized_int_add",
|
||||
"special case the addition of two integers in BINARY_ADD",
|
||||
default=False),
|
||||
BoolOption("optimized_comparison_op",
|
||||
"special case the comparison of integers",
|
||||
default=False),
|
||||
BoolOption("optimized_list_getitem",
|
||||
"special case the 'list[integer]' expressions",
|
||||
default=False),
|
||||
BoolOption("builtinshortcut",
|
||||
"a shortcut for operations between built-in types",
|
||||
default=False),
|
||||
BoolOption("getattributeshortcut",
|
||||
"track types that override __getattribute__",
|
||||
default=False),
|
||||
BoolOption("newshortcut",
|
||||
"cache and shortcut calling __new__ from builtin types",
|
||||
default=False),
|
||||
|
||||
BoolOption("logspaceoptypes",
|
||||
"a instrumentation option: before exit, print the types seen by "
|
||||
"certain simpler bytecodes",
|
||||
default=False),
|
||||
ChoiceOption("multimethods", "the multimethod implementation to use",
|
||||
["doubledispatch", "mrd"],
|
||||
default="mrd"),
|
||||
BoolOption("immutable_builtintypes",
|
||||
"Forbid the changing of builtin types", default=True),
|
||||
]),
|
||||
])
|
||||
|
||||
# ____________________________________________________________
|
||||
|
||||
def get_combined_translation_config(other_optdescr=None,
|
||||
existing_config=None,
|
||||
overrides=None,
|
||||
translating=False):
|
||||
if overrides is None:
|
||||
overrides = {}
|
||||
d = BoolOption("translating",
|
||||
"indicates whether we are translating currently",
|
||||
default=False)
|
||||
if other_optdescr is None:
|
||||
children = []
|
||||
newname = ""
|
||||
else:
|
||||
children = [other_optdescr]
|
||||
newname = other_optdescr._name
|
||||
descr = OptionDescription("eole", "all options", children)
|
||||
config = Config(descr, **overrides)
|
||||
if translating:
|
||||
config.translating = True
|
||||
if existing_config is not None:
|
||||
for child in existing_config._cfgimpl_descr._children:
|
||||
if child._name == newname:
|
||||
continue
|
||||
value = getattr(existing_config, child._name)
|
||||
config._cfgimpl_values[child._name] = value
|
||||
return config
|
||||
|
||||
def get_example_config(overrides=None, translating=False):
|
||||
return get_combined_translation_config(
|
||||
example__optiondescription, overrides=overrides,
|
||||
translating=translating)
|
||||
|
||||
# ____________________________________________________________
|
||||
|
||||
def test_example_option():
|
||||
config = get_example_config()
|
||||
result = ['objspace.name', 'objspace.opcodes.CALL_LIKELY_BUILTIN',
|
||||
'objspace.opcodes.CALL_METHOD', 'objspace.nofaking',
|
||||
'objspace.usemodules.amon', 'objspace.usemodules.sphynx',
|
||||
'objspace.usemodules.zephir', 'objspace.allworkingmodules',
|
||||
'objspace.translationmodules', 'objspace.geninterp',
|
||||
'objspace.logbytecodes', 'objspace.usepycfiles', 'objspace.lonepycfiles',
|
||||
'objspace.soabi', 'objspace.honor__builtins__',
|
||||
'objspace.disable_call_speedhacks', 'objspace.timing',
|
||||
'objspace.std.withtproxy', 'objspace.std.withsmallint',
|
||||
'objspace.std.withprebuiltint', 'objspace.std.prebuiltintfrom',
|
||||
'objspace.std.prebuiltintto', 'objspace.std.withstrjoin',
|
||||
'objspace.std.withstrslice', 'objspace.std.withstrbuf',
|
||||
'objspace.std.withprebuiltchar', 'objspace.std.sharesmallstr',
|
||||
'objspace.std.withrope', 'objspace.std.withropeunicode',
|
||||
'objspace.std.withcelldict', 'objspace.std.withdictmeasurement',
|
||||
'objspace.std.withmapdict', 'objspace.std.withrangelist',
|
||||
'objspace.std.withtypeversion', 'objspace.std.withmethodcache',
|
||||
'objspace.std.withmethodcachecounter', 'objspace.std.methodcachesizeexp',
|
||||
'objspace.std.optimized_int_add', 'objspace.std.optimized_comparison_op',
|
||||
'objspace.std.optimized_list_getitem', 'objspace.std.builtinshortcut',
|
||||
'objspace.std.getattributeshortcut', 'objspace.std.newshortcut',
|
||||
'objspace.std.logspaceoptypes', 'objspace.std.multimethods',
|
||||
'objspace.std.immutable_builtintypes']
|
||||
|
||||
assert config.getpaths(allpaths=True) == result
|
@ -1,207 +0,0 @@
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from config import *
|
||||
from option import *
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=['boolop'])
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
def make_description_duplicates():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
## dummy 1
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=['boolop'])
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
# dummy2 (same name)
|
||||
gcdummy2 = BoolOption('dummy', 'dummy2', default=True)
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, gcdummy2, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
def test_identical_names():
|
||||
"""If in the schema (the option description) there is something that
|
||||
have the same name, an exection is raised
|
||||
"""
|
||||
descr = make_description_duplicates()
|
||||
raises(ConflictConfigError, "cfg = Config(descr)")
|
||||
|
||||
def make_description2():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
# first multi
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
boolop.enable_multi()
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=['boolop'])
|
||||
# second multi
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
wantframework_option.enable_multi()
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
# FIXME: XXX would you mind putting the multi validations anywhere else
|
||||
# than in the requires !!!
|
||||
#def test_multi_constraints():
|
||||
# "a multi in a constraint has to have the same length"
|
||||
# descr = make_description2()
|
||||
# cfg = Config(descr)
|
||||
# cfg.boolop = [True, True, False]
|
||||
# cfg.wantframework = [False, False, True]
|
||||
#
|
||||
#def test_multi_raise():
|
||||
# "a multi in a constraint has to have the same length"
|
||||
# # FIXME fusionner les deux tests, MAIS PROBLEME :
|
||||
# # il ne devrait pas etre necessaire de refaire une config
|
||||
# # si la valeur est modifiee une deuxieme fois ->
|
||||
# #raises(ConflictConfigError, "cfg.wantframework = [False, False, True]")
|
||||
# # ExceptionFailure: 'DID NOT RAISE'
|
||||
# descr = make_description2()
|
||||
# cfg = Config(descr)
|
||||
# cfg.boolop = [True]
|
||||
# raises(ConflictConfigError, "cfg.wantframework = [False, False, True]")
|
||||
# ____________________________________________________________
|
||||
# adding dynamically new options description schema
|
||||
def test_newoption_add_in_descr():
|
||||
descr = make_description()
|
||||
newoption = BoolOption('newoption', 'dummy twoo', default=False)
|
||||
descr.add_child(newoption)
|
||||
config = Config(descr)
|
||||
assert config.newoption == False
|
||||
|
||||
def test_newoption_add_in_subdescr():
|
||||
descr = make_description()
|
||||
newoption = BoolOption('newoption', 'dummy twoo', default=False)
|
||||
descr.gc.add_child(newoption)
|
||||
config = Config(descr, bool=False)
|
||||
assert config.gc.newoption == False
|
||||
|
||||
def test_newoption_add_in_config():
|
||||
descr = make_description()
|
||||
config = Config(descr, bool=False)
|
||||
newoption = BoolOption('newoption', 'dummy twoo', default=False)
|
||||
descr.add_child(newoption)
|
||||
config.cfgimpl_update()
|
||||
assert config.newoption == False
|
||||
# ____________________________________________________________
|
||||
def make_description_requires():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
requires=[('int', 1, 'hide')])
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
stroption, intoption])
|
||||
return descr
|
||||
|
||||
def test_hidden_if_in():
|
||||
descr = make_description_requires()
|
||||
cfg = Config(descr)
|
||||
intoption = cfg.unwrap_from_path('int')
|
||||
stroption = cfg.unwrap_from_path('str')
|
||||
assert not stroption._is_hidden()
|
||||
cfg.int = 1
|
||||
raises(HiddenOptionError, "cfg.str")
|
||||
raises(HiddenOptionError, 'cfg.str= "uvw"')
|
||||
assert stroption._is_hidden()
|
||||
|
||||
def test_hidden_if_in_with_group():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||
requires=[('int', 1, 'hide')])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg = Config(descr)
|
||||
assert not gcgroup._is_hidden()
|
||||
cfg.int = 1
|
||||
raises(HiddenOptionError, "cfg.gc.name")
|
||||
# raises(HiddenOptionError, 'cfg.gc= "uvw"')
|
||||
assert gcgroup._is_hidden()
|
||||
|
||||
def test_disabled_with_group():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||
requires=[('int', 1, 'disable')])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg = Config(descr)
|
||||
assert not gcgroup._is_disabled()
|
||||
cfg.int = 1
|
||||
raises(DisabledOptionError, "cfg.gc.name")
|
||||
# raises(HiddenOptionError, 'cfg.gc= "uvw"')
|
||||
assert gcgroup._is_disabled()
|
||||
|
||||
|
@ -1,121 +0,0 @@
|
||||
"test all types of option default values for options, add new option in a descr"
|
||||
import autopath
|
||||
|
||||
from py.test import raises
|
||||
from config import *
|
||||
from option import *
|
||||
from error import MandatoryError
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=['boolop'])
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
#____________________________________________________________
|
||||
# default values
|
||||
def test_default_is_none():
|
||||
"""
|
||||
Most constructors take a ``default`` argument that specifies the default
|
||||
value of the option. If this argument is not supplied the default value is
|
||||
assumed to be ``None``.
|
||||
"""
|
||||
dummy1 = BoolOption('dummy1', 'doc dummy')
|
||||
dummy2 = BoolOption('dummy2', 'doc dummy')
|
||||
group = OptionDescription('group', '', [dummy1, dummy2])
|
||||
config = Config(group)
|
||||
# so when the default value is not set, there is actually a default value
|
||||
assert config.dummy1 == None
|
||||
assert config.dummy2 == None
|
||||
|
||||
def test_set_defaut_value_from_option_object():
|
||||
"""Options have an available default setting and can give it back"""
|
||||
b = BoolOption("boolean", "", default=False)
|
||||
assert b.getdefault() == False
|
||||
|
||||
def test_mandatory():
|
||||
dummy1 = BoolOption('dummy1', 'doc dummy', mandatory=True)
|
||||
dummy2 = BoolOption('dummy2', 'doc dummy', mandatory=True)
|
||||
group = OptionDescription('group', '', [dummy1, dummy2])
|
||||
config = Config(group)
|
||||
# config.setoption('dummy1', True)
|
||||
raises(MandatoryError, 'config.dummy1')
|
||||
config.dummy1 = True
|
||||
assert config.dummy1 == True
|
||||
raises(MandatoryError, 'config.dummy2 == None')
|
||||
raises(MandatoryError, "config.override({'dummy2':None})")
|
||||
config.set(dummy2=True)
|
||||
config.dummy2 = False
|
||||
assert config.dummy2 == False
|
||||
|
||||
def test_override_are_defaults():
|
||||
descr = make_description()
|
||||
config = Config(descr, bool=False)
|
||||
|
||||
config.gc.dummy = True
|
||||
assert config._cfgimpl_values['gc']._cfgimpl_value_owners['dummy'] == 'user'
|
||||
#Options have an available default setting and can give it back
|
||||
assert config._cfgimpl_descr._children[0]._children[1].getdefault() == False
|
||||
config.override({'gc.dummy':True})
|
||||
#assert config.gc.dummy == True
|
||||
#assert config._cfgimpl_descr._children[0]._children[1].getdefault() == True
|
||||
#assert config._cfgimpl_values['gc']._cfgimpl_value_owners['dummy'] == 'default'
|
||||
|
||||
def test_overrides_changes_option_value():
|
||||
"with config.override(), the default is changed and the value is changed"
|
||||
descr = OptionDescription("test", "", [
|
||||
BoolOption("b", "", default=False)])
|
||||
config = Config(descr)
|
||||
config.b = True
|
||||
config.override({'b': False})
|
||||
assert config.b == False
|
||||
#____________________________________________________________
|
||||
# test various option types
|
||||
def test_choice_with_no_default():
|
||||
descr = OptionDescription("test", "", [
|
||||
ChoiceOption("backend", "", ["c", "cli"])])
|
||||
config = Config(descr)
|
||||
assert config.backend is None
|
||||
config.backend = "c"
|
||||
|
||||
def test_choice_with_default():
|
||||
descr = OptionDescription("test", "", [
|
||||
ChoiceOption("backend", "", ["c", "cli"], default="cli")])
|
||||
config = Config(descr)
|
||||
assert config.backend == "cli"
|
||||
|
||||
def test_arbitrary_option():
|
||||
descr = OptionDescription("top", "", [
|
||||
ArbitraryOption("a", "no help", default=None)
|
||||
])
|
||||
config = Config(descr)
|
||||
config.a = []
|
||||
config.a.append(1)
|
||||
assert config.a == [1]
|
||||
|
||||
descr = OptionDescription("top", "", [
|
||||
ArbitraryOption("a", "no help", defaultfactory=list)
|
||||
])
|
||||
c1 = Config(descr)
|
||||
c2 = Config(descr)
|
||||
c1.a.append(1)
|
||||
assert c2.a == []
|
||||
assert c1.a == [1]
|
||||
|
@ -1,131 +0,0 @@
|
||||
import autopath
|
||||
|
||||
from py.test import raises
|
||||
from config import *
|
||||
from option import *
|
||||
from error import SpecialOwnersError
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', callback="toto")
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=['boolop'])
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
def make_description2():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=['boolop'])
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
def test_override_are_default_owner():
|
||||
"config.override() implies that the owner is 'default' again"
|
||||
descr = make_description2()
|
||||
config = Config(descr, bool=False)
|
||||
# default
|
||||
assert config.gc._cfgimpl_value_owners['dummy'] == 'default'
|
||||
# user
|
||||
config.gc.dummy = True
|
||||
assert config.gc._cfgimpl_value_owners['dummy'] == 'user'
|
||||
assert config._cfgimpl_values['gc']._cfgimpl_value_owners['dummy'] == 'user'
|
||||
#Options have an available default setting and can give it back
|
||||
assert config._cfgimpl_descr._children[0]._children[1].getdefault() == False
|
||||
config.override({'gc.dummy':True})
|
||||
assert config.gc._cfgimpl_value_owners['dummy'] == 'default'
|
||||
# user again
|
||||
config.gc.dummy = False
|
||||
assert config.gc._cfgimpl_value_owners['dummy'] == 'user'
|
||||
|
||||
def test_change_owner():
|
||||
descr = make_description()
|
||||
# here the owner is 'default'
|
||||
config = Config(descr, bool=False)
|
||||
# the default owner is 'user' (which is not 'default')
|
||||
# Still not getting it ? read the docs
|
||||
config.gc.dummy = True
|
||||
assert config.gc._cfgimpl_value_owners['dummy'] == 'user'
|
||||
# config.cfgimpl_set_owner('eggs')
|
||||
# config.set(dummy=False)
|
||||
# assert config.gc._cfgimpl_value_owners['dummy'] == 'eggs'
|
||||
# config.cfgimpl_set_owner('spam')
|
||||
# gcdummy = config.unwrap_from_path('gc.dummy')
|
||||
# gcdummy.setowner(config.gc, 'blabla')
|
||||
# assert config.gc._cfgimpl_value_owners['dummy'] == 'blabla'
|
||||
# config.gc.dummy = True
|
||||
# assert config.gc._cfgimpl_value_owners['dummy'] == 'spam'
|
||||
|
||||
#____________________________________________________________
|
||||
# special owners
|
||||
def test_auto_owner():
|
||||
descr = make_description()
|
||||
config = Config(descr, bool=False)
|
||||
config.gc.setoption('dummy', True, 'auto')
|
||||
raises(HiddenOptionError, "config.gc.dummy")
|
||||
raises(ConflictConfigError, "config.gc.setoption('dummy', False, 'auto')")
|
||||
# shall return an auto value...
|
||||
#assert config.gc.dummy == 'auto_dummy_value'
|
||||
|
||||
def test_cannot_override_special_owners():
|
||||
descr = make_description()
|
||||
config = Config(descr, bool=False)
|
||||
config.gc.setoption('dummy', True, 'auto')
|
||||
raises(SpecialOwnersError, "config.override({'gc.dummy': True})")
|
||||
|
||||
# FIXME have to test the fills anyway
|
||||
#def test_fill_owner():
|
||||
# "fill option"
|
||||
# descr = make_description()
|
||||
# config = Config(descr, bool=False)
|
||||
# assert config.bool == False
|
||||
# assert config.gc.dummy == False
|
||||
# # 'fill' special values
|
||||
# config.gc.setoption('dummy', True, 'fill')
|
||||
# assert config.gc.dummy == False
|
||||
|
||||
#def test_auto_fill_and_override():
|
||||
# descr = make_description()
|
||||
# config = Config(descr, bool=False)
|
||||
# booloption = config.unwrap_from_path('bool')
|
||||
# booloption.callback = 'identical'
|
||||
# booloption.setowner(config, 'auto')
|
||||
# assert config.bool == 'identicalbool'
|
||||
# gcdummy = config.unwrap_from_path('gc.dummy')
|
||||
# gcdummy.callback = 'identical'
|
||||
# gcdummy.setowner(config.gc, 'fill')
|
||||
# raises(SpecialOwnersError, "config.override({'gc.dummy':True})")
|
||||
# config.gc.setoption('dummy', False, 'fill')
|
||||
# # value is returned
|
||||
# assert config.gc.dummy == False
|
||||
|
||||
|
@ -1,420 +0,0 @@
|
||||
"config.set() or config.setoption() or option.setoption()"
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from config import *
|
||||
from option import *
|
||||
from error import *
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False)
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
#____________________________________________________________
|
||||
# change with __setattr__
|
||||
def test_attribute_access():
|
||||
"Once set, option values can't be changed again by attribute access"
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
# let's try to change it again
|
||||
config.string = "foo"
|
||||
assert config.string == "foo"
|
||||
|
||||
def test_setitem():
|
||||
s = StrOption("string", "", default=["string", "sdfsdf"], default_multi="prout", multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
print config.string[1]
|
||||
config.string[1] = "titi"
|
||||
print config.string[1]
|
||||
|
||||
def test_reset():
|
||||
"if value is None, resets to default owner"
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config.string = "foo"
|
||||
assert config.string == "foo"
|
||||
assert config._cfgimpl_value_owners['string'] == 'user'
|
||||
config.string = None
|
||||
assert config.string == 'string'
|
||||
assert config._cfgimpl_value_owners['string'] == 'default'
|
||||
|
||||
def test_reset_with_multi():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string" , multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config.string = []
|
||||
assert config.string == ["string"]
|
||||
assert config._cfgimpl_value_owners['string'] == ['default']
|
||||
config.string = ["eggs", "spam", "foo"]
|
||||
assert config._cfgimpl_value_owners['string'] == ['user', 'user', 'user']
|
||||
config.string = []
|
||||
assert config.string == ["string"]
|
||||
assert config._cfgimpl_value_owners['string'] == ['default']
|
||||
raises(ConfigError, "config.string = None")
|
||||
|
||||
def test_default_with_multi():
|
||||
"default with multi is a list"
|
||||
s = StrOption("string", "", default=[], default_multi="string" , multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert config.string == []
|
||||
s = StrOption("string", "", default=None, default_multi="string" , multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert config.string == []
|
||||
|
||||
def test_idontexist():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
raises(AttributeError, "cfg.idontexist")
|
||||
# ____________________________________________________________
|
||||
def test_attribute_access_with_multi():
|
||||
s = StrOption("string", "", default=["string"], default_multi= "string" , multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config.string = ["foo", "bar"]
|
||||
assert config.string == ["foo", "bar"]
|
||||
|
||||
def test_item_access_with_multi():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config.string = ["foo", "bar"]
|
||||
assert config.string == ["foo", "bar"]
|
||||
assert config.string[0] == "foo"
|
||||
# FIXME
|
||||
config.string[0] = 'changetest'
|
||||
# assert config.string[0] == 'changetest'
|
||||
# assert config.string[
|
||||
|
||||
def test_access_with_multi_default():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert config._cfgimpl_value_owners["string"] == ['default']
|
||||
config.string = ["foo", "bar"]
|
||||
assert config.string == ["foo", "bar"]
|
||||
assert config._cfgimpl_value_owners["string"] == ['user', 'user']
|
||||
|
||||
#def test_attribute_access_with_multi2():
|
||||
# s = StrOption("string", "", default="string", multi=True)
|
||||
# descr = OptionDescription("options", "", [s])
|
||||
# config = Config(descr)
|
||||
# config.string = ["foo", "bar"]
|
||||
# assert config.string == ["foo", "bar"]
|
||||
|
||||
def test_multi_with_requires():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi = "abc",
|
||||
requires=[('int', 1, 'hide')], multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
config = Config(descr)
|
||||
assert stroption._is_hidden() == False
|
||||
config.int = 1
|
||||
raises(HiddenOptionError, "config.str = ['a', 'b']")
|
||||
assert stroption._is_hidden()
|
||||
|
||||
def test__requires_with_inverted():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi = "abc",
|
||||
requires=[('int', 1, 'hide', 'inverted')], multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
config = Config(descr)
|
||||
assert stroption._is_hidden() == False
|
||||
config.int = 1
|
||||
assert stroption._is_hidden() == False
|
||||
|
||||
def test_multi_with_requires_in_another_group():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
descr = OptionDescription("options", "", [intoption])
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[('int', 1, 'hide')], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
assert stroption._is_hidden() == False
|
||||
config.int = 1
|
||||
raises(HiddenOptionError, "config.opt.str = ['a', 'b']")
|
||||
assert stroption._is_hidden()
|
||||
|
||||
def test_apply_requires_from_config():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
descr = OptionDescription("options", "", [intoption])
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[('int', 1, 'hide')], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
assert stroption._is_hidden() == False
|
||||
config.int = 1
|
||||
try:
|
||||
config.opt.str
|
||||
except:
|
||||
pass
|
||||
assert stroption._is_hidden()
|
||||
|
||||
|
||||
def test_apply_requires_with_disabled():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
descr = OptionDescription("options", "", [intoption])
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[('int', 1, 'disable')], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
assert stroption._is_disabled() == False
|
||||
config.int = 1
|
||||
try:
|
||||
config.opt.str
|
||||
except:
|
||||
pass
|
||||
assert stroption._is_disabled()
|
||||
|
||||
def test_multi_with_requires_with_disabled_in_another_group():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
descr = OptionDescription("options", "", [intoption])
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[('int', 1, 'disable')], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
assert stroption._is_disabled() == False
|
||||
config.int = 1
|
||||
raises(DisabledOptionError, "config.opt.str = ['a', 'b']")
|
||||
assert stroption._is_disabled()
|
||||
|
||||
def test_multi_with_requires_that_is_multi():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[('int', [1, 1], 'hide')], multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
config = Config(descr)
|
||||
assert stroption._is_hidden() == False
|
||||
config.int = [1, 1]
|
||||
raises(HiddenOptionError, "config.str = ['a', 'b']")
|
||||
assert stroption._is_hidden()
|
||||
|
||||
def test_multi_with_bool():
|
||||
s = BoolOption("bool", "", default=[False], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert descr.bool.multi == True
|
||||
config.bool = [True, False]
|
||||
assert config._cfgimpl_values['bool'] == [True, False]
|
||||
assert config.bool == [True, False]
|
||||
|
||||
def test_multi_with_bool_two():
|
||||
s = BoolOption("bool", "", default=[False], multi=True)
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
assert descr.bool.multi == True
|
||||
raises(ConfigError, "config.bool = True")
|
||||
|
||||
def test_choice_access_with_multi():
|
||||
ch = ChoiceOption("t1", "", ["a", "b"], default=["a"], multi=True)
|
||||
descr = OptionDescription("options", "", [ch])
|
||||
config = Config(descr)
|
||||
config.t1 = ["a", "b", "a", "b"]
|
||||
assert config.t1 == ["a", "b", "a", "b"]
|
||||
# ____________________________________________________________
|
||||
|
||||
def test_setoption_from_option():
|
||||
"a setoption directly from the option is **not** a good practice"
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
descr = OptionDescription('descr', '', [booloption])
|
||||
cfg = Config(descr)
|
||||
booloption.setoption(cfg, False, 'owner')
|
||||
assert cfg.bool == False
|
||||
# ____________________________________________________________
|
||||
def test_set_mode_in_config():
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True,
|
||||
mode='expert')
|
||||
descr = OptionDescription('descr', '', [booloption])
|
||||
cfg = Config(descr)
|
||||
cfg.cfgimpl_set_mode('expert')
|
||||
raises(ModeOptionError, "cfg.bool")
|
||||
cfg.cfgimpl_set_mode('normal')
|
||||
assert cfg.bool == True
|
||||
#____________________________________________________________
|
||||
def test_dwim_set():
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("sub", "", [
|
||||
BoolOption("b1", ""),
|
||||
ChoiceOption("c1", "", ['a', 'b', 'c'], 'a'),
|
||||
BoolOption("d1", ""),
|
||||
]),
|
||||
BoolOption("b2", ""),
|
||||
BoolOption("d1", ""),
|
||||
])
|
||||
c = Config(descr)
|
||||
c.set(b1=False, c1='b')
|
||||
assert not c.sub.b1
|
||||
assert c.sub.c1 == 'b'
|
||||
# new config, because you cannot change values once they are set
|
||||
c = Config(descr)
|
||||
c.set(b2=False, **{'sub.c1': 'c'})
|
||||
assert not c.b2
|
||||
assert c.sub.c1 == 'c'
|
||||
raises(AmbigousOptionError, "c.set(d1=True)")
|
||||
raises(NoMatchingOptionFound, "c.set(unknown='foo')")
|
||||
|
||||
def test_more_set():
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
BoolOption("a", "", default=False)]),
|
||||
IntOption("int", "", default=42)])
|
||||
d = {'s1.a': True, 'int': 23}
|
||||
config = Config(descr)
|
||||
config.set(**d)
|
||||
assert config.s1.a
|
||||
assert config.int == 23
|
||||
|
||||
def test_set_with_hidden_option():
|
||||
boolopt = BoolOption("a", "", default=False)
|
||||
boolopt.hide()
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [boolopt]),
|
||||
IntOption("int", "", default=42)])
|
||||
d = {'s1.a': True, 'int': 23}
|
||||
config = Config(descr)
|
||||
raises(HiddenOptionError, "config.set(**d)")
|
||||
|
||||
def test_set_with_unknown_option():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [boolopt]),
|
||||
IntOption("int", "", default=42)])
|
||||
d = {'s1.a': True, 'int': 23}
|
||||
config = Config(descr)
|
||||
raises(NoMatchingOptionFound, "config.set(**d)")
|
||||
|
||||
|
||||
def test_set_symlink_option():
|
||||
boolopt = BoolOption("b", "", default=False)
|
||||
linkopt = SymLinkOption("c", "s1.b")
|
||||
descr = OptionDescription("opt", "",
|
||||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
config = Config(descr)
|
||||
setattr(config, "s1.b", True)
|
||||
setattr(config, "s1.b", False)
|
||||
assert config.s1.b == False
|
||||
assert config.c == False
|
||||
config.c = True
|
||||
assert config.s1.b == True
|
||||
assert config.c == True
|
||||
config.c = False
|
||||
assert config.s1.b == False
|
||||
assert config.c == False
|
||||
|
||||
#____________________________________________________________
|
||||
def test_config_impl_values():
|
||||
descr = make_description()
|
||||
config = Config(descr, bool=False)
|
||||
# gcdummy.setoption(config, True, "user")
|
||||
# config.setoption("gc.dummy", True, "user")
|
||||
#config.gc.dummy = True
|
||||
# config.setoption("bool", False, "user")
|
||||
config.set(dummy=False)
|
||||
assert config.gc._cfgimpl_values == {'dummy': False, 'float': 2.3, 'name': 'ref'}
|
||||
## acces to the option object
|
||||
# config.gc._cfgimpl_descr.dummy.setoption(config, True, "user")
|
||||
assert config.gc.dummy == False
|
||||
# config.set(dummy=True)
|
||||
# assert config.gc.dummy == True
|
||||
|
||||
#____________________________________________________________
|
||||
def test_accepts_multiple_changes_from_option():
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
config.string = "egg"
|
||||
assert s.getdefault() == "string"
|
||||
assert config.string == "egg"
|
||||
s.setoption(config, 'blah', "default")
|
||||
assert s.getdefault() == "blah"
|
||||
assert config.string == "blah"
|
||||
s.setoption(config, 'bol', "user")
|
||||
assert config.string == 'bol'
|
||||
config.override({'string': "blurp"})
|
||||
assert config.string == 'blurp'
|
||||
assert s.getdefault() == 'blurp'
|
||||
|
||||
def test_allow_multiple_changes_from_config():
|
||||
"""
|
||||
a `setoption` from the config object is much like the attribute access,
|
||||
except the fact that value owner can bet set
|
||||
"""
|
||||
s = StrOption("string", "", default="string")
|
||||
s2 = StrOption("string2", "", default="string")
|
||||
suboption = OptionDescription("bip", "", [s2])
|
||||
descr = OptionDescription("options", "", [s, suboption])
|
||||
config = Config(descr)
|
||||
config.setoption("string", 'blah', "user")
|
||||
config.setoption("string", "oh", "user")
|
||||
assert config.string == "oh"
|
||||
config.set(string2= 'blah')
|
||||
assert config.bip.string2 == 'blah'
|
||||
# ____________________________________________________________
|
||||
|
||||
def test_overrides_are_defaults():
|
||||
descr = OptionDescription("test", "", [
|
||||
BoolOption("b1", "", default=False),
|
||||
BoolOption("b2", "", default=False),
|
||||
])
|
||||
# overrides here
|
||||
config = Config(descr, b2=True)
|
||||
assert config.b2
|
||||
# test with a require
|
||||
config.b1 = True
|
||||
assert config.b2
|
||||
|
||||
# ____________________________________________________________
|
||||
# accessing a value by the get method
|
||||
def test_access_by_get():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
raises(NotFoundError, "cfg.get('idontexist')" )
|
||||
assert cfg.get('wantref') == False
|
||||
assert cfg.gc.dummy == False
|
||||
assert cfg.get('dummy') == False
|
||||
|
||||
def test_access_by_get_whith_hide():
|
||||
b1 = BoolOption("b1", "")
|
||||
b1.hide()
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("sub", "", [
|
||||
b1,
|
||||
ChoiceOption("c1", "", ['a', 'b', 'c'], 'a'),
|
||||
BoolOption("d1", ""),
|
||||
]),
|
||||
BoolOption("b2", ""),
|
||||
BoolOption("d1", ""),
|
||||
])
|
||||
c = Config(descr)
|
||||
raises(HiddenOptionError, "c.get('b1')")
|
||||
|
@ -1,141 +0,0 @@
|
||||
# coding: utf-8
|
||||
"frozen and hidden values"
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from config import *
|
||||
from option import *
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcoption.set_mode("expert")
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
# hidding dummy here
|
||||
gcdummy.hide()
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=[('gc.name', 'ref')])
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=[('gc.name', 'framework')])
|
||||
|
||||
# ____________________________________________________________
|
||||
booloptiontwo = BoolOption('booltwo', 'Test boolean option two', default=False)
|
||||
subgroup = OptionDescription('subgroup', '', [booloptiontwo])
|
||||
# ____________________________________________________________
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [subgroup, gcoption, gcdummy, floatoption])
|
||||
gcgroup.set_mode("expert")
|
||||
descr = OptionDescription('trs', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption])
|
||||
return descr
|
||||
#____________________________________________________________
|
||||
#freeze
|
||||
def make_description_freeze():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=['boolop'])
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=['boolop'])
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
def test_freeze_one_option():
|
||||
"freeze an option "
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
#freeze only one option
|
||||
conf.gc._cfgimpl_descr.dummy.freeze()
|
||||
assert conf.gc.dummy == False
|
||||
raises(TypeError, "conf.gc.dummy = True")
|
||||
|
||||
def test_frozen_value():
|
||||
"setattr a frozen value at the config level"
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
config = Config(descr)
|
||||
s.freeze()
|
||||
raises(ConfigError, 'config.string = "egg"')
|
||||
|
||||
def test_freeze():
|
||||
"freeze a whole configuration object"
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
conf.cfgimpl_freeze()
|
||||
raises(ConfigError, "conf.gc.name = 'try to modify'")
|
||||
# ____________________________________________________________
|
||||
def test_is_hidden():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
assert config.gc._cfgimpl_descr.dummy._is_hidden() == True
|
||||
# setattr
|
||||
raises(HiddenOptionError, "config.gc.dummy == False")
|
||||
# getattr
|
||||
raises(HiddenOptionError, "config.gc.dummy")
|
||||
# I want to access to this option anyway
|
||||
path = 'gc.dummy'
|
||||
homeconfig, name = config._cfgimpl_get_home_by_path(path)
|
||||
assert homeconfig._cfgimpl_values[name] == False
|
||||
|
||||
def test_group_is_hidden():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
gc = config.unwrap_from_path('gc')
|
||||
gc.hide()
|
||||
dummy = config.unwrap_from_path('gc.dummy')
|
||||
raises(HiddenOptionError, "config.gc.dummy")
|
||||
assert gc._is_hidden()
|
||||
raises(HiddenOptionError, "config.gc.float")
|
||||
# manually set the subconfigs to "show"
|
||||
gc.show()
|
||||
assert gc._is_hidden() == False
|
||||
assert config.gc.float == 2.3
|
||||
#dummy est en hide
|
||||
raises(HiddenOptionError, "config.gc.dummy == False")
|
||||
|
||||
def test_global_show():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
assert config.gc._cfgimpl_descr.dummy._is_hidden() == True
|
||||
raises(HiddenOptionError, "config.gc.dummy == False")
|
||||
|
||||
def test_with_many_subgroups():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
assert config.gc.subgroup._cfgimpl_descr.booltwo._is_hidden() == False
|
||||
assert config.gc.subgroup.booltwo == False
|
||||
config.gc.subgroup._cfgimpl_descr.booltwo.hide()
|
||||
path = 'gc.subgroup.booltwo'
|
||||
homeconfig, name = config._cfgimpl_get_home_by_path(path)
|
||||
assert name == "booltwo"
|
||||
option = getattr(homeconfig._cfgimpl_descr, name)
|
||||
assert option._is_hidden()
|
||||
|
||||
def test_option_mode():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
assert config.gc._cfgimpl_descr.name.get_mode() == 'expert'
|
||||
assert config._cfgimpl_descr.gc.get_mode() == 'expert'
|
||||
|
@ -1,47 +0,0 @@
|
||||
#this test is much more to test that **it's there** and answers attribute access
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from config import *
|
||||
from option import *
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
gcdummy2 = BoolOption('hide', 'dummy', default=True)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
['std', 'thunk'], 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False)
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption, gcdummy2])
|
||||
descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
def test_base_config_and_groups():
|
||||
descr = make_description()
|
||||
# overrides the booloption default value
|
||||
config = Config(descr, bool=False)
|
||||
assert config.gc.hide == True
|
||||
|
||||
def test_root_config_answers_ok():
|
||||
"if you hide the root config, the options in this namespace behave normally"
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy, boolop])
|
||||
cfg = Config(descr)
|
||||
cfg.cfgimpl_hide()
|
||||
assert cfg.dummy == False
|
||||
assert cfg.boolop == True
|
||||
|
||||
|
||||
|
@ -1,70 +0,0 @@
|
||||
# coding: utf-8
|
||||
import autopath
|
||||
from config import *
|
||||
from option import *
|
||||
|
||||
def make_description():
|
||||
numero_etab = StrOption('numero_etab', "identifiant de l'établissement")
|
||||
nom_machine = StrOption('nom_machine', "nom de la machine", default="eoleng")
|
||||
nombre_interfaces = IntOption('nombre_interfaces', "nombre d'interfaces à activer",
|
||||
default=1)
|
||||
activer_proxy_client = BoolOption('activer_proxy_client', "utiliser un proxy",
|
||||
default=False)
|
||||
mode_conteneur_actif = BoolOption('mode_conteneur_actif', "le serveur est en mode conteneur",
|
||||
default=False)
|
||||
# hidden (variable cachée)
|
||||
# mode_conteneur_actif.taint()
|
||||
adresse_serveur_ntp = StrOption('serveur_ntp', "adresse serveur ntp", multi=True)
|
||||
time_zone = ChoiceOption('time_zone', 'fuseau horaire du serveur',
|
||||
['Paris', 'Londres'], 'Paris')
|
||||
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé")
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau")
|
||||
|
||||
master = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
interface1 = OptionDescription('interface1', '', [master])
|
||||
interface1.set_group_type('group')
|
||||
|
||||
general = OptionDescription('general', '', [numero_etab, nom_machine,
|
||||
nombre_interfaces, activer_proxy_client,
|
||||
mode_conteneur_actif, adresse_serveur_ntp,
|
||||
time_zone])
|
||||
general.set_group_type('family')
|
||||
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1])
|
||||
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole] )
|
||||
return descr
|
||||
|
||||
def test_base_config():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
assert config.creole.general.activer_proxy_client == False
|
||||
assert config.creole.general.nom_machine == "eoleng"
|
||||
assert config.get('nom_machine') == "eoleng"
|
||||
result = {'general.numero_etab': None, 'general.nombre_interfaces': 1,
|
||||
'general.serveur_ntp': [], 'interface1.ip_admin_eth0.ip_admin_eth0': None,
|
||||
'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris',
|
||||
'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine':
|
||||
'eoleng', 'general.activer_proxy_client': False}
|
||||
assert make_dict(config.creole) == result
|
||||
result = {'serveur_ntp': [], 'mode_conteneur_actif': False,
|
||||
'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None,
|
||||
'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client':
|
||||
False, 'nombre_interfaces': 1}
|
||||
assert make_dict(config.creole, flatten=True) == result
|
||||
|
||||
def test_get_group_type():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
grp = config.unwrap_from_path('creole.general')
|
||||
assert grp.get_group_type() == "family"
|
||||
|
||||
def test_iter_on_groups():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
result = list(config.creole.iter_groups(group_type= "family"))
|
||||
group_names = [res[0] for res in result]
|
||||
assert group_names == ['general']
|
||||
result = list(config.creole.iter_groups())
|
||||
group_names = [res[0] for res in result]
|
||||
assert group_names == ['general', 'interface1']
|
||||
|
@ -1,42 +0,0 @@
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from tool import reverse_from_paths
|
||||
|
||||
#def make_description():
|
||||
# gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
|
||||
# gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
# objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
# ['std', 'thunk'], 'std')
|
||||
# booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
# intoption = IntOption('int', 'Test int option', default=0)
|
||||
# floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
# stroption = StrOption('str', 'Test string option', default="abc")
|
||||
# boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
# wantref_option = BoolOption('wantref', 'Test requires', default=False)
|
||||
# wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
# default=False)
|
||||
#
|
||||
# gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
# descr = OptionDescription('tiram', '', [gcgroup, booloption, objspaceoption,
|
||||
# wantref_option, stroption,
|
||||
# wantframework_option,
|
||||
# intoption, boolop])
|
||||
# return descr
|
||||
|
||||
def test_rebuild():
|
||||
# pouvoir faire une comparaison avec equal
|
||||
d = {"s1.s2.s3.s4.a": True, "int": 43, "s2.b":True, "s3.c": True, "s3.d":[1,2,3]}
|
||||
cfg = reverse_from_paths(d)
|
||||
assert cfg.s1.s2.s3.s4.a == True
|
||||
assert cfg.int == 43
|
||||
assert cfg.s2.b == True
|
||||
assert cfg.s3.c == True
|
||||
assert cfg.s3.d == [1,2,3]
|
||||
|
||||
# assert config.getpaths() == ['gc.name', 'gc.dummy', 'gc.float', 'bool',
|
||||
# 'objspace', 'wantref', 'str', 'wantframework',
|
||||
# 'int', 'boolop']
|
||||
|
||||
# assert config.getpaths(include_groups=False) == ['gc.name', 'gc.dummy', 'gc.float', 'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
||||
# assert config.getpaths(include_groups=True) == ['gc', 'gc.name', 'gc.dummy', 'gc.float', 'bool', 'objspace', 'wantref', 'str', 'wantframework', 'int', 'boolop']
|
@ -1,26 +0,0 @@
|
||||
#this test is much more to test that **it's there** and answers attribute access
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from tool import extend
|
||||
|
||||
class A:
|
||||
a = 'titi'
|
||||
def tarte(self):
|
||||
return "tart"
|
||||
class B:
|
||||
__metaclass__ = extend
|
||||
|
||||
def to_rst(self):
|
||||
return "hello"
|
||||
|
||||
B.extend(A)
|
||||
|
||||
a = B()
|
||||
|
||||
def test_extendable():
|
||||
assert a.a == 'titi'
|
||||
assert a.tarte() == 'tart'
|
||||
assert a.to_rst() == "hello"
|
||||
|
||||
|
Reference in New Issue
Block a user