This commit is contained in:
2018-09-26 21:30:05 +02:00
parent df77bc8738
commit 4426cc5111
6 changed files with 71 additions and 63 deletions

View File

@ -541,6 +541,37 @@ def test_requires_dyndescription():
assert frozenset(props) == frozenset(['disabled'])
def test_requires_dyndescription_boolean():
boolean1 = BoolOption('boolean1', '', True)
boolean = BoolOption('boolean', '', True, requires=[{'option': boolean1,
'expected': False,
'action': 'disabled'}])
st = StrOption('st', '', requires=[{'option': boolean, 'expected': False,
'action': 'disabled'}])
dod = DynOptionDescription('dod', '', [st], callback=return_list)
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od, boolean1, boolean])
cfg = Config(od2)
cfg.property.read_write()
assert cfg.value.dict() == {'boolean1': True,
'boolean': True,
'od.dodval1.stval1': None,
'od.dodval2.stval2': None}
#
cfg.option('boolean').value.set(False)
assert cfg.value.dict() == {'boolean1': True,
'boolean': False}
#
cfg.option('boolean').value.set(True)
assert cfg.value.dict() == {'boolean1': True,
'boolean': True,
'od.dodval1.stval1': None,
'od.dodval2.stval2': None}
#
cfg.option('boolean1').value.set(False)
assert cfg.value.dict() == {'boolean1': False}
def test_requires_dyndescription_in_dyn():
boolean = BoolOption('boolean', '', True)
st = StrOption('st', '', requires=[{'option': boolean, 'expected': False,

View File

@ -227,9 +227,12 @@ def test_freeze_and_has_callback():
def test_callback():
val1 = StrOption('val1', "", callback=return_val)
maconfig = OptionDescription('rootconfig', '', [val1])
val2 = StrOption('val2', "")
maconfig = OptionDescription('rootconfig', '', [val1, val2])
api = Config(maconfig)
api.property.read_write()
assert api.option('val1').option.callbacks() != (None, None)
assert api.option('val2').option.callbacks() == (None, None)
assert api.option('val1').value.get() == 'val'
api.option('val1').value.set('new-val')
assert api.option('val1').value.get() == 'new-val'

View File

@ -50,9 +50,13 @@ def test_consistency_warnings_only_default():
def test_consistency_warnings_only():
a = IntOption('a', '')
b = IntOption('b', '')
od = OptionDescription('od', '', [a, b])
c = IntOption('c', '')
od = OptionDescription('od', '', [a, b, c])
a.impl_add_consistency('not_equal', b, warnings_only=True)
api = Config(od)
assert api.option('a').option.consistencies()
assert not api.option('b').option.consistencies()
assert not api.option('c').option.consistencies()
api.option('a').value.set(1)
warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: