test coverage

This commit is contained in:
Emmanuel Garette 2018-09-22 17:45:52 +02:00
parent 721ff8643d
commit df77bc8738
8 changed files with 74 additions and 41 deletions

View file

@ -919,9 +919,8 @@ def autocheck_set_owner(cfg, mcfg, pathread, pathwrite, confread, confwrite, **k
if not isslave: if not isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
cfg.config(confwrite).option(pathwrite).owner.set('new_user') cfg.config(confwrite).option(pathwrite).owner.set('new_user')
raises(ConfigError, "cfg.config(confwrite).option(pathwrite).owner.set('default')") raises(ValueError, "cfg.config(confwrite).option(pathwrite).owner.set('default')")
raises(ConfigError, "cfg.config(confwrite).option(pathwrite).owner.set('forced')") raises(ValueError, "cfg.config(confwrite).option(pathwrite).owner.set('forced')")
raises(ConfigError, "cfg.config(confwrite).option(pathwrite).owner.set('meta')")
#FIXME else: #FIXME else:
# raises(PropertiesOptionError, "cfg.config(confwrite).option(pathwrite).owner.set('new_user')") # raises(PropertiesOptionError, "cfg.config(confwrite).option(pathwrite).owner.set('new_user')")
else: else:
@ -1081,7 +1080,7 @@ def autocheck_find(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs
def _getoption(opt): def _getoption(opt):
opt = opt.option.get() opt = opt.option.get()
if opt.impl_is_dynsymlinkoption(): if opt.impl_is_dynsymlinkoption():
opt = opt.impl_getopt() opt = opt._opt
return opt return opt
def _getoptions(opts): def _getoptions(opts):

View file

@ -191,12 +191,15 @@ def test_get_modified_values():
root = OptionDescription('root', '', [d1]) root = OptionDescription('root', '', [d1])
config = Config(root) config = Config(root)
assert to_tuple(config.value.exportation()) == ((), (), (), ()) assert to_tuple(config.value.exportation()) == ((), (), (), ())
assert not config.option('od.g5').option.ismulti()
assert not config.option('od.g5').option.issubmulti()
config.option('od.g5').value.set('yes') config.option('od.g5').value.set('yes')
assert to_tuple(config.value.exportation()) == (('od.g5',), (None,), ('yes',), ('user',)) assert to_tuple(config.value.exportation()) == (('od.g5',), (None,), ('yes',), ('user',))
config.option('od.g4').value.set(True) config.option('od.g4').value.set(True)
assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g4'), (None, None), ('yes', True), ('user', 'user')) assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g4'), (None, None), ('yes', True), ('user', 'user'))
config.option('od.g4').value.reset() config.option('od.g4').value.reset()
assert to_tuple(config.value.exportation()) == (('od.g5',), (None,), ('yes',), ('user',)) assert to_tuple(config.value.exportation()) == (('od.g5',), (None,), ('yes',), ('user',))
assert config.option('od.g6').option.ismulti()
config.option('od.g6').value.set([undefined]) config.option('od.g6').value.set([undefined])
assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', (None,)), ('user', 'user')) assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', (None,)), ('user', 'user'))
config.option('od.g6').value.set([]) config.option('od.g6').value.set([])

View file

@ -205,6 +205,10 @@ def test_groups_is_master():
assert api.option('ip_admin_eth0').option.ismasterslaves() assert api.option('ip_admin_eth0').option.ismasterslaves()
assert not api.option('od2.var').option.ismaster() assert not api.option('od2.var').option.ismaster()
assert not api.option('od2.var').option.isslave() assert not api.option('od2.var').option.isslave()
assert api.option('ip_admin_eth0.ip_admin_eth0').option.ismulti()
assert api.option('ip_admin_eth0.netmask_admin_eth0').option.ismulti()
assert not api.option('ip_admin_eth0.ip_admin_eth0').option.issubmulti()
assert not api.option('ip_admin_eth0.netmask_admin_eth0').option.issubmulti()
assert api.option('ip_admin_eth0.ip_admin_eth0').option.ismaster() assert api.option('ip_admin_eth0.ip_admin_eth0').option.ismaster()
assert not api.option('ip_admin_eth0.ip_admin_eth0').option.isslave() assert not api.option('ip_admin_eth0.ip_admin_eth0').option.isslave()
assert not api.option('ip_admin_eth0.netmask_admin_eth0').option.ismaster() assert not api.option('ip_admin_eth0.netmask_admin_eth0').option.ismaster()

View file

@ -83,6 +83,22 @@ def test_none():
meta.config('conf1').option('od1.i3').value.reset() meta.config('conf1').option('od1.i3').value.reset()
assert meta.option('od1.i3').value.get() is meta.config('conf1').option('od1.i3').value.get() is meta.config('conf2').option('od1.i3').value.get() is None assert meta.option('od1.i3').value.get() is meta.config('conf1').option('od1.i3').value.get() is meta.config('conf2').option('od1.i3').value.get() is None
assert meta.option('od1.i3').owner.get() is meta.config('conf1').option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.default assert meta.option('od1.i3').owner.get() is meta.config('conf1').option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.default
#
assert meta.config(None).config.name() == meta.config.name()
def test_reset():
meta = make_metaconfig()
assert meta.option('od1.i2').value.get() == 1
meta.option('od1.i2').value.set(2)
meta.config('conf1').option('od1.i2').value.set(3)
assert meta.option('od1.i2').value.get() == 2
assert meta.config('conf1').option('od1.i2').value.get() == 3
assert meta.config('conf2').option('od1.i2').value.get() == 2
meta.config.reset()
assert meta.option('od1.i2').value.get() == 1
assert meta.config('conf1').option('od1.i2').value.get() == 3
assert meta.config('conf2').option('od1.i2').value.get() == 1
def test_default(): def test_default():

View file

@ -87,6 +87,15 @@ def test_optiondescription_get_information():
assert o.impl_getdoc() == description assert o.impl_getdoc() == description
def test_option_isoptiondescription():
i = IntOption('test', '')
od = OptionDescription('od', '', [i])
od = OptionDescription('od', '', [od])
cfg = Config(od)
assert cfg.option('od').option.isoptiondescription()
assert not cfg.option('od.test').option.isoptiondescription()
def test_option_multi(): def test_option_multi():
IntOption('test', '', multi=True) IntOption('test', '', multi=True)
IntOption('test', '', multi=True, default_multi=1) IntOption('test', '', multi=True, default_multi=1)
@ -127,6 +136,7 @@ def test_optiondescription_group():
assert len(list(api.option.list('optiondescription'))) == 2 assert len(list(api.option.list('optiondescription'))) == 2
assert len(list(api.option.list('optiondescription', group_type=groups.family))) == 1 assert len(list(api.option.list('optiondescription', group_type=groups.family))) == 1
assert len(list(api.option.list('optiondescription', group_type=groups.notfamily))) == 1 assert len(list(api.option.list('optiondescription', group_type=groups.notfamily))) == 1
raises(APIError, "list(api.option.list('unknown'))")
def test_optiondescription_group_redefined(): def test_optiondescription_group_redefined():

View file

@ -46,6 +46,8 @@ def test_requires():
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) api = Config(od)
api.property.read_write() api.property.read_write()
assert not api.option('activate_service').option.requires()
assert api.option('ip_address_service').option.requires()
api.option('ip_address_service').value.get() api.option('ip_address_service').value.get()
api.option('activate_service').value.set(False) api.option('activate_service').value.set(False)
props = [] props = []

View file

@ -41,6 +41,8 @@ def test_submulti():
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti) multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
od = OptionDescription('od', '', [multi, multi2, multi3]) od = OptionDescription('od', '', [multi, multi2, multi3])
api = Config(od) api = Config(od)
assert api.option('multi').option.ismulti()
assert api.option('multi').option.issubmulti()
assert api.option('multi').owner.get() == owners.default assert api.option('multi').owner.get() == owners.default
assert api.option('multi').value.get() == [] assert api.option('multi').value.get() == []
assert api.option('multi').owner.get() == owners.default assert api.option('multi').owner.get() == owners.default

View file

@ -156,9 +156,9 @@ class CommonTiramisuOption(CommonTiramisu):
if self.option_bag.index is None and option.impl_is_master_slaves('slave'): if self.option_bag.index is None and option.impl_is_master_slaves('slave'):
raise APIError(_('index must be set with the slave option "{}"').format(self.option_bag.path)) raise APIError(_('index must be set with the slave option "{}"').format(self.option_bag.path))
elif self.option_bag.index is not None and not option.impl_is_master_slaves('slave'): elif self.option_bag.index is not None and not option.impl_is_master_slaves('slave'):
raise APIError(_('index must be set only with a slave option, not for "{}"').format(self.option_bag.path)) raise APIError(_('index must be set only with a slave option, not for "{}"').format(self.option_bag.path)) # pragma: no cover
def __getattr__(self, name): def __getattr__(self, name): # pragma: no cover
if not hasattr(CommonTiramisuOption, name): if not hasattr(CommonTiramisuOption, name):
raise APIError(_('unknown method {}').format(name)) raise APIError(_('unknown method {}').format(name))
else: else:
@ -246,7 +246,7 @@ class TiramisuOptionOption(CommonTiramisuOption):
option = self.option_bag.option option = self.option_bag.option
if not option.impl_is_optiondescription() and not name.startswith('_'): if not option.impl_is_optiondescription() and not name.startswith('_'):
return getattr(self, '_' + name) return getattr(self, '_' + name)
raise APIError(_('{} is unknown').format(name)) raise APIError(_('{} is unknown').format(name)) # pragma: no cover
def isoptiondescription(self): def isoptiondescription(self):
"""test if option is an optiondescription""" """test if option is an optiondescription"""
@ -560,13 +560,10 @@ class TiramisuOption(CommonTiramisu):
self._path = path self._path = path
self.index = index self.index = index
self.config_bag = config_bag self.config_bag = config_bag
if option_bag: self.option_bag = OptionBag()
self.option_bag = option_bag self.option_bag.path = self._path
else: self.option_bag.index = self.index
self.option_bag = OptionBag() self.option_bag.config_bag = self.config_bag
self.option_bag.path = self._path
self.option_bag.index = self.index
self.option_bag.config_bag = self.config_bag
if not self.registers: if not self.registers:
registers(self.registers, self.__class__.__name__) registers(self.registers, self.__class__.__name__)
@ -577,7 +574,7 @@ class TiramisuOption(CommonTiramisu):
self.option_bag) self.option_bag)
elif self._get_option().impl_is_optiondescription() and not subfunc.startswith('_'): elif self._get_option().impl_is_optiondescription() and not subfunc.startswith('_'):
return getattr(self, '_' + subfunc) return getattr(self, '_' + subfunc)
raise APIError(_('please specify a valid sub function ({})').format(subfunc)) raise APIError(_('please specify a valid sub function ({})').format(subfunc)) # pragma: no cover
def _find(self, def _find(self,
name: str, name: str,
@ -613,29 +610,29 @@ class TiramisuOption(CommonTiramisu):
return t_option return t_option
ret.append(t_option) ret.append(t_option)
return ret return ret
#
def _get(self, name): # def _get(self, name):
self._get_option() # self._get_option()
current_option = self.option_bag.option.impl_getchild(name, # current_option = self.option_bag.option.impl_getchild(name,
self.config_bag, # self.config_bag,
self.subconfig.cfgimpl_get_path) # self.subconfig.cfgimpl_get_path)
path = self.option_bag.path + '.' + name # path = self.option_bag.path + '.' + name
option_bag= OptionBag() # option_bag= OptionBag()
option_bag.set_option(current_option, # option_bag.set_option(current_option,
path, # path,
None, # None,
self.config_bag) # self.config_bag)
if current_option.impl_is_optiondescription(): # if current_option.impl_is_optiondescription():
subconfig = self.subconfig.getattr(name, # subconfig = self.subconfig.getattr(name,
option_bag) # option_bag)
else: # else:
subconfig = self.subconfig # subconfig = self.subconfig
return TiramisuOption(name, # return TiramisuOption(name,
path, # path,
None, # None,
subconfig, # subconfig,
self.config_bag, # self.config_bag,
option_bag) # option_bag)
def _group_type(self): def _group_type(self):
"""get type for an optiondescription (only for optiondescription)""" """get type for an optiondescription (only for optiondescription)"""
@ -992,7 +989,7 @@ class TiramisuContextConfig(TiramisuContext):
return Config(self.config_bag.context.find_firsts(byname=name, return Config(self.config_bag.context.find_firsts(byname=name,
byvalue=value, byvalue=value,
config_bag=self.config_bag)) config_bag=self.config_bag))
else: else: # pragma: no cover
raise APIError('not implemented yet') raise APIError('not implemented yet')
def name(self): def name(self):
@ -1064,9 +1061,9 @@ class TiramisuContextConfig(TiramisuContext):
return getattr(self, '_g_' + name) return getattr(self, '_g_' + name)
elif isinstance(self.config_bag.context, KernelConfig): elif isinstance(self.config_bag.context, KernelConfig):
return getattr(self, '_c_' + name) return getattr(self, '_c_' + name)
except APIError: except APIError: # pragma: no cover
raise APIError(_('{} is unknown').format(name)) raise APIError(_('{} is unknown').format(name))
raise APIError(_('{} is unknown').format(name)) raise APIError(_('{} is unknown').format(name)) # pragma: no cover
class TiramisuDispatcher: class TiramisuDispatcher: