127 lines
4.4 KiB
Python
127 lines
4.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
#this test is much more to test that **it's there** and answers attribute access
|
|
import autopath
|
|
from py.test import raises
|
|
|
|
from tiramisu.config import Config
|
|
from tiramisu.option import IntOption, FloatOption, StrOption, ChoiceOption, \
|
|
BoolOption, UnicodeOption, OptionDescription
|
|
|
|
|
|
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", properties=('mandatory', ))
|
|
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 is 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 is False
|
|
cfg.gc.dummy = True
|
|
assert cfg.gc.dummy is True
|
|
|
|
|
|
def test_base_config_and_groups():
|
|
descr = make_description()
|
|
# overrides the booloption default value
|
|
config = Config(descr)
|
|
config.bool = False
|
|
assert config.gc.name == 'ref'
|
|
assert config.bool is 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)
|
|
config.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)
|
|
config.bool = False
|
|
assert config.gc.name == 'ref'
|
|
config.wantframework = True
|
|
|
|
|
|
def test_cfgimpl_get_home_by_path():
|
|
descr = make_description()
|
|
config = Config(descr)
|
|
config.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']
|
|
|
|
|
|
def test_information_config():
|
|
descr = make_description()
|
|
config = Config(descr)
|
|
string = 'some informations'
|
|
config.impl_set_information('info', string)
|
|
assert config.impl_get_information('info') == string
|
|
|
|
|
|
def test_information_display():
|
|
g1 = IntOption('g1', '', 1)
|
|
g2 = StrOption('g2', '', 'héhé')
|
|
g3 = UnicodeOption('g3', '', u'héhé')
|
|
g4 = BoolOption('g4', '', True)
|
|
g5 = StrOption('g5', '')
|
|
d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5])
|
|
root = OptionDescription('root', '', [d1])
|
|
config = Config(root)
|
|
str(config.od)
|