mandatory_warnings => mandatory

This commit is contained in:
Emmanuel Garette 2018-11-13 12:39:51 +01:00
parent 5bb788b5b7
commit f04169d5a6
5 changed files with 56 additions and 39 deletions

View File

@ -284,7 +284,7 @@ def test_mandatory_dyndescription():
api.option('od.dodval1.stval1').value.reset() api.option('od.dodval1.stval1').value.reset()
api.property.read_only() api.property.read_only()
raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()") raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()")
assert list(api.value.mandatory_warnings()) == ['od.dodval1.stval1', 'od.dodval2.stval2'] assert list(api.value.mandatory()) == ['od.dodval1.stval1', 'od.dodval2.stval2']
def test_build_dyndescription_context(): def test_build_dyndescription_context():
@ -446,7 +446,7 @@ def test_mandatory_dyndescription_context():
api.option('od.dodval1.stval1').value.reset() api.option('od.dodval1.stval1').value.reset()
api.property.read_only() api.property.read_only()
raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()") raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()")
assert list(api.value.mandatory_warnings()) == ['od.dodval1.stval1', 'od.dodval2.stval2'] assert list(api.value.mandatory()) == ['od.dodval1.stval1', 'od.dodval2.stval2']
def test_increase_dyndescription_context(): def test_increase_dyndescription_context():

View File

@ -329,11 +329,11 @@ def test_mandatory_warnings_ro():
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3'] assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
api.property.read_write() api.property.read_write()
api.option('str').value.set('a') api.option('str').value.set('a')
api.property.read_only() api.property.read_only()
assert list(api.value.mandatory_warnings()) == ['str1', 'unicode2', 'str3'] assert list(api.value.mandatory()) == ['str1', 'unicode2', 'str3']
def test_mandatory_warnings_rw(): def test_mandatory_warnings_rw():
@ -342,9 +342,9 @@ def test_mandatory_warnings_rw():
api.option('str').value.set('') api.option('str').value.set('')
api.property.read_write() api.property.read_write()
api.option('str').value.get() api.option('str').value.get()
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3'] assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
api.option('str').value.set('a') api.option('str').value.set('a')
assert list(api.value.mandatory_warnings()) == ['str1', 'unicode2', 'str3'] assert list(api.value.mandatory()) == ['str1', 'unicode2', 'str3']
def test_mandatory_warnings_disabled(): def test_mandatory_warnings_disabled():
@ -353,9 +353,9 @@ def test_mandatory_warnings_disabled():
api.option('str').value.set('') api.option('str').value.set('')
api.property.read_write() api.property.read_write()
api.option('str').value.get() api.option('str').value.get()
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'} assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
api.option('str').property.add('disabled') api.option('str').property.add('disabled')
assert set(api.value.mandatory_warnings()) == {'str1', 'unicode2', 'str3'} assert set(api.value.mandatory()) == {'str1', 'unicode2', 'str3'}
def test_mandatory_warnings_hidden(): def test_mandatory_warnings_hidden():
@ -365,9 +365,9 @@ def test_mandatory_warnings_hidden():
api.property.read_write() api.property.read_write()
api.permissive.set(frozenset(['hidden'])) api.permissive.set(frozenset(['hidden']))
api.option('str').value.get() api.option('str').value.get()
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'} assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
api.option('str').property.add('hidden') api.option('str').property.add('hidden')
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'} assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
def test_mandatory_warnings_frozen(): def test_mandatory_warnings_frozen():
@ -376,10 +376,10 @@ def test_mandatory_warnings_frozen():
api.option('str').value.set('') api.option('str').value.set('')
api.property.read_write() api.property.read_write()
api.option('str').value.get() api.option('str').value.get()
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'} assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
api.option('str').property.add('frozen') api.option('str').property.add('frozen')
api.property.read_only() api.property.read_only()
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'} assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
def test_mandatory_master(): def test_mandatory_master():
@ -404,7 +404,7 @@ def test_mandatory_warnings_master():
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
descr = OptionDescription('o', '', [interface1]) descr = OptionDescription('o', '', [interface1])
api = Config(descr) api = Config(descr)
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0'] assert list(api.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
def test_mandatory_master_empty(): def test_mandatory_master_empty():
@ -462,17 +462,17 @@ def test_mandatory_warnings_master_empty():
api.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined]) api.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None] assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0'] assert list(api.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['']) api.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [''] assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0'] assert list(api.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
# #
api.property.read_write() api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip']) api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
assert list(api.value.mandatory_warnings()) == [] assert list(api.value.mandatory()) == []
def test_mandatory_slave(): def test_mandatory_slave():
@ -517,9 +517,9 @@ def test_mandatory_warnings_slave():
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
# #
api.property.read_write() api.property.read_write()
assert list(api.value.mandatory_warnings()) == [] assert list(api.value.mandatory()) == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip']) api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.netmask_admin_eth0'] assert list(api.value.mandatory()) == ['ip_admin_eth0.netmask_admin_eth0']
def test_mandatory_warnings_symlink(): def test_mandatory_warnings_symlink():
@ -528,19 +528,19 @@ def test_mandatory_warnings_symlink():
api.option('str').value.set('') api.option('str').value.set('')
api.property.read_write() api.property.read_write()
api.option('str').value.get() api.option('str').value.get()
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'str3'] assert list(api.value.mandatory()) == ['str', 'str1', 'str3']
api.option('str').property.add('frozen') api.option('str').property.add('frozen')
api.property.read_only() api.property.read_only()
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'str3'] assert list(api.value.mandatory()) == ['str', 'str1', 'str3']
#def test_mandatory_warnings_validate(): #def test_mandatory_warnings_validate():
# descr = make_description3() # descr = make_description3()
# api = Config(descr) # api = Config(descr)
# api.option('str').value.set('') # api.option('str').value.set('')
# raises(ValueError, "list(api.value.mandatory_warnings())") # raises(ValueError, "list(api.value.mandatory())")
# api.option('str').value.set('test') # api.option('str').value.set('test')
# raises(ValueError, "list(api.value.mandatory_warnings())") # raises(ValueError, "list(api.value.mandatory())")
def test_mandatory_warnings_validate_empty(): def test_mandatory_warnings_validate_empty():
@ -548,7 +548,7 @@ def test_mandatory_warnings_validate_empty():
api = Config(descr) api = Config(descr)
api.option('str').value.set('') api.option('str').value.set('')
api.property.read_only() api.property.read_only()
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'str3', 'unicode1'] assert list(api.value.mandatory()) == ['str', 'str1', 'str3', 'unicode1']
def test_mandatory_warnings_requires(): def test_mandatory_warnings_requires():
@ -564,12 +564,12 @@ def test_mandatory_warnings_requires():
api.option('str').value.set('') api.option('str').value.set('')
api.property.read_write() api.property.read_write()
api.option('str').value.get() api.option('str').value.get()
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2'] assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2']
api.property.read_only() api.property.read_only()
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2'] assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2']
api.property.read_write() api.property.read_write()
api.option('str').value.set('yes') api.option('str').value.set('yes')
assert list(api.value.mandatory_warnings()) == ['str1', 'unicode2', 'str3'] assert list(api.value.mandatory()) == ['str1', 'unicode2', 'str3']
def test_mandatory_warnings_requires_masterslaves(): def test_mandatory_warnings_requires_masterslaves():
@ -582,9 +582,9 @@ def test_mandatory_warnings_requires_masterslaves():
api = Config(descr) api = Config(descr)
api.option('str').value.set('') api.option('str').value.set('')
api.option('master.str1').value.set(['str']) api.option('master.str1').value.set(['str'])
assert list(api.value.mandatory_warnings()) == ['str'] assert list(api.value.mandatory()) == ['str']
api.option('str').value.set('yes') api.option('str').value.set('yes')
assert list(api.value.mandatory_warnings()) == ['master.str2'] assert list(api.value.mandatory()) == ['master.str2']
def test_mandatory_warnings_requires_masterslaves_slave(): def test_mandatory_warnings_requires_masterslaves_slave():
@ -595,9 +595,9 @@ def test_mandatory_warnings_requires_masterslaves_slave():
descr = OptionDescription('tiram', '', [masterslave]) descr = OptionDescription('tiram', '', [masterslave])
api = Config(descr) api = Config(descr)
api.option('master.str').value.set(['str']) api.option('master.str').value.set(['str'])
assert list(api.value.mandatory_warnings()) == [] assert list(api.value.mandatory()) == []
api.option('master.str1', 0).value.set('yes') api.option('master.str1', 0).value.set('yes')
assert list(api.value.mandatory_warnings()) == ['master.str2'] assert list(api.value.mandatory()) == ['master.str2']
def test_mandatory_od_disabled(): def test_mandatory_od_disabled():
@ -605,6 +605,6 @@ def test_mandatory_od_disabled():
descr = OptionDescription('od', '', [descr]) descr = OptionDescription('od', '', [descr])
api = Config(descr) api = Config(descr)
api.property.read_only() api.property.read_only()
assert list(api.value.mandatory_warnings()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3'] assert list(api.value.mandatory()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
api.option('tiram').property.add('disabled') api.option('tiram').property.add('disabled')
assert list(api.value.mandatory_warnings()) == [] assert list(api.value.mandatory()) == []

View File

@ -670,7 +670,7 @@ def test_callback_master_and_slaves_master3():
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
assert list(api.value.mandatory_warnings()) == ['val1.val1'] assert list(api.value.mandatory()) == ['val1.val1']
def test_callback_master_and_slaves_master4(): def test_callback_master_and_slaves_master4():
@ -685,7 +685,7 @@ def test_callback_master_and_slaves_master4():
api.property.read_write() api.property.read_write()
api.property.add('expert') api.property.add('expert')
api.permissive.set(frozenset(['expert'])) api.permissive.set(frozenset(['expert']))
assert list(api.value.mandatory_warnings()) == [] assert list(api.value.mandatory()) == []
def test_consistency_master_and_slaves_master_mandatory_transitive(): def test_consistency_master_and_slaves_master_mandatory_transitive():
@ -709,7 +709,7 @@ def test_consistency_master_and_slaves_master_mandatory_transitive():
else: else:
raise Exception('must raises') raise Exception('must raises')
raises(PropertiesOptionError, "api.option('val3.val3').value.get()") raises(PropertiesOptionError, "api.option('val3.val3').value.get()")
assert list(api.value.mandatory_warnings()) == [] assert list(api.value.mandatory()) == []
def test_consistency_master_and_slaves_master_mandatory_non_transitive(): def test_consistency_master_and_slaves_master_mandatory_non_transitive():
@ -729,9 +729,9 @@ def test_consistency_master_and_slaves_master_mandatory_non_transitive():
api = Config(maconfig) api = Config(maconfig)
api.property.read_write() api.property.read_write()
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
assert list(api.value.mandatory_warnings()) == ["val1.val1", "val1.val2"] assert list(api.value.mandatory()) == ["val1.val1", "val1.val2"]
else: else:
assert list(api.value.mandatory_warnings()) == ["val1.val1"] assert list(api.value.mandatory()) == ["val1.val1"]
def test_callback_master_and_slaves_master_list(): def test_callback_master_and_slaves_master_list():

View File

@ -736,7 +736,7 @@ def test_consistency_broadcast_warnings():
assert len(w) == 1 assert len(w) == 1
api.property.read_write() api.property.read_write()
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
list(api.value.mandatory_warnings()) list(api.value.mandatory())
assert len(w) == 0 assert len(w) == 0

View File

@ -433,6 +433,23 @@ class _TiramisuOptionValueOption:
self._test_slave_index() self._test_slave_index()
self._subconfig.delattr(self._option_bag) self._subconfig.delattr(self._option_bag)
def default(self):
"""Get default value (default of option or calculated value)"""
option = self._option_bag.option
values = self._option_bag.config_bag.context.cfgimpl_get_values()
if option.impl_is_master_slaves('slave') and self._option_bag.index is None:
value = []
length = self._subconfig.cfgimpl_get_length_slave(self._option_bag)
for idx in range(length):
soption_bag = OptionBag()
soption_bag.set_option(option,
self._option_bag.path,
idx,
self._option_bag.config_bag)
value.append(values.getdefaultvalue(soption_bag))
else:
return values.getdefaultvalue(self._option_bag)
class _TiramisuOptionValueMaster: class _TiramisuOptionValueMaster:
def pop(self, index): def pop(self, index):
@ -755,7 +772,7 @@ class TiramisuContextInformation(TiramisuContext):
class TiramisuContextValue(TiramisuContext): class TiramisuContextValue(TiramisuContext):
"""Manage config value""" """Manage config value"""
def mandatory_warnings(self): def mandatory(self):
"""Return path of options with mandatory property without any value""" """Return path of options with mandatory property without any value"""
return self._config_bag.context.cfgimpl_get_values().mandatory_warnings(self._config_bag) return self._config_bag.context.cfgimpl_get_values().mandatory_warnings(self._config_bag)