coverages

This commit is contained in:
2018-09-15 22:44:49 +02:00
parent 84d1f85b90
commit 2d063f8170
16 changed files with 163 additions and 95 deletions

View File

@ -189,6 +189,44 @@ def test_choiceoption_calc_opt_multi_function():
raises(ValueError, "cfg.option('ch2').value.get()")
def test_choiceoption_calc_opt_multi_function_kwargs():
str_ = StrOption('str', '', ['val1'], multi=True)
choice = ChoiceOption('choice',
"",
default_multi='val2',
values=return_val,
values_params=Params(kwargs={'val': ParamOption(str_)}),
multi=True)
ch2 = ChoiceOption('ch2',
"",
default=['val2'],
values=return_val,
values_params=Params(kwargs={'val': ParamOption(str_)}),
multi=True)
odesc = OptionDescription('od', '', [str_, choice, ch2])
cfg = Config(odesc)
cfg.property.read_write()
owner = cfg.owner.get()
assert cfg.option('choice').owner.isdefault()
assert cfg.option('choice').value.get() == []
#
cfg.option('choice').value.set(['val1'])
assert cfg.option('choice').owner.get() == owner
#
raises(ValueError, "cfg.option('choice').value.set([undefined])")
#
cfg.option('choice').value.set(['val1'])
assert cfg.option('choice').owner.get() == owner
#
cfg.option('choice').value.reset()
assert cfg.option('choice').owner.isdefault()
#
raises(ValueError, "cfg.option('choice').value.set('no')")
assert cfg.option('choice').owner.isdefault()
#
raises(ValueError, "cfg.option('ch2').value.get()")
def test_choiceoption_calc_invalid():
str_ = StrOption('str', '', ['val1'], multi=True)
str_

View File

@ -361,6 +361,17 @@ def test_callback_value_force_permissive():
api.option('val3').value.get() is None
def test_callback_value_force_permissive_kwargs():
val1 = StrOption('val1', "", 'val', properties=('disabled',))
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(value=ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(value=ParamOption(val1, True)))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
api = Config(maconfig)
api.property.read_only()
raises(ConfigError, "api.option('val2').value.get()")
api.option('val3').value.get() is None
def test_callback_symlink():
val1 = StrOption('val1', "", 'val')
val2 = SymLinkOption('val2', val1)

View File

@ -5,7 +5,7 @@ do_autopath()
from py.test import raises
from tiramisu import IntOption, UnicodeOption, OptionDescription, Config
from tiramisu.error import PropertiesOptionError
from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.api import TIRAMISU_VERSION
@ -102,12 +102,18 @@ def test_permissive_frozen():
assert frozenset(props) == frozenset(['disabled'])
if TIRAMISU_VERSION == 3:
def test_invalid_permissive():
descr = make_description()
api = Config(descr)
api.property.read_write()
raises(TypeError, "api.unrestraint.permissive.set(['frozen', 'disabled'])")
def test_invalid_permissive():
descr = make_description()
api = Config(descr)
api.property.read_write()
raises(TypeError, "api.unrestraint.permissive.set(['frozen', 'disabled'])")
def test_forbidden_permissive():
descr = make_description()
api = Config(descr)
api.property.read_write()
raises(ConfigError, "api.permissive.set(frozenset(['force_default_on_freeze']))")
def test_permissive_option():

View File

@ -323,23 +323,41 @@ def test_exportation_importation():
try:
c = Config(o, session_id='test_persistent', persistent=True)
d = Config(o, session_id='test_persistent2', persistent=True)
e = Config(o, session_id='test_persistent3', persistent=True)
except ValueError:
# storage is not persistent
pass
else:
c.owner.set('export')
assert c.option('b').value.get() is None
c.option('b').value.set(True)
assert c.option('b').value.get() is True
assert c.owner.get() == 'export'
del c
#
c = Config(o, session_id='test_persistent', persistent=True)
assert c.value.exportation() == [['b'], [None], [True], ['user']]
assert c.owner.get() == 'export'
assert c.value.exportation() == [['b'], [None], [True], ['export']]
d.value.importation(c.value.exportation())
assert c.value.exportation() == [['b'], [None], [True], ['user']]
assert d.value.exportation() == [['b'], [None], [True], ['user']]
assert c.value.exportation() == [['b'], [None], [True], ['export']]
assert c.owner.get() == 'export'
assert d.value.exportation() == [['b'], [None], [True], ['export']]
assert d.owner.get() == 'user'
del d
#
d = Config(o, session_id='test_persistent2', persistent=True)
assert d.value.exportation() == [['b'], [None], [True], ['user']]
assert d.value.exportation() == [['b'], [None], [True], ['export']]
assert d.owner.get() == 'user'
#
e.value.importation(c.value.exportation(with_default_owner=True))
assert e.value.exportation() == [['b'], [None], [True], ['export']]
assert e.owner.get() == 'export'
del e
#
e = Config(o, session_id='test_persistent3', persistent=True)
assert e.value.exportation() == [['b'], [None], [True], ['export']]
assert e.owner.get() == 'export'
#
delete_session('test_persistent')
delete_session('test_persistent2')
delete_session('test_persistent3')

View File

@ -63,6 +63,16 @@ def test_symlink_addproperties():
raises(TypeError, "api.option('c').property.reset()")
def test_symlink_getpermissive():
boolopt = BoolOption('b', '', default=True, properties=('test',))
linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription('opt', '', [boolopt, linkopt])
api = Config(descr)
api.property.read_write()
api.option('b').permissive.set(frozenset(['perm']))
api.option('c').permissive.get() == frozenset(['perm'])
def test_symlink_addpermissive():
boolopt = BoolOption('b', '', default=True, properties=('test',))
linkopt = SymLinkOption("c", boolopt)