convert tests
This commit is contained in:
0
test/new_api/__init__.py
Normal file
0
test/new_api/__init__.py
Normal file
14
test/new_api/autopath.py
Normal file
14
test/new_api/autopath.py
Normal file
@ -0,0 +1,14 @@
|
||||
"""automatically sets the PYTHONPATH before running the unit tests
|
||||
|
||||
This is supposed to be used in development mode (i.e. testing from a fresh
|
||||
checkout)
|
||||
"""
|
||||
|
||||
from os.path import dirname, abspath, join, normpath
|
||||
import sys
|
||||
|
||||
def do_autopath():
|
||||
HERE = dirname(abspath(__file__))
|
||||
PATH = normpath(join(HERE, '..', 'tiramisu'))
|
||||
if PATH not in sys.path:
|
||||
sys.path.insert(1, PATH)
|
790
test/new_api/test_cache.py
Normal file
790
test/new_api/test_cache.py
Normal file
@ -0,0 +1,790 @@
|
||||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu import setting, value
|
||||
setting.expires_time = 1
|
||||
value.expires_time = 1
|
||||
from tiramisu.option import BoolOption, IPOption, IntOption, StrOption, OptionDescription, MasterSlaves
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.error import ConfigError, PropertiesOptionError
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu import getapi, undefined
|
||||
from tiramisu.api import TIRAMISU_VERSION
|
||||
|
||||
|
||||
from time import sleep, time
|
||||
from py.test import raises
|
||||
|
||||
|
||||
global incr
|
||||
incr = 0
|
||||
def return_incr():
|
||||
global incr
|
||||
incr += 1
|
||||
return incr
|
||||
|
||||
|
||||
def return_value(val):
|
||||
return val
|
||||
|
||||
|
||||
def make_description():
|
||||
u1 = IntOption('u1', '', multi=True)
|
||||
u2 = IntOption('u2', '')
|
||||
u3 = IntOption('u3', '', multi=True)
|
||||
return OptionDescription('od1', '', [u1, u2, u3])
|
||||
|
||||
|
||||
def test_cache_config():
|
||||
od1 = make_description()
|
||||
assert od1.impl_already_build_caches() is False
|
||||
c = Config(od1)
|
||||
assert od1.impl_already_build_caches() is True
|
||||
c
|
||||
|
||||
|
||||
def test_cache():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
|
||||
|
||||
#def test_get_cache():
|
||||
# # force a value in cache, try if reget corrupted value
|
||||
# od1 = make_description()
|
||||
# c = Config(od1)
|
||||
# api = getapi(c)
|
||||
# values = c.cfgimpl_get_values()
|
||||
# settings = c.cfgimpl_get_settings()
|
||||
# ntime = time() + 1
|
||||
# settings._p_.setcache('u1', set(['inject']), ntime, None)
|
||||
# assert 'inject' in settings[od1.u1]
|
||||
# values._p_.setcache('u1', 100, ntime, None)
|
||||
# assert api.option('u1').value.get() == [100]
|
||||
|
||||
|
||||
#def test_get_cache_no_expire():
|
||||
# # force a value in cache, try if reget corrupted value
|
||||
# od1 = make_description()
|
||||
# c = Config(od1)
|
||||
# api = getapi(c)
|
||||
# values = c.cfgimpl_get_values()
|
||||
# settings = c.cfgimpl_get_settings()
|
||||
# settings._p_.setcache('u1', set(['inject2']), None, None)
|
||||
# assert 'inject2' in settings[od1.u1]
|
||||
# values._p_.setcache('u1', 200, None, None)
|
||||
# assert api.option('u1').value.get() == [200]
|
||||
|
||||
|
||||
def test_cache_reset():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
#when change a value
|
||||
api.option('u1').value.get()
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
api.option('u2').value.set(1)
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
#when remove a value
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.option('u2').value.reset()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
#when add/del property
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.option('u2').property.add('test')
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.option('u2').property.pop('test')
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
#when enable/disabled property
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.property.add('test')
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.property.pop('test')
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
|
||||
|
||||
def test_cache_reset_multi():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
api.option('u1').value.get()
|
||||
api.option('u3').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' in values._p_.get_cached()
|
||||
assert 'u3' in settings._p_.get_cached()
|
||||
#when change a value
|
||||
api.option('u3').value.set([1])
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' not in values._p_.get_cached()
|
||||
assert 'u3' not in settings._p_.get_cached()
|
||||
#when append value
|
||||
api.option('u1').value.get()
|
||||
api.option('u3').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' in values._p_.get_cached()
|
||||
assert 'u3' in settings._p_.get_cached()
|
||||
api.option('u3').value.set([1, 1])
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' not in values._p_.get_cached()
|
||||
assert 'u3' not in settings._p_.get_cached()
|
||||
#when pop value
|
||||
api.option('u1').value.get()
|
||||
api.option('u3').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' in values._p_.get_cached()
|
||||
assert 'u3' in settings._p_.get_cached()
|
||||
api.option('u3').value.set([1])
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' not in values._p_.get_cached()
|
||||
assert 'u3' not in settings._p_.get_cached()
|
||||
#when remove a value
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
api.option('u3').value.reset()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u3' not in values._p_.get_cached()
|
||||
assert 'u3' not in settings._p_.get_cached()
|
||||
|
||||
|
||||
def test_reset_cache():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache()
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
api.option('u1').value.get()
|
||||
sleep(1)
|
||||
api.option('u1').value.get()
|
||||
sleep(1)
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache()
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
assert 'u2' not in values._p_.get_cached()
|
||||
assert 'u2' not in settings._p_.get_cached()
|
||||
|
||||
|
||||
#def test_reset_cache_subconfig():
|
||||
# od1 = make_description()
|
||||
# od2 = OptionDescription('od2', '', [od1])
|
||||
# c = Config(od2)
|
||||
# api = getapi(c)
|
||||
# values = c.cfgimpl_get_values()
|
||||
# api.option('od1.u1').value.get()
|
||||
# assert 'od1.u1' in values._p_.get_cached()
|
||||
# c.od1.cfgimpl_reset_cache()
|
||||
# assert 'od1.u1' not in values._p_.get_cached()
|
||||
|
||||
|
||||
def test_reset_cache_only_expired():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache(True)
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
sleep(1)
|
||||
api.option('u1').value.get()
|
||||
sleep(1)
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache(True)
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
|
||||
|
||||
def test_cache_not_expire():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
api.property.pop('expire')
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache(True)
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
sleep(1)
|
||||
api.option('u2').value.get()
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
c.cfgimpl_reset_cache(True)
|
||||
assert 'u1' in values._p_.get_cached()
|
||||
assert 'u1' in settings._p_.get_cached()
|
||||
assert 'u2' in values._p_.get_cached()
|
||||
assert 'u2' in settings._p_.get_cached()
|
||||
|
||||
|
||||
def test_cache_not_cache():
|
||||
od1 = make_description()
|
||||
c = Config(od1)
|
||||
api = getapi(c)
|
||||
values = c.cfgimpl_get_values()
|
||||
settings = c.cfgimpl_get_settings()
|
||||
api.property.pop('cache')
|
||||
api.option('u1').value.get()
|
||||
assert 'u1' not in values._p_.get_cached()
|
||||
assert 'u1' not in settings._p_.get_cached()
|
||||
|
||||
|
||||
#def test_reset_cache_only():
|
||||
# od1 = make_description()
|
||||
# c = Config(od1)
|
||||
# api = getapi(c)
|
||||
# values = c.cfgimpl_get_values()
|
||||
# settings = c.cfgimpl_get_settings()
|
||||
# api.option('u1').value.get()
|
||||
# assert 'u1' in values._p_.get_cached()
|
||||
# assert 'u1' in settings._p_.get_cached()
|
||||
# c.cfgimpl_reset_cache(only=('values',))
|
||||
# assert 'u1' not in values._p_.get_cached()
|
||||
# assert 'u1' in settings._p_.get_cached()
|
||||
# api.option('u1').value.get()
|
||||
# assert 'u1' in values._p_.get_cached()
|
||||
# assert 'u1' in settings._p_.get_cached()
|
||||
# c.cfgimpl_reset_cache(only=('settings',))
|
||||
# assert 'u1' in values._p_.get_cached()
|
||||
# assert 'u1' not in settings._p_.get_cached()
|
||||
|
||||
|
||||
#def test_force_cache():
|
||||
# u1 = IntOption('u1', '', multi=True)
|
||||
# u2 = IntOption('u2', '')
|
||||
# u3 = IntOption('u3', '', multi=True)
|
||||
# u4 = IntOption('u4', '', properties=('disabled',))
|
||||
# od = OptionDescription('od1', '', [u1, u2, u3, u4])
|
||||
# c = Config(od)
|
||||
# api = getapi(c)
|
||||
# api.property.read_write()
|
||||
# api.property.pop('expire')
|
||||
# api.property.pop('disabled')
|
||||
#
|
||||
# c.cfgimpl_get_values().force_cache()
|
||||
# assert c.cfgimpl_get_values()._p_.get_cached() == {'u1': {None: ([], None)},
|
||||
# 'u2': {None: (None, None)},
|
||||
# 'u3': {None: ([], None)},
|
||||
# 'u4': {None: (None, None)}}
|
||||
# assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'u1': {None: (set(['empty']), None)},
|
||||
# 'u2': {None: (set([]), None)},
|
||||
# 'u3': {None: (set(['empty']), None)},
|
||||
# 'u4': {None: (set(['disabled']), None)}}
|
||||
# api.property.read_only()
|
||||
#
|
||||
# c.cfgimpl_get_values().force_cache()
|
||||
# assert c.cfgimpl_get_values()._p_.get_cached() == {'u1': {None: ([], None)},
|
||||
# 'u2': {None: (None, None)},
|
||||
# 'u3': {None: ([], None)}}
|
||||
# assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'empty', 'everything_frozen', 'frozen', 'mandatory', 'validator', 'warnings']), None)},
|
||||
# 'u1': {None: (set(['empty']), None)},
|
||||
# 'u2': {None: (set([]), None)},
|
||||
# 'u3': {None: (set(['empty']), None)},
|
||||
# 'u4': {None: (set(['disabled']), None)}}
|
||||
#
|
||||
# c.cfgimpl_get_settings().remove('cache')
|
||||
# raises(ConfigError, "c.cfgimpl_get_values().force_cache()")
|
||||
|
||||
|
||||
def test_cache_master_slave():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('toto', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
||||
cache = cfg.cfgimpl_get_values()._p_.get_cached()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0'])
|
||||
else:
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2']
|
||||
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None]
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
|
||||
cache = cfg.cfgimpl_get_settings()._p_.get_cached()
|
||||
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert set(cache['ip_admin_eth0'].keys()) == set([None])
|
||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None, 0])
|
||||
else:
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0])
|
||||
#
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.get()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()
|
||||
cache = cfg.cfgimpl_get_values()._p_.get_cached()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0'])
|
||||
else:
|
||||
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2', '192.168.1.1']
|
||||
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None, None]
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
|
||||
#assert cache['ip_admin_eth0.netmask_admin_eth0'][1][0] is None
|
||||
cache = cfg.cfgimpl_get_settings()._p_.get_cached()
|
||||
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert set(cache['ip_admin_eth0'].keys()) == set([None])
|
||||
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None, 0, 1])
|
||||
else:
|
||||
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0, 1])
|
||||
#DEL, insert, ...
|
||||
|
||||
|
||||
def return_value(value=None):
|
||||
return value
|
||||
|
||||
|
||||
def test_cache_callback():
|
||||
val1 = StrOption('val1', "", 'val')
|
||||
val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)}, properties=('mandatory',))
|
||||
val3 = StrOption('val3', "", callback=return_value, callback_params={'': ('yes',)})
|
||||
val4 = StrOption('val4', "", callback=return_value, callback_params={'value': ((val1, False),)})
|
||||
val5 = StrOption('val5', "", callback=return_value, callback_params={'value': ('yes',)}, multi=True)
|
||||
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
||||
cfg = Config(maconfig)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
api.property.pop('expire')
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('val', None)},
|
||||
'val2': {None: ('val', None)},
|
||||
'val3': {None: ('yes', None)},
|
||||
'val4': {None: ('val', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option('val1').value.set('new')
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val3': {None: ('yes', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('yes', None)},
|
||||
'val4': {None: ('new', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option('val3').value.set('new2')
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val4': {None: ('new', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('new2', None)},
|
||||
'val4': {None: ('new', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option('val4').value.set('new3')
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)},
|
||||
# 'val4': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('new2', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)},
|
||||
# 'val4': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('new2', None)},
|
||||
'val4': {None: ('new3', None)},
|
||||
'val5': {None: (['yes'], None)}}
|
||||
api.option('val5').value.set([undefined, 'new4'])
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)},
|
||||
# 'val4': {None: (set([]), None)},
|
||||
# 'val5': {None: (set(['empty']), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('new2', None)},
|
||||
'val4': {None: ('new3', None)}}
|
||||
api.option.make_dict()
|
||||
#assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)},
|
||||
# 'val3': {None: (set([]), None)},
|
||||
# 'val4': {None: (set([]), None)},
|
||||
# 'val5': {None: (set(['empty']), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1': {None: ('new', None)},
|
||||
'val2': {None: ('new', None)},
|
||||
'val3': {None: ('new2', None)},
|
||||
'val4': {None: ('new3', None)},
|
||||
'val5': {None: (['yes', 'new4'], None)}}
|
||||
|
||||
|
||||
def test_cache_master_and_slaves_master():
|
||||
val1 = StrOption('val1', "", multi=True)
|
||||
val2 = StrOption('val2', "", multi=True)
|
||||
interface1 = MasterSlaves('val1', '', [val1, val2])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
api.property.pop('expire')
|
||||
api.option.make_dict()
|
||||
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']
|
||||
val1_props = []
|
||||
val1_val1_props = ['empty']
|
||||
val1_val2_props = []
|
||||
if TIRAMISU_VERSION == 2:
|
||||
global_props = set(global_props)
|
||||
val1_props = set(val1_props)
|
||||
val1_val1_props = set(val1_val1_props)
|
||||
val1_val2_props = set(val1_val2_props)
|
||||
else:
|
||||
global_props = frozenset(global_props)
|
||||
val1_props = frozenset(val1_props)
|
||||
val1_val1_props = frozenset(val1_val1_props)
|
||||
val1_val2_props = frozenset(val1_val2_props)
|
||||
#None because no value
|
||||
idx_val2 = None
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
|
||||
'val1': {None: (val1_props, None)},
|
||||
'val1.val1': {None: (val1_val1_props, None)},
|
||||
'val1.val2': {idx_val2: (val1_val2_props, None)}}
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}, 'val1.val2': {None: ([], None)}}
|
||||
else:
|
||||
# len is 0 so don't get any value
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}}
|
||||
#
|
||||
api.option('val1.val1').value.set([undefined])
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
api.option.make_dict()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
val_val2 = [None]
|
||||
val_val2_props = {None: (set(), None), 0: (set(), None)}
|
||||
else:
|
||||
#has value
|
||||
idx_val2 = 0
|
||||
val_val2 = None
|
||||
val_val2_props = {idx_val2: (val1_val2_props, None)}
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
|
||||
'val1': {None: (val1_props, None)},
|
||||
'val1.val1': {None: (val1_val1_props, None)},
|
||||
'val1.val2': val_val2_props}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
|
||||
'val1.val2': {idx_val2: (val_val2, None)}}
|
||||
api.option('val1.val1').value.set([undefined, undefined])
|
||||
api.option.make_dict()
|
||||
api.option('val1.val2', 1).value.set('oui')
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'val1': {None: (set([]), None)}}
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
api.option.make_dict()
|
||||
if TIRAMISU_VERSION == 2:
|
||||
val1_val2_props = {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)}
|
||||
else:
|
||||
val1_val2_props = {0: (frozenset([]), None), 1: (frozenset([]), None)}
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
|
||||
'val1': {None: (val1_props, None)},
|
||||
'val1.val1': {None: (val1_val1_props, None)},
|
||||
'val1.val2': val1_val2_props}
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
|
||||
'val1.val2': {None: ([None, 'oui'], None)}}
|
||||
else:
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
|
||||
'val1.val2': {0: (None, None), 1: ('oui', None)}}
|
||||
|
||||
|
||||
def test_cache_master_callback():
|
||||
val1 = StrOption('val1', "", multi=True)
|
||||
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params={'value': ((val1, False),)})
|
||||
interface1 = MasterSlaves('val1', '', [val1, val2])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
api.property.pop('expire')
|
||||
api.option.make_dict()
|
||||
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']
|
||||
val1_props = []
|
||||
val1_val1_props = ['empty']
|
||||
val1_val2_props = []
|
||||
if TIRAMISU_VERSION == 2:
|
||||
global_props = set(global_props)
|
||||
val1_props = set(val1_props)
|
||||
val1_val1_props = set(val1_val1_props)
|
||||
val1_val2_props = set(val1_val2_props)
|
||||
else:
|
||||
global_props = frozenset(global_props)
|
||||
val1_props = frozenset(val1_props)
|
||||
val1_val1_props = frozenset(val1_val1_props)
|
||||
val1_val2_props = frozenset(val1_val2_props)
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
|
||||
'val1': {None: (val1_props, None)},
|
||||
'val1.val1': {None: (val1_val1_props, None)},
|
||||
'val1.val2': {None: (val1_val2_props, None)}}
|
||||
if TIRAMISU_VERSION == 2:
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}, 'val1.val2': {None: ([], None)}}
|
||||
else:
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([], None)}}
|
||||
api.option('val1.val1').value.set([undefined])
|
||||
assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'val1': {None: (set([]), None)}}
|
||||
|
||||
assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
api.option.make_dict()
|
||||
#FIXMEassert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'val1': {None: (set([]), None)}}
|
||||
#FIXMEassert cfg.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
|
||||
# 'val1.val2': {None: ([None], None)}
|
||||
# }
|
||||
|
||||
|
||||
#def test_cache_master_slave_different():
|
||||
# b = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
# c = StrOption('str', 'Test string option', multi=True)
|
||||
# d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True)
|
||||
# descr = MasterSlaves("int", "", [b, c, d])
|
||||
# #descr.impl_set_group_type(groups.master)
|
||||
# cfg = Config(descr)
|
||||
# api = getapi(cfg)
|
||||
# api.property.read_write()
|
||||
# api.property.pop('expire')
|
||||
# api.option.make_dict()
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'int': {None: ([0], None)},
|
||||
# 'str': {None: ([None], None)},
|
||||
# 'str1': {None: ([None], None)}}
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'int': {None: (set(['empty']), None)},
|
||||
# 'str': {None: (set([]), None), 0: (set([]), None)},
|
||||
# 'str1': {None: (set([]), None), 0: (set([]), None)}}
|
||||
# api.option('int').value.set([0, 1])
|
||||
# api.option.make_dict()
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'int': {None: ([0, 1], None)},
|
||||
# 'str': {None: ([None, None], None)},
|
||||
# 'str1': {None: ([None, None], None)}}
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'int': {None: (set(['empty']), None)},
|
||||
# 'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
||||
# 'str1': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)}}
|
||||
#
|
||||
# api.option('str', 1).value.set('1')
|
||||
# api.option.make_dict()
|
||||
# assert set(cfg.cfgimpl_get_values()._p_.get_cached().keys()) == set(['int', 'str', 'str1'])
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached()['int'] == {None: ([0, 1], None)}
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached()['str'] == {None: ([None, '1'], None)}
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][0][0] == None
|
||||
# raises(PropertiesOptionError, "cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][0][1]")
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached()['str1'][None][1] == None
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
# 'int': {None: (set(['empty']), None)},
|
||||
# 'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
||||
# 'str1': {None: (set([]), None), 0: (set([]), None), 1: (set(['hidden']), None)}}
|
||||
# api.property.read_only()
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
# api.option.make_dict()
|
||||
# assert cfg.cfgimpl_get_values()._p_.get_cached() == {'int': {None: ([0, 1], None)},
|
||||
# 'str': {None: ([None, '1'], None)},
|
||||
# 'str1': {None: ([None, None], None)}}
|
||||
# assert cfg.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'everything_frozen', 'validator', 'warnings', 'empty', 'mandatory', ]), None)},
|
||||
# 'int': {None: (set(['empty']), None)},
|
||||
# 'str': {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)},
|
||||
# 'str1': {None: (set([]), None), 0: (set([]), None), 1: (set(['hidden']), None)}}
|
||||
|
||||
|
||||
|
||||
def test_cache_requires():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.property.pop('expire')
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
|
||||
api.option.make_dict()
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)},
|
||||
'activate_service': {None: (True, None)}}
|
||||
api.option('ip_address_service').value.set('1.1.1.1')
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'activate_service': {None: (True, None)}}
|
||||
api.option.make_dict()
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: ('1.1.1.1', None)},
|
||||
'activate_service': {None: (True, None)}}
|
||||
api.option('activate_service').value.set(False)
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
api.option.make_dict()
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set(['disabled']), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'activate_service': {None: (False, None)}}
|
||||
|
||||
|
||||
def test_cache_global_properties():
|
||||
a = BoolOption('activate_service', '', True)
|
||||
b = IPOption('ip_address_service', '',
|
||||
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
|
||||
od = OptionDescription('service', '', [a, b])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.property.pop('expire')
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {}
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {}
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
assert c.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
|
||||
api.property.pop('disabled')
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
api.property.add('test')
|
||||
assert api.option('ip_address_service').value.get() == None
|
||||
assert c.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test']), None)},
|
||||
'activate_service': {None: (set([]), None)},
|
||||
'ip_address_service': {None: (set([]), None)}}
|
||||
|
||||
|
||||
def test_callback_value_incr():
|
||||
val1 = IntOption('val1', "", callback=return_incr)
|
||||
val2 = IntOption('val2', "", callback=return_value, callback_params={'value': ((val1, False),)})
|
||||
maconfig = OptionDescription('rootconfig', '', [val1, val2])
|
||||
cfg = Config(maconfig)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
assert api.option('val1').value.get() == 1
|
||||
sleep(1)
|
||||
assert api.option('val2').value.get() == 1
|
||||
sleep(1)
|
||||
assert api.option('val1').value.get() == 2
|
||||
assert api.option('val2').value.get() == 2
|
199
test/new_api/test_choice_option.py
Normal file
199
test/new_api/test_choice_option.py
Normal file
@ -0,0 +1,199 @@
|
||||
# coding: utf-8
|
||||
from py.test import raises
|
||||
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu.setting import owners
|
||||
from tiramisu.option import ChoiceOption, StrOption, OptionDescription
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.error import ConfigError
|
||||
from tiramisu import getapi, undefined
|
||||
|
||||
|
||||
def return_val(val):
|
||||
return val
|
||||
|
||||
|
||||
def return_list():
|
||||
return ['val1', 'val2']
|
||||
|
||||
|
||||
def return_calc_list(val):
|
||||
return [val]
|
||||
|
||||
|
||||
def return_error():
|
||||
raise Exception('test')
|
||||
|
||||
|
||||
def test_choiceoption():
|
||||
choice = ChoiceOption('choice', '', values=('val1', 'val2'))
|
||||
odesc = OptionDescription('od', '', [choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.get() == owners.default
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.set('val1')
|
||||
assert api.option('choice').owner.get() == owner
|
||||
assert not api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.get() == owners.default
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.get() == owners.default
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
assert api.option('choice').value.list() == ('val1', 'val2')
|
||||
|
||||
|
||||
def test_choiceoption_function():
|
||||
choice = ChoiceOption('choice', '', values=return_list)
|
||||
odesc = OptionDescription('od', '', [choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.set('val1')
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
assert api.option('choice').value.list() == ['val1', 'val2']
|
||||
|
||||
|
||||
def test_choiceoption_function_error():
|
||||
choice = ChoiceOption('choice', '', values=return_error)
|
||||
odesc = OptionDescription('od', '', [choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
raises(ConfigError, "api.option('choice').value.set('val1')")
|
||||
|
||||
|
||||
def test_choiceoption_calc_function():
|
||||
choice = ChoiceOption('choice', "", values=return_calc_list, values_params={'': ('val1',)})
|
||||
odesc = OptionDescription('od', '', [choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.set('val1')
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.isdefault()
|
||||
|
||||
|
||||
def test_choiceoption_calc_opt_function():
|
||||
str_ = StrOption('str', '', 'val1')
|
||||
choice = ChoiceOption('choice',
|
||||
"",
|
||||
values=return_calc_list,
|
||||
values_params={'': ((str_, False),)})
|
||||
odesc = OptionDescription('od', '', [str_, choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
api.option('choice').value.set('val1')
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.isdefault()
|
||||
|
||||
|
||||
def test_choiceoption_calc_opt_function_propertyerror():
|
||||
str_ = StrOption('str', '', 'val1', properties=('disabled',))
|
||||
choice = ChoiceOption('choice',
|
||||
"",
|
||||
values=return_calc_list,
|
||||
values_params={'': ((str_, False),)})
|
||||
odesc = OptionDescription('od', '', [str_, choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
raises(ConfigError, "api.option('choice').value.set('no')")
|
||||
|
||||
|
||||
def test_choiceoption_calc_opt_multi_function():
|
||||
str_ = StrOption('str', '', ['val1'], multi=True)
|
||||
choice = ChoiceOption('choice',
|
||||
"",
|
||||
default_multi='val2',
|
||||
values=return_val,
|
||||
values_params={'': ((str_, False),)},
|
||||
multi=True)
|
||||
ch2 = ChoiceOption('ch2',
|
||||
"",
|
||||
default=['val2'],
|
||||
values=return_val,
|
||||
values_params={'': ((str_, False),)},
|
||||
multi=True)
|
||||
odesc = OptionDescription('od', '', [str_, choice, ch2])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
owner = api.owner.get()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
assert api.option('choice').value.get() == []
|
||||
#
|
||||
api.option('choice').value.set(['val1'])
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set([undefined])")
|
||||
#
|
||||
api.option('choice').value.set(['val1'])
|
||||
assert api.option('choice').owner.get() == owner
|
||||
#
|
||||
api.option('choice').value.reset()
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('choice').value.set('no')")
|
||||
assert api.option('choice').owner.isdefault()
|
||||
#
|
||||
raises(ValueError, "api.option('ch2').value.get()")
|
||||
|
||||
|
||||
def test_choiceoption_calc_invalid():
|
||||
str_ = StrOption('str', '', ['val1'], multi=True)
|
||||
str_
|
||||
raises(ValueError,
|
||||
"choice = ChoiceOption('choice', '', default_multi='val2', values=[1, 2, 3], \
|
||||
values_params={'': ((str_, False),)}, multi=True)")
|
||||
|
||||
|
||||
def test_choiceoption_calc_not_list():
|
||||
str_ = StrOption('str', '', 'val1')
|
||||
choice = ChoiceOption('choice',
|
||||
"",
|
||||
default_multi='val2',
|
||||
values=return_val,
|
||||
values_params={'': ((str_, False),)},
|
||||
multi=True)
|
||||
odesc = OptionDescription('od', '', [str_, choice])
|
||||
cfg = Config(odesc)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
raises(ConfigError, "api.option('choice').value.set(['val1'])")
|
403
test/new_api/test_config.py
Normal file
403
test/new_api/test_config.py
Normal file
@ -0,0 +1,403 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""theses tests are much more to test that config, option description, vs...
|
||||
**it's there** and answers via attribute access"""
|
||||
from py.test import raises
|
||||
import weakref
|
||||
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu.config import Config, SubConfig
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, UnicodeOption, OptionDescription, getapi, undefined
|
||||
from tiramisu.error import ConflictError, ConfigError, PropertiesOptionError, APIError
|
||||
|
||||
|
||||
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, properties=('hidden',))
|
||||
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():
|
||||
"""making a :class:`tiramisu.config.Config()` object
|
||||
and a :class:`tiramisu.option.OptionDescription()` object
|
||||
"""
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
api = getapi(cfg)
|
||||
assert api.option('dummy').value.get() is False
|
||||
dmo = cfg.unwrap_from_path('dummy')
|
||||
assert dmo.impl_getname() == 'dummy'
|
||||
|
||||
|
||||
def test_base_config_name():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr, session_id='cfg')
|
||||
cfg.impl_getname() == 'cfg'
|
||||
raises(ValueError, "Config(descr, session_id='unvalid name')")
|
||||
|
||||
|
||||
def test_not_config():
|
||||
assert raises(TypeError, "Config('str')")
|
||||
|
||||
|
||||
def test_base_path():
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
descr = OptionDescription('tiramisu', '', [gcdummy])
|
||||
cfg = Config(descr)
|
||||
assert cfg._impl_path is None
|
||||
base = OptionDescription('config', '', [descr])
|
||||
cfg = Config(base)
|
||||
assert cfg._impl_path is None
|
||||
assert cfg.getattr('tiramisu', None, validate_properties=False)._impl_path == 'tiramisu'
|
||||
nbase = OptionDescription('baseconfig', '', [base])
|
||||
cfg = Config(nbase)
|
||||
assert cfg._impl_path is None
|
||||
assert cfg.getattr('config', None, validate_properties=False)._impl_path == 'config'
|
||||
assert cfg.getattr('config.tiramisu', None, validate_properties=False)._impl_path == 'config.tiramisu'
|
||||
|
||||
|
||||
def test_base_config_force_permissive():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
api.property.read_write()
|
||||
api.permissive.set(('hidden',))
|
||||
raises(PropertiesOptionError, "api.option('boolop').value.get()")
|
||||
assert api.forcepermissive.option('boolop').value.get() is True
|
||||
|
||||
|
||||
def test_base_config_in_a_tree():
|
||||
"how options are organized into a tree, see :ref:`tree`"
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
#
|
||||
api.option('bool').value.set(False)
|
||||
#
|
||||
assert api.option('gc.name').value.get() == 'ref'
|
||||
api.option('gc.name').value.set('framework')
|
||||
assert api.option('gc.name').value.get() == 'framework'
|
||||
#
|
||||
assert api.option('objspace').value.get() == 'std'
|
||||
api.option('objspace').value.set('thunk')
|
||||
assert api.option('objspace').value.get() == 'thunk'
|
||||
#
|
||||
assert api.option('gc.float').value.get() == 2.3
|
||||
api.option('gc.float').value.set(3.4)
|
||||
assert api.option('gc.float').value.get() == 3.4
|
||||
#
|
||||
assert api.option('int').value.get() == 0
|
||||
api.option('int').value.set(123)
|
||||
assert api.option('int').value.get() == 123
|
||||
#
|
||||
assert api.option('wantref').value.get() is False
|
||||
api.option('wantref').value.set(True)
|
||||
assert api.option('wantref').value.get() is True
|
||||
#
|
||||
assert api.option('str').value.get() == 'abc'
|
||||
api.option('str').value.set('def')
|
||||
assert api.option('str').value.get() == 'def'
|
||||
#
|
||||
raises(AttributeError, "api.option('gc.foo').value.get()")
|
||||
##
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
assert api.option('bool').value.get() is True
|
||||
assert api.option('gc.name').value.get() == 'ref'
|
||||
assert api.option('wantframework').value.get() is False
|
||||
|
||||
|
||||
def test_cfgimpl_get_home_by_path():
|
||||
" :meth:`tiramisu.config.SubConfig.cfgimpl_get_home_by_path()` to retrieve a path"
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
api.option('bool').value.set(False)
|
||||
assert config.cfgimpl_get_home_by_path('gc.dummy', None)[1] == 'dummy'
|
||||
assert config.cfgimpl_get_home_by_path('dummy', None)[1] == 'dummy'
|
||||
|
||||
|
||||
def test_not_valid_properties():
|
||||
raises(TypeError, "stroption = StrOption('str', 'Test string option', default='abc', properties=['mandatory',])")
|
||||
|
||||
|
||||
def test_information_config():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
string = 'some informations'
|
||||
#
|
||||
api.information.set('info', string)
|
||||
assert api.information.get('info') == string
|
||||
#
|
||||
raises(ValueError, "api.information.get('noinfo')")
|
||||
assert api.information.get('noinfo', 'default') == 'default'
|
||||
api.information.reset('info')
|
||||
raises(ValueError, "api.information.get('info')")
|
||||
raises(ValueError, "api.information.reset('noinfo')")
|
||||
|
||||
|
||||
def test_config_impl_get_path_by_opt():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
dummy = api.option.get('gc.dummy')
|
||||
boo = api.option.get('bool')
|
||||
unknown = IntOption('test', '')
|
||||
unknown
|
||||
assert config.cfgimpl_get_description().impl_get_path_by_opt(boo) == 'bool'
|
||||
assert config.cfgimpl_get_description().impl_get_path_by_opt(dummy) == 'gc.dummy'
|
||||
raises(AttributeError, "config.cfgimpl_get_description().impl_get_path_by_opt(unknown)")
|
||||
|
||||
|
||||
def test_config_impl_get_path_by_opt_od():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
dummy = api.option.get('gc.dummy')
|
||||
dummy
|
||||
raises(ConfigError, "config.getattr('gc', None).cfgimpl_get_description().impl_get_path_by_opt(dummy)")
|
||||
|
||||
|
||||
def test_config_impl_get_opt_by_path():
|
||||
descr = make_description()
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
dummy = api.option.get('gc.dummy')
|
||||
boo = api.option.get('bool')
|
||||
assert config.cfgimpl_get_description().impl_get_opt_by_path('bool') == boo
|
||||
assert config.cfgimpl_get_description().impl_get_opt_by_path('gc.dummy') == dummy
|
||||
raises(AttributeError, "config.cfgimpl_get_description().impl_get_opt_by_path('gc.unknown')")
|
||||
raises(ConfigError, "config.getattr('gc', None).cfgimpl_get_description().impl_get_opt_by_path('gc.unknown')")
|
||||
|
||||
|
||||
#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)
|
||||
# assert str(config.od) == """g1 = 1
|
||||
#g2 = héhé
|
||||
#g3 = héhé
|
||||
#g4 = True
|
||||
#g5 = None"""
|
||||
# assert str(config) == '[od]'
|
||||
|
||||
|
||||
def test_get_modified_values():
|
||||
g1 = IntOption('g1', '', 1)
|
||||
g2 = StrOption('g2', '', 'héhé')
|
||||
g3 = UnicodeOption('g3', '', u'héhé')
|
||||
g4 = BoolOption('g4', '', True)
|
||||
g5 = StrOption('g5', '')
|
||||
g6 = StrOption('g6', '', multi=True)
|
||||
d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5, g6])
|
||||
root = OptionDescription('root', '', [d1])
|
||||
config = Config(root)
|
||||
api = getapi(config)
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {}
|
||||
api.option('od.g5').value.set('yes')
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes')}
|
||||
api.option('od.g4').value.set(True)
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g4': ('user', True)}
|
||||
api.option('od.g4').value.reset()
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes')}
|
||||
api.option('od.g6').value.set([undefined])
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', (None,))}
|
||||
api.option('od.g6').value.set([])
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', tuple())}
|
||||
api.option('od.g6').value.set(['3'])
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', ('3',))}
|
||||
api.option('od.g6').value.set([])
|
||||
assert config.cfgimpl_get_values().get_modified_values() == {'od.g5': ('user', 'yes'), 'od.g6': ('user', tuple())}
|
||||
|
||||
|
||||
#def test_has_value():
|
||||
# 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)
|
||||
# api = getapi(config)
|
||||
# assert not g5 in config.cfgimpl_get_values()
|
||||
# api.option('od.g5').value.set('yes')
|
||||
# assert g5 in config.cfgimpl_get_values()
|
||||
|
||||
|
||||
#def test_values_not_setitem():
|
||||
# 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)
|
||||
# config
|
||||
# raises(ConfigError, "config.cfgimpl_get_values()[g1] = 2")
|
||||
|
||||
|
||||
def test_duplicated_option():
|
||||
g1 = IntOption('g1', '', 1)
|
||||
g1
|
||||
#in same OptionDescription
|
||||
raises(ConflictError, "d1 = OptionDescription('od', '', [g1, g1])")
|
||||
|
||||
|
||||
def test_duplicated_option_diff_od():
|
||||
g1 = IntOption('g1', '', 1)
|
||||
d1 = OptionDescription('od1', '', [g1])
|
||||
#in different OptionDescription
|
||||
d2 = OptionDescription('od2', '', [g1, d1])
|
||||
d2
|
||||
raises(ConflictError, 'Config(d2)')
|
||||
|
||||
|
||||
def test_cannot_assign_value_to_option_description():
|
||||
descr = make_description()
|
||||
cfg = Config(descr)
|
||||
api = getapi(cfg)
|
||||
api
|
||||
raises(APIError, "api.option('gc').value.set(3)")
|
||||
|
||||
|
||||
def test_config_multi():
|
||||
i1 = IntOption('test1', '', multi=True)
|
||||
i2 = IntOption('test2', '', multi=True, default_multi=1)
|
||||
i3 = IntOption('test3', '', default=[2], multi=True, default_multi=1)
|
||||
od = OptionDescription('test', '', [i1, i2, i3])
|
||||
config = Config(od)
|
||||
api = getapi(config)
|
||||
assert api.option('test1').value.get() == []
|
||||
assert api.option('test2').value.get() == []
|
||||
api.option('test2').value.set([undefined])
|
||||
assert api.option('test2').value.get() == [1]
|
||||
assert api.option('test3').value.get() == [2]
|
||||
api.option('test3').value.set([undefined, undefined])
|
||||
assert api.option('test3').value.get() == [2, 1]
|
||||
|
||||
|
||||
def test_no_validation():
|
||||
i1 = IntOption('test1', '')
|
||||
od = OptionDescription('test', '', [i1])
|
||||
cfg = Config(od)
|
||||
api = getapi(cfg)
|
||||
api.property.read_write()
|
||||
api.option('test1').value.set(1)
|
||||
raises(ValueError, "api.option('test1').value.set('yes')")
|
||||
assert api.option('test1').value.get() == 1
|
||||
api.property.pop('validator')
|
||||
api.option('test1').value.set('yes')
|
||||
assert api.option('test1').value.get() == 'yes'
|
||||
api.property.add('validator')
|
||||
raises(ValueError, "api.option('test1').value.get()")
|
||||
api.option('test1').value.reset()
|
||||
assert api.option('test1').value.get() is None
|
||||
|
||||
|
||||
#def test_delete_config_with_subconfig():
|
||||
# test = IntOption('test', '')
|
||||
# multi = IntOption('multi', '', multi=True)
|
||||
# od = OptionDescription('od', '', [test, multi])
|
||||
# odroot = OptionDescription('odroot', '', [od])
|
||||
# cfg = Config(odroot)
|
||||
# api = getapi(cfg)
|
||||
# sub = cfg.od
|
||||
# val = cfg.cfgimpl_get_values()
|
||||
# setting = cfg.cfgimpl_get_settings()
|
||||
# assert api.option('od.test').value.get() is None
|
||||
# assert api.option('od.multi').value.get() == []
|
||||
# api.config.make_dict()
|
||||
# del(api)
|
||||
# del(cfg)
|
||||
# raises(ConfigError, 'val[test]')
|
||||
# raises(ConfigError, 'val[multi]')
|
||||
# raises(ConfigError, 'setting[test]')
|
||||
# raises(ConfigError, 'sub.make_dict()')
|
||||
|
||||
|
||||
def test_subconfig():
|
||||
i = IntOption('i', '')
|
||||
o = OptionDescription('val', '', [i])
|
||||
o2 = OptionDescription('val', '', [o])
|
||||
c = Config(o2)
|
||||
c
|
||||
raises(TypeError, "SubConfig(i, weakref.ref(c))")
|
||||
|
||||
|
||||
#def test_config_weakref():
|
||||
# o = OptionDescription('val', '', [])
|
||||
# o2 = OptionDescription('val', '', [o])
|
||||
# c = Config(o2)
|
||||
# SubConfig(o, weakref.ref(c))
|
||||
# raises(ValueError, "SubConfig(o, c)")
|
||||
# s = SubConfig(o, weakref.ref(c))
|
||||
# assert s._cfgimpl_get_context() == c
|
||||
# del(c)
|
||||
# raises(ConfigError, "s._cfgimpl_get_context()")
|
||||
|
||||
|
||||
#def test_config_str():
|
||||
# gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
# gcdummy1 = BoolOption('dummy1', 'dummy', default=False, properties=('disabled',))
|
||||
# o = OptionDescription('o', '', [gcdummy, gcdummy1])
|
||||
# descr = OptionDescription('tiramisu', '', [o])
|
||||
# cfg = Config(descr)
|
||||
# api = getapi(cfg)
|
||||
# api.property.read_only()
|
||||
# str(cfg)
|
||||
# str(cfg.o)
|
||||
|
||||
|
||||
#def test_config_od_function():
|
||||
# gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
# gcdummy1 = BoolOption('dummy1', 'dummy', default=False, properties=('disabled',))
|
||||
# o = OptionDescription('o', '', [gcdummy, gcdummy1])
|
||||
# descr = OptionDescription('tiramisu', '', [o])
|
||||
# cfg = Config(descr)
|
||||
# try:
|
||||
# print(cfg.impl_get_opt_by_path())
|
||||
# except AttributeError as err:
|
||||
# assert str(err) == _('unknown Option {0} in OptionDescription {1}'
|
||||
# '').format('impl_get_opt_by_path', descr.impl_getname())
|
||||
|
||||
|
||||
def test_config_subconfig():
|
||||
i1 = IntOption('i1', '')
|
||||
i2 = IntOption('i2', '', default=1)
|
||||
i3 = IntOption('i3', '')
|
||||
i4 = IntOption('i4', '', default=2)
|
||||
od1 = OptionDescription('od1', '', [i1, i2, i3, i4])
|
||||
od2 = OptionDescription('od2', '', [od1])
|
||||
conf1 = Config(od2, session_id='conf1')
|
||||
api = getapi(conf1)
|
||||
raises(ConfigError, "conf2 = Config(od1, session_id='conf2')")
|
387
test/new_api/test_config_api.py
Normal file
387
test/new_api/test_config_api.py
Normal file
@ -0,0 +1,387 @@
|
||||
"configuration objects global API"
|
||||
from py.test import raises
|
||||
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \
|
||||
BoolOption, FilenameOption, UnicodeOption, SymLinkOption, IPOption, \
|
||||
PortOption, NetworkOption, NetmaskOption, BroadcastOption, \
|
||||
DomainnameOption, OptionDescription, getapi
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
prop = BoolOption('prop', '', properties=('disabled',))
|
||||
prop2 = BoolOption('prop', '', properties=('hidden',))
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
booloption2 = BoolOption('bool', 'Test boolean option', default=False)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
floatoption2 = FloatOption('float', 'Test float option', default=2.3)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Tests', default=False)
|
||||
wantframework_option = BoolOption('wantframework', 'Test', default=False)
|
||||
gcgroup2 = OptionDescription('gc2', '', [booloption2, prop])
|
||||
gcgroup = OptionDescription('gc', '', [gcgroup2, gcoption, gcdummy, floatoption, prop2])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop, floatoption2])
|
||||
return descr
|
||||
|
||||
|
||||
def _is_same_opt(opt1, opt2):
|
||||
if "id" in dir(opt1):
|
||||
assert opt1.id == opt2.id
|
||||
else:
|
||||
assert opt1 == opt2
|
||||
|
||||
|
||||
#def test_iter_config():
|
||||
# "iteration on config object"
|
||||
# s = StrOption("string", "", default="string")
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# descr = OptionDescription("options", "", [s, s2])
|
||||
# config = Config(descr)
|
||||
# assert [(name, value) for name, value in config] == \
|
||||
# [('string', 'string'), ('string2', 'string2')]
|
||||
#
|
||||
#
|
||||
#def test_iter_config_property():
|
||||
# "iteration on config object"
|
||||
# s = StrOption("string", "", default="string", properties=('disabled',))
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# descr = OptionDescription("options", "", [s, s2])
|
||||
# config = Config(descr)
|
||||
# config.read_only()
|
||||
# assert [(name, value) for name, value in config] == \
|
||||
# [('string2', 'string2')]
|
||||
#
|
||||
#
|
||||
#def test_iter_subconfig():
|
||||
# "iteration on config sub object"
|
||||
# descr = make_description()
|
||||
# conf = Config(descr)
|
||||
# for (name, value), (gname, gvalue) in \
|
||||
# zip(conf.gc, [("name", "ref"), ("dummy", False)]):
|
||||
# assert name == gname
|
||||
# assert value == gvalue
|
||||
|
||||
|
||||
def test_str():
|
||||
descr = make_description()
|
||||
c = Config(descr)
|
||||
c # does not crash
|
||||
|
||||
|
||||
def test_make_dict():
|
||||
"serialization of the whole config to a dict"
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False, properties=('hidden',))]),
|
||||
IntOption("int", "", default=42)])
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
api.property.read_write()
|
||||
api.permissive.set(('hidden',))
|
||||
d = api.option.make_dict()
|
||||
assert d == {"s1.a": False, "int": 42}
|
||||
api.option('int').value.set(43)
|
||||
api.option('s1.a').value.set(True)
|
||||
d = api.option.make_dict()
|
||||
assert d == {"s1.a": True, "int": 43}
|
||||
d2 = api.option.make_dict(flatten=True)
|
||||
assert d2 == {'a': True, 'int': 43}
|
||||
raises(ValueError, 'd2 = api.option.make_dict(withvalue="3")')
|
||||
d = api.forcepermissive.option.make_dict()
|
||||
assert d == {"s1.a": True, "s1.b": False, "int": 43}
|
||||
|
||||
|
||||
def test_make_dict_with_disabled():
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False, properties=('disabled',))]),
|
||||
OptionDescription("s2", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False)], properties=('disabled',)),
|
||||
IntOption("int", "", default=42)])
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
api.property.read_only()
|
||||
d = api.option.make_dict()
|
||||
assert d == {"s1.a": False, "int": 42}
|
||||
|
||||
|
||||
def test_make_dict_with_disabled_in_callback():
|
||||
descr = OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False, properties=('disabled',))]),
|
||||
OptionDescription("s2", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False)], properties=('disabled',)),
|
||||
IntOption("int", "", default=42)])
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
api.property.read_only()
|
||||
d = api.option.make_dict()
|
||||
assert d == {"s1.a": False, "int": 42}
|
||||
|
||||
|
||||
def test_make_dict_fullpath():
|
||||
descr = OptionDescription("root", "", [
|
||||
OptionDescription("opt", "", [
|
||||
OptionDescription("s1", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False, properties=('disabled',))]),
|
||||
OptionDescription("s2", "", [
|
||||
BoolOption("a", "", default=False),
|
||||
BoolOption("b", "", default=False)], properties=('disabled',)),
|
||||
IntOption("int", "", default=42)]),
|
||||
IntOption("introot", "", default=42)])
|
||||
config = Config(descr)
|
||||
api = getapi(config)
|
||||
api.property.read_only()
|
||||
assert api.option.make_dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
|
||||
assert api.option('opt').make_dict() == {"s1.a": False, "int": 42}
|
||||
assert api.option.make_dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
|
||||
assert api.option('opt').make_dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42}
|
||||
|
||||
|
||||
def test_find_in_config():
|
||||
"finds option in config"
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
api = getapi(conf)
|
||||
api.property.read_only()
|
||||
api.permissive.set(('hidden',))
|
||||
ret = api.option.find('dummy')
|
||||
assert len(ret) == 1
|
||||
_is_same_opt(ret[0], api.option.get('gc.dummy'))
|
||||
#
|
||||
ret = api.option.find_first('dummy')
|
||||
_is_same_opt(ret, api.option.get('gc.dummy'))
|
||||
#
|
||||
ret = api.option.find('float')
|
||||
assert len(ret) == 2
|
||||
_is_same_opt(ret[0], api.option.get('gc.float'))
|
||||
_is_same_opt(ret[1], api.option.get('float'))
|
||||
#
|
||||
_is_same_opt(api.option.find_first('bool'), api.option.get('gc.gc2.bool'))
|
||||
#_is_same_opt(conf.find_first(byname='bool', byvalue=True), conf.unwrap_from_path('bool'))
|
||||
#_is_same_opt(conf.find_first(byname='dummy'), conf.unwrap_from_path('gc.dummy'))
|
||||
#_is_same_opt(conf.find_first(byname='float'), conf.unwrap_from_path('gc.float'))
|
||||
#ret = conf.find(bytype=ChoiceOption)
|
||||
#assert len(ret) == 2
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.name'))
|
||||
#_is_same_opt(ret[1], conf.unwrap_from_path('objspace'))
|
||||
#_is_same_opt(conf.find_first(bytype=ChoiceOption), conf.unwrap_from_path('gc.name'))
|
||||
#ret = conf.find(byvalue='ref')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.name'))
|
||||
#_is_same_opt(conf.find_first(byvalue='ref'), conf.unwrap_from_path('gc.name'))
|
||||
#ret = conf.find(byname='prop')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.prop'))
|
||||
#conf.read_write()
|
||||
#raises(AttributeError, "assert conf.find(byname='prop')")
|
||||
#ret = conf.find(byname='prop', check_properties=False)
|
||||
#assert len(ret) == 2
|
||||
#_is_same_opt(ret[0], conf.cfgimpl_get_description().impl_get_opt_by_path('gc.gc2.prop'))
|
||||
#_is_same_opt(ret[1], conf.unwrap_from_path('gc.prop', force_permissive=True))
|
||||
#ret = conf.find(byname='prop', force_permissive=True)
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.prop', force_permissive=True))
|
||||
#_is_same_opt(conf.find_first(byname='prop', force_permissive=True), conf.unwrap_from_path('gc.prop', force_permissive=True))
|
||||
##assert conf.find_first(byname='prop') == conf.unwrap_from_path('gc.prop')
|
||||
## combinaison of filters
|
||||
#ret = conf.find(bytype=BoolOption, byname='dummy')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.dummy'))
|
||||
#_is_same_opt(conf.find_first(bytype=BoolOption, byname='dummy'), conf.unwrap_from_path('gc.dummy'))
|
||||
#ret = conf.find(byvalue=False, byname='dummy')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.dummy'))
|
||||
#_is_same_opt(conf.find_first(byvalue=False, byname='dummy'), conf.unwrap_from_path('gc.dummy'))
|
||||
##subconfig
|
||||
#ret = conf.gc.find(byname='dummy')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.dummy'))
|
||||
#ret = conf.gc.find(byname='float')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.float'))
|
||||
#ret = conf.gc.find(byname='bool')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.gc2.bool'))
|
||||
#_is_same_opt(conf.gc.find_first(byname='bool', byvalue=False), conf.unwrap_from_path('gc.gc2.bool'))
|
||||
#raises(AttributeError, "assert conf.gc.find_first(byname='bool', byvalue=True)")
|
||||
#raises(AttributeError, "conf.gc.find(byname='wantref').first()")
|
||||
#ret = conf.gc.find(byname='prop', check_properties=False)
|
||||
#assert len(ret) == 2
|
||||
#_is_same_opt(ret[0], conf.cfgimpl_get_description().impl_get_opt_by_path('gc.gc2.prop'))
|
||||
#_is_same_opt(ret[1], conf.unwrap_from_path('gc.prop', force_permissive=True))
|
||||
#conf.read_only()
|
||||
#ret = conf.gc.find(byname='prop')
|
||||
#assert len(ret) == 1
|
||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.prop'))
|
||||
## not OptionDescription
|
||||
#raises(AttributeError, "conf.find_first(byname='gc')")
|
||||
#raises(AttributeError, "conf.gc.find_first(byname='gc2')")
|
||||
#raises(ValueError, "conf.find(byname='bool', type_='unknown')")
|
||||
|
||||
|
||||
#def test_find_multi():
|
||||
# b = BoolOption('bool', '', multi=True)
|
||||
# o = OptionDescription('od', '', [b])
|
||||
# conf = Config(o)
|
||||
# raises(AttributeError, "conf.find(byvalue=True)")
|
||||
# raises(AttributeError, "conf.find_first(byvalue=True)")
|
||||
# conf.bool.append(False)
|
||||
# raises(AttributeError, "conf.find(byvalue=True)")
|
||||
# raises(AttributeError, "conf.find_first(byvalue=True)")
|
||||
# conf.bool.append(False)
|
||||
# raises(AttributeError, "conf.find(byvalue=True)")
|
||||
# raises(AttributeError, "conf.find_first(byvalue=True)")
|
||||
# conf.bool.append(True)
|
||||
# ret = conf.find(byvalue=True)
|
||||
# assert len(ret) == 1
|
||||
# _is_same_opt(ret[0], b)
|
||||
# _is_same_opt(conf.find_first(byvalue=True), b)
|
||||
|
||||
|
||||
def test_does_not_find_in_config():
|
||||
descr = make_description()
|
||||
conf = Config(descr)
|
||||
api = getapi(conf)
|
||||
api
|
||||
raises(AttributeError, "api.option.find('IDontExist')")
|
||||
|
||||
|
||||
def test_filename():
|
||||
a = FilenameOption('a', '')
|
||||
o = OptionDescription('o', '', [a])
|
||||
cfg = Config(o)
|
||||
api = getapi(cfg)
|
||||
api.option('a').value.set('/')
|
||||
api.option('a').value.set('/tmp')
|
||||
api.option('a').value.set('/tmp/')
|
||||
api.option('a').value.set('/tmp/text.txt')
|
||||
api.option('a').value.set('tmp')
|
||||
api.option('a').value.set('tmp/')
|
||||
api.option('a').value.set('tmp/text.txt')
|
||||
raises(ValueError, "api.option('a').value.set('/tmp/with space.txt')")
|
||||
raises(ValueError, "api.option('a').value.set('/tmp/with$.txt')")
|
||||
|
||||
|
||||
#def test_iter_all():
|
||||
# s = StrOption("string", "", default="string")
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# descr = OptionDescription("options", "", [s, s2])
|
||||
# config = Config(descr)
|
||||
# assert list(config.iter_all()) == [('string', 'string'), ('string2', 'string2')]
|
||||
# for i in config.iter_all():
|
||||
# #test StopIteration
|
||||
# break
|
||||
#
|
||||
#
|
||||
#def test_iter_all_force_permissive():
|
||||
# s = StrOption("string", "", default="string")
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# s3 = StrOption("string3", "", default="string3", properties=('hidden',))
|
||||
# descr = OptionDescription("options", "", [s, s2, s3])
|
||||
# config = Config(descr)
|
||||
# api = getapi(config)
|
||||
# api.property.read_write()
|
||||
# api.permissive.set(('hidden',))
|
||||
# assert list(config.iter_all()) == [('string', 'string'), ('string2', 'string2')]
|
||||
# assert list(config.iter_all(force_permissive=True)) == [('string', 'string'),
|
||||
# ('string2', 'string2'),
|
||||
# ('string3', 'string3')]
|
||||
#
|
||||
#
|
||||
#def test_iter_all_prop():
|
||||
# s = StrOption("string", "", default="string", properties=('disabled',))
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# descr = OptionDescription("options", "", [s, s2])
|
||||
# config = Config(descr)
|
||||
# api = getapi(config)
|
||||
# api.property.read_only()
|
||||
# assert list(config.iter_all()) == [('string2', 'string2')]
|
||||
|
||||
|
||||
#def test_impl_getpaths():
|
||||
# s = StrOption("string", "", default="string", properties=('disabled',))
|
||||
# s2 = StrOption("string2", "", default="string2")
|
||||
# s3 = StrOption("string3", "", default="string3")
|
||||
# s4 = StrOption("string4", "", default="string4", properties=('hidden',))
|
||||
# od = OptionDescription('od', '', [s3, s4])
|
||||
# descr = OptionDescription("options", "", [s, s2, od])
|
||||
# config = Config(descr)
|
||||
# assert ['string', 'string2', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths()
|
||||
# assert ['string', 'string2', 'od', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths(include_groups=True)
|
||||
# config.read_write()
|
||||
# raises(PropertiesOptionError, "config.od.string4")
|
||||
# assert ['string', 'string2', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths()
|
||||
# assert ['string', 'string2', 'od', 'od.string3', 'od.string4'] == config.cfgimpl_get_description().impl_getpaths(include_groups=True)
|
||||
|
||||
|
||||
def test_invalid_option():
|
||||
ChoiceOption('a', '', ('1', '2'))
|
||||
raises(TypeError, "ChoiceOption('a', '', [1, 2])")
|
||||
raises(TypeError, "ChoiceOption('a', '', 1)")
|
||||
raises(ValueError, "ChoiceOption('a', '', (1,), 3)")
|
||||
FloatOption('a', '')
|
||||
raises(ValueError, "FloatOption('a', '', 'string')")
|
||||
UnicodeOption('a', '')
|
||||
raises(ValueError, "UnicodeOption('a', '', 1)")
|
||||
u = UnicodeOption('a', '')
|
||||
SymLinkOption('a', u)
|
||||
raises(ValueError, "SymLinkOption('a', 'string')")
|
||||
IPOption('a', '')
|
||||
raises(ValueError, "IPOption('a', '', 1)")
|
||||
raises(ValueError, "IPOption('a', '', 'string')")
|
||||
PortOption('a', '')
|
||||
raises(ValueError, "PortOption('a', '', 'string')")
|
||||
raises(ValueError, "PortOption('a', '', '11:12:13', allow_range=True)")
|
||||
raises(ValueError, "PortOption('a', '', 11111111111111111111)")
|
||||
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=False)")
|
||||
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=True, allow_registred=False, allow_private=True)")
|
||||
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=False, allow_private=True)")
|
||||
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=True)")
|
||||
raises(ValueError, "PortOption('a', '', allow_zero=False, allow_wellknown=False, allow_registred=False, allow_private=False)")
|
||||
NetworkOption('a', '')
|
||||
raises(ValueError, "NetworkOption('a', '', 'string')")
|
||||
NetmaskOption('a', '')
|
||||
raises(ValueError, "NetmaskOption('a', '', 'string')")
|
||||
BroadcastOption('a', '')
|
||||
raises(ValueError, "BroadcastOption('a', '', 'string')")
|
||||
DomainnameOption('a', '')
|
||||
raises(ValueError, "DomainnameOption('a', '', 'string')")
|
||||
raises(ValueError, "DomainnameOption('a', '', type_='string')")
|
||||
raises(ValueError, "DomainnameOption('a', '', allow_ip='string')")
|
||||
raises(ValueError, "DomainnameOption('a', '', allow_without_dot='string')")
|
||||
raises(ValueError, "DomainnameOption('a', '', 1)")
|
||||
#
|
||||
ChoiceOption('a', '', (1,), multi=True, default_multi=1)
|
||||
raises(ValueError, "ChoiceOption('a', '', (1,), default_multi=1)")
|
||||
raises(ValueError, "ChoiceOption('a', '', (1,), multi=True, default=[1,], default_multi=2)")
|
||||
raises(ValueError, "FloatOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "UnicodeOption('a', '', multi=True, default_multi=1)")
|
||||
raises(ValueError, "IPOption('a', '', multi=True, default_multi=1)")
|
||||
raises(ValueError, "IPOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "PortOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "PortOption('a', '', multi=True, default_multi='11:12:13', allow_range=True)")
|
||||
raises(ValueError, "PortOption('a', '', multi=True, default_multi=11111111111111111111)")
|
||||
raises(ValueError, "NetworkOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "NetmaskOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "BroadcastOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "DomainnameOption('a', '', multi=True, default_multi='string')")
|
||||
raises(ValueError, "DomainnameOption('a', '', multi=True, default_multi=1)")
|
178
test/new_api/test_config_domain.py
Normal file
178
test/new_api/test_config_domain.py
Normal file
@ -0,0 +1,178 @@
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
import warnings, sys
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import DomainnameOption, EmailOption, URLOption, OptionDescription
|
||||
from tiramisu.error import ValueWarning
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu import getapi
|
||||
|
||||
|
||||
def test_domainname():
|
||||
d = DomainnameOption('d', '')
|
||||
f = DomainnameOption('f', '', allow_without_dot=True)
|
||||
g = DomainnameOption('g', '', allow_ip=True)
|
||||
od = OptionDescription('a', '', [d, f, g])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('d').value.set('toto.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto')")
|
||||
api.option('d').value.set('toto3.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto_super.com')")
|
||||
api.option('d').value.set('toto-.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto..com')")
|
||||
#
|
||||
api.option('f').value.set('toto.com')
|
||||
api.option('f').value.set('toto')
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
|
||||
raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
|
||||
raises(ValueError, "api.option('d').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien')")
|
||||
api.option('f').value.set('d')
|
||||
api.option('f').value.set('d.t')
|
||||
#
|
||||
raises(ValueError, "api.option('f').value.set('192.168.1.1')")
|
||||
api.option('g').value.set('toto.com')
|
||||
api.option('g').value.set('192.168.1.0')
|
||||
api.option('g').value.set('192.168.1.29')
|
||||
|
||||
|
||||
def test_domainname_upper():
|
||||
d = DomainnameOption('d', '')
|
||||
od = OptionDescription('a', '', [d])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('d').value.set('toto.com')
|
||||
msg = _('some characters are uppercase')
|
||||
has_error = False
|
||||
try:
|
||||
api.option('d').value.set('TOTO.COM')
|
||||
except ValueError as err:
|
||||
assert msg in str(err)
|
||||
has_error = True
|
||||
assert has_error is True
|
||||
has_error = False
|
||||
try:
|
||||
api.option('d').value.set('toTo.com')
|
||||
except ValueError as err:
|
||||
assert msg in str(err)
|
||||
has_error = True
|
||||
assert has_error is True
|
||||
|
||||
|
||||
def test_domainname_warning():
|
||||
d = DomainnameOption('d', '', warnings_only=True)
|
||||
f = DomainnameOption('f', '', allow_without_dot=True, warnings_only=True)
|
||||
g = DomainnameOption('g', '', allow_ip=True, warnings_only=True)
|
||||
od = OptionDescription('a', '', [d, f, g])
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('d').value.set('toto.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto')")
|
||||
api.option('d').value.set('toto3.com')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('d').value.set('toto_super.com')
|
||||
assert len(w) == 1
|
||||
api.option('d').value.set('toto-.com')
|
||||
raises(ValueError, "api.option('d').value.set('toto..com')")
|
||||
#
|
||||
api.option('f').value.set('toto.com')
|
||||
api.option('f').value.set('toto')
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
|
||||
raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
|
||||
api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
|
||||
raises(ValueError, "api.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx')")
|
||||
api.option('f').value.set('d')
|
||||
api.option('f').value.set('d.t')
|
||||
#
|
||||
raises(ValueError, "api.option('f').value.set('192.168.1.1')")
|
||||
api.option('g').value.set('toto.com')
|
||||
api.option('g').value.set('192.168.1.0')
|
||||
api.option('g').value.set('192.168.1.29')
|
||||
|
||||
|
||||
def test_special_domain_name():
|
||||
"""domain name option that starts with a number or not
|
||||
"""
|
||||
d = DomainnameOption('d', '')
|
||||
e = DomainnameOption('e', '', type_='netbios')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('d').value.set('1toto.com')
|
||||
api.option('d').value.set('123toto.com')
|
||||
api.option('e').value.set('toto')
|
||||
api.option('e').value.set('1toto')
|
||||
|
||||
|
||||
def test_domainname_netbios():
|
||||
d = DomainnameOption('d', '', type_='netbios')
|
||||
e = DomainnameOption('e', '', "toto", type_='netbios')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
raises(ValueError, "api.option('d').value.set('toto.com')")
|
||||
api.option('d').value.set('toto')
|
||||
raises(ValueError, "api.option('d').value.set('domainnametoolong')")
|
||||
|
||||
|
||||
def test_domainname_hostname():
|
||||
d = DomainnameOption('d', '', type_='hostname')
|
||||
e = DomainnameOption('e', '', "toto", type_='hostname')
|
||||
od = OptionDescription('a', '', [d, e])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
raises(ValueError, "api.option('d').value.set('toto.com')")
|
||||
api.option('d').value.set('toto')
|
||||
api.option('d').value.set('domainnametoolong')
|
||||
|
||||
|
||||
def test_email():
|
||||
e = EmailOption('e', '')
|
||||
od = OptionDescription('a', '', [e])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('e').value.set('foo-bar.baz@example.com')
|
||||
api.option('e').value.set('root@foo.com')
|
||||
api.option('e').value.set('root@domain')
|
||||
raises(ValueError, "api.option('e').value.set(1)")
|
||||
raises(ValueError, "api.option('e').value.set('root')")
|
||||
raises(ValueError, "api.option('e').value.set('root[]@domain')")
|
||||
|
||||
|
||||
def test_url():
|
||||
u = URLOption('u', '')
|
||||
od = OptionDescription('a', '', [u])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.property.read_write()
|
||||
api.option('u').value.set('http://foo.com')
|
||||
api.option('u').value.set('https://foo.com')
|
||||
api.option('u').value.set('https://foo.com/')
|
||||
raises(ValueError, "api.option('u').value.set(1)")
|
||||
raises(ValueError, "api.option('u').value.set('ftp://foo.com')")
|
||||
raises(ValueError, "api.option('u').value.set('foo.com')")
|
||||
raises(ValueError, "api.option('u').value.set(':/foo.com')")
|
||||
raises(ValueError, "api.option('u').value.set('foo.com/http://')")
|
||||
api.option('u').value.set('https://foo.com/index.html')
|
||||
api.option('u').value.set('https://foo.com/index.html?var=value&var2=val2')
|
||||
raises(ValueError, "api.option('u').value.set('https://foo.com/index\\n.html')")
|
||||
api.option('u').value.set('https://foo.com:8443')
|
||||
api.option('u').value.set('https://foo.com:8443/')
|
||||
api.option('u').value.set('https://foo.com:8443/index.html')
|
||||
raises(ValueError, "api.option('u').value.set('https://foo.com:84438989')")
|
||||
api.option('u').value.set('https://foo.com:8443/INDEX')
|
||||
raises(ValueError, "api.option('u').value.set('https://FOO.COM:8443')")
|
254
test/new_api/test_config_ip.py
Normal file
254
test/new_api/test_config_ip.py
Normal file
@ -0,0 +1,254 @@
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
import warnings
|
||||
from py.test import raises
|
||||
from tiramisu import Config ,IPOption, NetworkOption, NetmaskOption, \
|
||||
PortOption, BroadcastOption, OptionDescription, getapi
|
||||
from tiramisu.error import ValueWarning
|
||||
|
||||
|
||||
def test_ip():
|
||||
a = IPOption('a', '')
|
||||
b = IPOption('b', '', private_only=True)
|
||||
d = IPOption('d', '', warnings_only=True, private_only=True)
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
od = OptionDescription('od', '', [a, b, d])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.option('a').value.set('192.168.1.0')
|
||||
api.option('a').value.set('88.88.88.88')
|
||||
api.option('a').value.set('0.0.0.0')
|
||||
raises(ValueError, "api.option('a').value.set('255.255.255.0')")
|
||||
api.option('b').value.set('192.168.1.1')
|
||||
api.option('b').value.set('192.168.1.0')
|
||||
raises(ValueError, "api.option('b').value.set('88.88.88.88')")
|
||||
api.option('b').value.set('0.0.0.0')
|
||||
raises(ValueError, "api.option('b').value.set('255.255.255.0')")
|
||||
raises(ValueError, "api.option('a').value.set('333.0.1.20')")
|
||||
|
||||
raises(ValueError, "IPOption('a', 'ip', default='192.000.023.01')")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('d').value.set('88.88.88.88')
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_ip_default():
|
||||
a = IPOption('a', '', '88.88.88.88')
|
||||
od = OptionDescription('od', '', [a])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.option('a').value.get() == '88.88.88.88'
|
||||
|
||||
|
||||
def test_ip_reserved():
|
||||
a = IPOption('a', '')
|
||||
b = IPOption('b', '', allow_reserved=True)
|
||||
c = IPOption('c', '', warnings_only=True)
|
||||
od = OptionDescription('od', '', [a, b, c])
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
cfg = Config(od)
|
||||
api = getapi(cfg)
|
||||
raises(ValueError, "api.option('a').value.set('226.94.1.1')")
|
||||
api.option('b').value.set('226.94.1.1')
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('c').value.set('226.94.1.1')
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_network():
|
||||
a = NetworkOption('a', '')
|
||||
b = NetworkOption('b', '', warnings_only=True)
|
||||
od = OptionDescription('od', '', [a, b])
|
||||
warnings.simplefilter("always", ValueWarning)
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
api.option('a').value.set('192.168.1.1')
|
||||
api.option('a').value.set('192.168.1.0')
|
||||
api.option('a').value.set('88.88.88.88')
|
||||
api.option('a').value.set('0.0.0.0')
|
||||
raises(ValueError, "api.option('a').value.set(1)")
|
||||
raises(ValueError, "api.option('a').value.set('1.1.1.1.1')")
|
||||
raises(ValueError, "api.option('a').value.set('255.255.255.0')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.001.0')")
|
||||
raises(ValueError, "api.option('a').value.set('333.168.1.1')")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('b').value.set('255.255.255.0')
|
||||
assert len(w) == 1
|
||||
|
||||
|
||||
def test_network_invalid():
|
||||
raises(ValueError, "NetworkOption('a', '', default='toto')")
|
||||
|
||||
|
||||
def test_netmask():
|
||||
a = NetmaskOption('a', '')
|
||||
od = OptionDescription('od', '', [a])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.1.1')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.1')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.0')")
|
||||
raises(ValueError, "api.option('a').value.set('88.88.88.88')")
|
||||
raises(ValueError, "api.option('a').value.set('255.255.255.000')")
|
||||
raises(ValueError, "api.option('a').value.set(2)")
|
||||
api.option('a').value.set('0.0.0.0')
|
||||
api.option('a').value.set('255.255.255.0')
|
||||
|
||||
|
||||
def test_broadcast():
|
||||
a = BroadcastOption('a', '')
|
||||
od = OptionDescription('od', '', [a])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
raises(ValueError, "api.option('a').value.set('192.168.1.255.1')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.001.255')")
|
||||
raises(ValueError, "api.option('a').value.set('192.168.0.300')")
|
||||
raises(ValueError, "api.option('a').value.set(1)")
|
||||
raises(ValueError, "api.option('a').value.set(2)")
|
||||
api.option('a').value.set('0.0.0.0')
|
||||
api.option('a').value.set('255.255.255.0')
|
||||
|
||||
|
||||
def test_port():
|
||||
a = PortOption('a', '')
|
||||
b = PortOption('b', '', allow_zero=True)
|
||||
c = PortOption('c', '', allow_zero=True, allow_registred=False)
|
||||
d = PortOption('d', '', allow_zero=True, allow_wellknown=False, allow_registred=False)
|
||||
e = PortOption('e', '', allow_zero=True, allow_private=True)
|
||||
f = PortOption('f', '', allow_private=True)
|
||||
od = OptionDescription('od', '', [a, b, c, d, e, f])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
raises(ValueError, "api.option('a').value.set(0)")
|
||||
api.option('a').value.set(1)
|
||||
api.option('a').value.set(1023)
|
||||
api.option('a').value.set(1024)
|
||||
api.option('a').value.set(49151)
|
||||
raises(ValueError, "api.option('a').value.set(49152)")
|
||||
raises(ValueError, "api.option('a').value.set(65535)")
|
||||
raises(ValueError, "api.option('a').value.set(65536)")
|
||||
|
||||
api.option('b').value.set(0)
|
||||
api.option('b').value.set(1)
|
||||
api.option('b').value.set(1023)
|
||||
api.option('b').value.set(1024)
|
||||
api.option('b').value.set(49151)
|
||||
raises(ValueError, "api.option('b').value.set(49152)")
|
||||
raises(ValueError, "api.option('b').value.set(65535)")
|
||||
raises(ValueError, "api.option('b').value.set(65536)")
|
||||
|
||||
api.option('c').value.set(0)
|
||||
api.option('c').value.set(1)
|
||||
api.option('c').value.set(1023)
|
||||
raises(ValueError, "api.option('c').value.set(1024)")
|
||||
raises(ValueError, "api.option('c').value.set(49151)")
|
||||
raises(ValueError, "api.option('c').value.set(49152)")
|
||||
raises(ValueError, "api.option('c').value.set(65535)")
|
||||
raises(ValueError, "api.option('c').value.set(65536)")
|
||||
|
||||
api.option('d').value.set(0)
|
||||
raises(ValueError, "api.option('d').value.set(1)")
|
||||
raises(ValueError, "api.option('d').value.set(1023)")
|
||||
raises(ValueError, "api.option('d').value.set(1024)")
|
||||
raises(ValueError, "api.option('d').value.set(49151)")
|
||||
raises(ValueError, "api.option('d').value.set(49152)")
|
||||
raises(ValueError, "api.option('d').value.set(65535)")
|
||||
raises(ValueError, "api.option('d').value.set(65536)")
|
||||
|
||||
api.option('e').value.set(0)
|
||||
api.option('e').value.set(1)
|
||||
api.option('e').value.set(1023)
|
||||
api.option('e').value.set(1024)
|
||||
api.option('e').value.set(49151)
|
||||
api.option('e').value.set(49152)
|
||||
api.option('e').value.set(65535)
|
||||
|
||||
raises(ValueError, "api.option('f').value.set(0)")
|
||||
api.option('f').value.set(1)
|
||||
api.option('f').value.set(1023)
|
||||
api.option('f').value.set(1024)
|
||||
api.option('f').value.set(49151)
|
||||
api.option('f').value.set(49152)
|
||||
api.option('f').value.set(65535)
|
||||
raises(ValueError, "api.option('f').value.set(65536)")
|
||||
|
||||
|
||||
def test_port_range():
|
||||
a = PortOption('a', '', allow_range=True)
|
||||
b = PortOption('b', '', allow_range=True, allow_zero=True)
|
||||
c = PortOption('c', '', allow_range=True, allow_zero=True, allow_registred=False)
|
||||
d = PortOption('d', '', allow_range=True, allow_zero=True, allow_wellknown=False, allow_registred=False)
|
||||
e = PortOption('e', '', allow_range=True, allow_zero=True, allow_private=True)
|
||||
f = PortOption('f', '', allow_range=True, allow_private=True)
|
||||
od = OptionDescription('od', '', [a, b, c, d, e, f])
|
||||
c = Config(od)
|
||||
api = getapi(c)
|
||||
raises(ValueError, "api.option('a').value.set(0)")
|
||||
api.option('a').value.set(1)
|
||||
api.option('a').value.set(1023)
|
||||
api.option('a').value.set(1024)
|
||||
api.option('a').value.set(49151)
|
||||
raises(ValueError, "api.option('a').value.set(49152)")
|
||||
raises(ValueError, "api.option('a').value.set(65535)")
|
||||
raises(ValueError, "api.option('a').value.set(65536)")
|
||||
api.option('a').value.set('1:49151')
|
||||
raises(ValueError, "api.option('a').value.set('0:49151')")
|
||||
raises(ValueError, "api.option('a').value.set('1:49152')")
|
||||
|
||||
api.option('b').value.set(0)
|
||||
api.option('b').value.set(1)
|
||||
api.option('b').value.set(1023)
|
||||
api.option('b').value.set(1024)
|
||||
api.option('b').value.set(49151)
|
||||
raises(ValueError, "api.option('b').value.set(49152)")
|
||||
raises(ValueError, "api.option('b').value.set(65535)")
|
||||
raises(ValueError, "api.option('b').value.set(65536)")
|
||||
api.option('b').value.set('0:49151')
|
||||
raises(ValueError, "api.option('b').value.set('0:49152')")
|
||||
|
||||
api.option('c').value.set(0)
|
||||
api.option('c').value.set(1)
|
||||
api.option('c').value.set(1023)
|
||||
raises(ValueError, "api.option('c').value.set(1024)")
|
||||
raises(ValueError, "api.option('c').value.set(49151)")
|
||||
raises(ValueError, "api.option('c').value.set(49152)")
|
||||
raises(ValueError, "api.option('c').value.set(65535)")
|
||||
raises(ValueError, "api.option('c').value.set(65536)")
|
||||
api.option('c').value.set('0:1023')
|
||||
raises(ValueError, "api.option('c').value.set('0:1024')")
|
||||
|
||||
api.option('d').value.set(0)
|
||||
raises(ValueError, "api.option('d').value.set(1)")
|
||||
raises(ValueError, "api.option('d').value.set(1023)")
|
||||
raises(ValueError, "api.option('d').value.set(1024)")
|
||||
raises(ValueError, "api.option('d').value.set(49151)")
|
||||
raises(ValueError, "api.option('d').value.set(49152)")
|
||||
raises(ValueError, "api.option('d').value.set(65535)")
|
||||
raises(ValueError, "api.option('d').value.set(65536)")
|
||||
raises(ValueError, "api.option('d').value.set('0:0')")
|
||||
raises(ValueError, "api.option('d').value.set('0:1')")
|
||||
|
||||
api.option('e').value.set(0)
|
||||
api.option('e').value.set(1)
|
||||
api.option('e').value.set(1023)
|
||||
api.option('e').value.set(1024)
|
||||
api.option('e').value.set(49151)
|
||||
api.option('e').value.set(49152)
|
||||
api.option('e').value.set(65535)
|
||||
api.option('e').value.set('0:65535')
|
||||
raises(ValueError, "api.option('e').value.set('0:65536')")
|
||||
|
||||
raises(ValueError, "api.option('f').value.set(0)")
|
||||
api.option('f').value.set(1)
|
||||
api.option('f').value.set(1023)
|
||||
api.option('f').value.set(1024)
|
||||
api.option('f').value.set(49151)
|
||||
api.option('f').value.set(49152)
|
||||
api.option('f').value.set(65535)
|
||||
raises(ValueError, "api.option('f').value.set(65536)")
|
||||
api.option('f').value.set('1:65535')
|
||||
api.option('f').value.set('3:4')
|
||||
raises(ValueError, "api.option('f').value.set('0:65535')")
|
||||
raises(ValueError, "api.option('f').value.set('4:3')")
|
1368
test/new_api/test_dyn_optiondescription.py
Normal file
1368
test/new_api/test_dyn_optiondescription.py
Normal file
@ -0,0 +1,1368 @@
|
||||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu import BoolOption, StrOption, ChoiceOption, IPOption, \
|
||||
NetworkOption, NetmaskOption, IntOption, FloatOption, \
|
||||
UnicodeOption, PortOption, BroadcastOption, DomainnameOption, \
|
||||
EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \
|
||||
OptionDescription, DynOptionDescription, DynSymLinkOption, submulti, MasterSlaves, \
|
||||
Config, getapi
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError
|
||||
from tiramisu.storage import delete_session
|
||||
#from .test_state import _diff_opts, _diff_conf
|
||||
|
||||
from py.test import raises
|
||||
|
||||
|
||||
def return_true(value, param=None, suffix=None):
|
||||
if value == 'val' and param in [None, 'yes']:
|
||||
return
|
||||
raise ValueError('no value')
|
||||
|
||||
|
||||
def return_dynval(value='val', suffix=None):
|
||||
return value
|
||||
|
||||
|
||||
def return_list2(suffix):
|
||||
return [str(suffix), 'val2']
|
||||
|
||||
|
||||
def return_list(val=None, suffix=None):
|
||||
if val:
|
||||
return val
|
||||
else:
|
||||
return ['val1', 'val2']
|
||||
|
||||
|
||||
def return_same_list():
|
||||
return ['val1', 'val1']
|
||||
|
||||
|
||||
def return_wrong_list():
|
||||
return ['---', ' ']
|
||||
|
||||
|
||||
def return_raise():
|
||||
raise Exception('error')
|
||||
|
||||
|
||||
#def test_build_dyndescription():
|
||||
# st = StrOption('st', '')
|
||||
# dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
# od = OptionDescription('od', '', [dod])
|
||||
# cfg = Config(od)
|
||||
# assert str(cfg) == """[dodval1]
|
||||
#[dodval2]"""
|
||||
# assert str(cfg.dodval1) == "stval1 = None"
|
||||
# assert str(cfg.dodval2) == "stval2 = None"
|
||||
|
||||
|
||||
#def test_build_dyndescription_raise():
|
||||
# st = StrOption('st', '')
|
||||
# dod = DynOptionDescription('dod', '', [st], callback=return_raise)
|
||||
# od = OptionDescription('od', '', [dod])
|
||||
# cfg = Config(od)
|
||||
# raises(ConfigError, "str(cfg)")
|
||||
|
||||
|
||||
#def test_subpath_dyndescription():
|
||||
# st = StrOption('st', '')
|
||||
# dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
# od = OptionDescription('od', '', [dod])
|
||||
# od2 = OptionDescription('od', '', [od])
|
||||
# api = getapi(Config(od2))
|
||||
# assert str(cfg) == "[od]"
|
||||
# assert str(cfg.od) == """[dodval1]
|
||||
#[dodval2]"""
|
||||
# assert str(cfg.od.dodval1) == "stval1 = None"
|
||||
# assert str(cfg.od.dodval2) == "stval2 = None"
|
||||
|
||||
|
||||
def test_list_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
assert api.option('od.dodval1.stval1').value.get() is None
|
||||
assert api.option('od.dodval2.stval2').value.get() is None
|
||||
|
||||
|
||||
def test_unknown_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
raises(AttributeError, "api.option('od.dodval3').value.get()")
|
||||
raises(AttributeError, "api.option('od.dodval1.novalue').value.get()")
|
||||
|
||||
|
||||
#def test_getdoc_dyndescription():
|
||||
# st = StrOption('st', 'doc1')
|
||||
# dod = DynOptionDescription('dod', 'doc2', [st], callback=return_list)
|
||||
# od = OptionDescription('od', '', [dod])
|
||||
# od2 = OptionDescription('od', '', [od])
|
||||
# api = getapi(Config(od2))
|
||||
# stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
# stval2 = cfg.unwrap_from_path('od.dodval2.stval2')
|
||||
# dodval1 = cfg.unwrap_from_path('od.dodval1')
|
||||
# dodval2 = cfg.unwrap_from_path('od.dodval2')
|
||||
# assert stval1.impl_getname() == 'stval1'
|
||||
# assert stval2.impl_getname() == 'stval2'
|
||||
# assert dodval1.impl_getname() == 'dodval1'
|
||||
# assert dodval2.impl_getname() == 'dodval2'
|
||||
# assert stval1.impl_getdoc() == 'doc1'
|
||||
# assert stval2.impl_getdoc() == 'doc1'
|
||||
# assert dodval1.impl_getdoc() == 'doc2'
|
||||
# assert dodval2.impl_getdoc() == 'doc2'
|
||||
|
||||
|
||||
#def test_getpaths_dyndescription():
|
||||
# st = StrOption('st', '')
|
||||
# dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
# od = OptionDescription('od', '', [dod])
|
||||
# od2 = OptionDescription('od', '', [od])
|
||||
# api = getapi(Config(od2))
|
||||
# assert cfg.cfgimpl_get_description().impl_getpaths() == ['od.dodval1.stval1', 'od.dodval2.stval2']
|
||||
# assert cfg.cfgimpl_get_description().impl_getpaths(include_groups=True) == ['od', 'od.dodval1', 'od.dodval1.stval1', 'od.dodval2', 'od.dodval2.stval2']
|
||||
|
||||
|
||||
def test_mod_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
owner = api.owner.get()
|
||||
#
|
||||
assert api.option('od.dodval1.stval1').value.get() is None
|
||||
assert api.option('od.dodval2.stval2').value.get() is None
|
||||
assert api.option('od.dodval1.stval1').owner.isdefault()
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
#
|
||||
api.option('od.dodval1.stval1').value.set('yes')
|
||||
assert api.option('od.dodval1.stval1').value.get() == 'yes'
|
||||
assert api.option('od.dodval2.stval2').value.get() is None
|
||||
assert api.option('od.dodval1.stval1').owner.get() == owner
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
#
|
||||
api.option('od.dodval2.stval2').value.set('no')
|
||||
assert api.option('od.dodval1.stval1').value.get() == 'yes'
|
||||
assert api.option('od.dodval2.stval2').value.get() == 'no'
|
||||
assert api.option('od.dodval1.stval1').owner.get() == owner
|
||||
assert api.option('od.dodval2.stval2').owner.get() == owner
|
||||
|
||||
|
||||
def test_del_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
owner = api.owner.get()
|
||||
assert api.option('od.dodval1.stval1').value.get() is None
|
||||
assert api.option('od.dodval2.stval2').value.get() is None
|
||||
api.option('od.dodval1.stval1').value.set('yes')
|
||||
assert api.option('od.dodval1.stval1').owner.get() == owner
|
||||
api.option('od.dodval1.stval1').value.reset()
|
||||
assert api.option('od.dodval1.stval1').owner.isdefault()
|
||||
|
||||
|
||||
def test_multi_dyndescription():
|
||||
st = StrOption('st', '', multi=True)
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
owner = api.owner.get()
|
||||
assert api.option('od.dodval1.stval1').value.get() == []
|
||||
assert api.option('od.dodval2.stval2').value.get() == []
|
||||
assert api.option('od.dodval1.stval1').owner.isdefault()
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
api.option('od.dodval1.stval1').value.set(['yes'])
|
||||
assert api.option('od.dodval1.stval1').value.get() == ['yes']
|
||||
assert api.option('od.dodval2.stval2').value.get() == []
|
||||
assert api.option('od.dodval1.stval1').owner.get() == owner
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
api.option('od.dodval2.stval2').value.set(['no'])
|
||||
assert api.option('od.dodval1.stval1').value.get() == ['yes']
|
||||
assert api.option('od.dodval2.stval2').value.get() == ['no']
|
||||
#assert cfg.getowner(st) == owners.default
|
||||
assert api.option('od.dodval1.stval1').owner.get() == owner
|
||||
assert api.option('od.dodval2.stval2').owner.get() == owner
|
||||
api.option('od.dodval1.stval1').value.set(['yes', 'yes'])
|
||||
assert api.option('od.dodval1.stval1').value.get() == ['yes', 'yes']
|
||||
api.option('od.dodval1.stval1').value.set(['yes'])
|
||||
assert api.option('od.dodval1.stval1').value.get() == ['yes']
|
||||
|
||||
|
||||
def test_prop_dyndescription():
|
||||
st = StrOption('st', '', properties=('test',))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
assert set(api.option('od.dodval1.stval1').property.get()) == set(['test'])
|
||||
assert set(api.option('od.dodval2.stval2').property.get()) == set(['test'])
|
||||
api.option('od.dodval2.stval2').property.add('test2')
|
||||
assert set(api.option('od.dodval1.stval1').property.get()) == set(['test'])
|
||||
assert set(api.option('od.dodval2.stval2').property.get()) == set(['test', 'test2'])
|
||||
api.option('od.dodval1.stval1').property.pop('test')
|
||||
assert set(api.option('od.dodval1.stval1').property.get()) == set([])
|
||||
#
|
||||
assert set(api.option('od.dodval1').property.get()) == set([])
|
||||
assert set(api.option('od.dodval2').property.get()) == set([])
|
||||
api.option('od.dodval1').property.add('test1')
|
||||
assert set(api.option('od.dodval1').property.get()) == set(['test1'])
|
||||
assert set(api.option('od.dodval2').property.get()) == set([])
|
||||
api.option('od.dodval1').property.pop('test1')
|
||||
assert set(api.option('od.dodval1').property.get()) == set([])
|
||||
assert set(api.option('od.dodval2').property.get()) == set([])
|
||||
|
||||
|
||||
def test_prop_dyndescription_force_store_value():
|
||||
st = StrOption('st', '', properties=('force_store_value',))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
raises(ConfigError, "Config(od2)")
|
||||
|
||||
|
||||
def test_callback_dyndescription():
|
||||
st = StrOption('st', '', callback=return_dynval)
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
owner = api.owner.get()
|
||||
assert api.option('od.dodval1.stval1').value.get() == 'val'
|
||||
assert api.option('od.dodval2.stval2').value.get() == 'val'
|
||||
assert api.option('od.dodval1.stval1').owner.isdefault()
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
api.option('od.dodval1.stval1').value.set('val2')
|
||||
assert api.option('od.dodval1.stval1').value.get() == 'val2'
|
||||
assert api.option('od.dodval2.stval2').value.get() == 'val'
|
||||
assert api.option('od.dodval1.stval1').owner.get() == owner
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
api.option('od.dodval1.stval1').value.reset()
|
||||
assert api.option('od.dodval1.stval1').value.get() == 'val'
|
||||
assert api.option('od.dodval2.stval2').value.get() == 'val'
|
||||
assert api.option('od.dodval1.stval1').owner.isdefault()
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
|
||||
|
||||
def test_callback_list_dyndescription():
|
||||
st = StrOption('st', '', callback=return_list2, multi=True)
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
owner = api.owner.get()
|
||||
assert api.option('od.dodval1.stval1').value.get() == ['val1', 'val2']
|
||||
assert api.option('od.dodval2.stval2').value.get() == ['val2', 'val2']
|
||||
assert api.option('od.dodval1.stval1').owner.isdefault()
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
api.option('od.dodval1.stval1').value.set(['val3', 'val2'])
|
||||
assert api.option('od.dodval1.stval1').value.get() == ['val3', 'val2']
|
||||
assert api.option('od.dodval2.stval2').value.get() == ['val2', 'val2']
|
||||
assert api.option('od.dodval1.stval1').owner.get() == owner
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
|
||||
|
||||
def test_mandatory_dyndescription():
|
||||
st = StrOption('st', '', properties=('mandatory',))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('od.dodval2.stval2').value.get()")
|
||||
api.property.read_write()
|
||||
api.option('od.dodval1.stval1').value.set('val')
|
||||
api.property.read_only()
|
||||
assert api.option('od.dodval1.stval1').value.get() == 'val'
|
||||
raises(PropertiesOptionError, "api.option('od.dodval2.stval2').value.get()")
|
||||
api.property.read_write()
|
||||
api.option('od.dodval1.stval1').value.reset()
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()")
|
||||
assert list(api.value.mandatory_warnings()) == ['od.dodval1.stval1', 'od.dodval2.stval2']
|
||||
|
||||
|
||||
#def test_build_dyndescription_context():
|
||||
# val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
# st = StrOption('st', '')
|
||||
# dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
# od = OptionDescription('od', '', [dod, val1])
|
||||
# cfg = Config(od)
|
||||
# cfg._impl_test = True
|
||||
# assert str(cfg) == """[dodval1]
|
||||
#[dodval2]
|
||||
#val1 = ['val1', 'val2']"""
|
||||
# assert str(cfg.dodval1) == "stval1 = None"
|
||||
# assert str(cfg.dodval2) == "stval2 = None"
|
||||
# cfg.unwrap_from_path('dodval2')
|
||||
|
||||
|
||||
#def test_subpath_dyndescription_context():
|
||||
# val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
# st = StrOption('st', '')
|
||||
# dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
# od = OptionDescription('od', '', [dod, val1])
|
||||
# od2 = OptionDescription('od', '', [od])
|
||||
# api = getapi(Config(od2))
|
||||
# assert str(cfg) == "[od]"
|
||||
# assert str(cfg.od) == """[dodval1]
|
||||
#[dodval2]
|
||||
#val1 = ['val1', 'val2']"""
|
||||
# assert str(cfg.od.dodval1) == "stval1 = None"
|
||||
# assert str(cfg.od.dodval2) == "stval2 = None"
|
||||
|
||||
|
||||
def test_list_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
assert api.option('od.dodval1.stval1').value.get() is None
|
||||
assert api.option('od.dodval2.stval2').value.get() is None
|
||||
raises(AttributeError, "api.option('od.dodval3').value.get()")
|
||||
|
||||
|
||||
def test_mod_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
owner = api.owner.get()
|
||||
assert api.option('od.dodval1.stval1').value.get() is None
|
||||
assert api.option('od.dodval2.stval2').value.get() is None
|
||||
assert api.option('od.dodval1.stval1').owner.isdefault()
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
api.option('od.dodval1.stval1').value.set('yes')
|
||||
assert api.option('od.dodval1.stval1').value.get() == 'yes'
|
||||
assert api.option('od.dodval2.stval2').value.get() is None
|
||||
assert api.option('od.dodval1.stval1').owner.get() == owner
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
api.option('od.dodval2.stval2').value.set('no')
|
||||
assert api.option('od.dodval1.stval1').value.get() == 'yes'
|
||||
assert api.option('od.dodval2.stval2').value.get() == 'no'
|
||||
#assert cfg.getowner(st) == owners.default
|
||||
assert api.option('od.dodval1.stval1').owner.get() == owner
|
||||
assert api.option('od.dodval2.stval2').owner.get() == owner
|
||||
|
||||
|
||||
def test_del_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
owner = api.owner.get()
|
||||
assert api.option('od.dodval1.stval1').value.get() is None
|
||||
assert api.option('od.dodval2.stval2').value.get() is None
|
||||
api.option('od.dodval1.stval1').value.set('yes')
|
||||
assert api.option('od.dodval1.stval1').owner.get() == owner
|
||||
api.option('od.dodval1.stval1').value.reset()
|
||||
assert api.option('od.dodval1.stval1').owner.isdefault()
|
||||
|
||||
|
||||
def test_multi_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', multi=True)
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
owner = api.owner.get()
|
||||
assert api.option('od.dodval1.stval1').value.get() == []
|
||||
assert api.option('od.dodval2.stval2').value.get() == []
|
||||
assert api.option('od.dodval1.stval1').owner.isdefault()
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
api.option('od.dodval1.stval1').value.set(['yes'])
|
||||
assert api.option('od.dodval1.stval1').value.get() == ['yes']
|
||||
assert api.option('od.dodval2.stval2').value.get() == []
|
||||
assert api.option('od.dodval1.stval1').owner.get() == owner
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
api.option('od.dodval2.stval2').value.set(['no'])
|
||||
assert api.option('od.dodval1.stval1').value.get() == ['yes']
|
||||
assert api.option('od.dodval2.stval2').value.get() == ['no']
|
||||
#assert cfg.getowner(st) == owners.default
|
||||
assert api.option('od.dodval1.stval1').owner.get() == owner
|
||||
assert api.option('od.dodval2.stval2').owner.get() == owner
|
||||
api.option('od.dodval1.stval1').value.set(['yes', 'yes'])
|
||||
assert api.option('od.dodval1.stval1').value.get() == ['yes', 'yes']
|
||||
api.option('od.dodval1.stval1').value.set(['yes'])
|
||||
assert api.option('od.dodval1.stval1').value.get() == ['yes']
|
||||
|
||||
|
||||
def test_prop_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', properties=('test',))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
assert set(api.option('od.dodval1.stval1').property.get()) == set(['test'])
|
||||
assert set(api.option('od.dodval2.stval2').property.get()) == set(['test'])
|
||||
api.option('od.dodval2.stval2').property.add('test2')
|
||||
assert set(api.option('od.dodval1.stval1').property.get()) == set(['test'])
|
||||
assert set(api.option('od.dodval2.stval2').property.get()) == set(['test', 'test2'])
|
||||
api.option('od.dodval1.stval1').property.pop('test')
|
||||
assert set(api.option('od.dodval1.stval1').property.get()) == set([])
|
||||
assert set(api.option('od.dodval2.stval2').property.get()) == set(['test', 'test2'])
|
||||
|
||||
|
||||
def test_callback_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', callback=return_dynval)
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
owner = api.owner.get()
|
||||
assert api.option('od.dodval1.stval1').value.get() == 'val'
|
||||
assert api.option('od.dodval2.stval2').value.get() == 'val'
|
||||
assert api.option('od.dodval1.stval1').owner.isdefault()
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
api.option('od.dodval1.stval1').value.set('val2')
|
||||
assert api.option('od.dodval1.stval1').value.get() == 'val2'
|
||||
assert api.option('od.dodval2.stval2').value.get() == 'val'
|
||||
assert api.option('od.dodval1.stval1').owner.get() == owner
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
api.option('od.dodval1.stval1').value.reset()
|
||||
assert api.option('od.dodval1.stval1').value.get() == 'val'
|
||||
assert api.option('od.dodval2.stval2').value.get() == 'val'
|
||||
assert api.option('od.dodval1.stval1').owner.isdefault()
|
||||
assert api.option('od.dodval2.stval2').owner.isdefault()
|
||||
|
||||
|
||||
def test_mandatory_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', properties=('mandatory',))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('od.dodval2.stval2').value.get()")
|
||||
api.property.read_write()
|
||||
api.option('od.dodval1.stval1').value.set('val')
|
||||
api.property.read_only()
|
||||
assert api.option('od.dodval1.stval1').value.get() == 'val'
|
||||
raises(PropertiesOptionError, "api.option('od.dodval2.stval2').value.get()")
|
||||
api.property.read_write()
|
||||
api.option('od.dodval1.stval1').value.reset()
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()")
|
||||
assert list(api.value.mandatory_warnings()) == ['od.dodval1.stval1', 'od.dodval2.stval2']
|
||||
|
||||
|
||||
def test_increase_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', properties=('mandatory',))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.property.read_write()
|
||||
assert api.option('od.dodval1.stval1').value.get() is None
|
||||
assert api.option('od.dodval2.stval2').value.get() is None
|
||||
raises(AttributeError, "api.option('od.dodval3').value.get()")
|
||||
api.option('od.val1').value.set(['val1', 'val2', 'val3'])
|
||||
assert api.option('od.dodval1.stval1').value.get() is None
|
||||
assert api.option('od.dodval2.stval2').value.get() is None
|
||||
assert api.option('od.dodval3.stval3').value.get() is None
|
||||
|
||||
|
||||
def test_decrease_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', properties=('mandatory',))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
owner = api.owner.get()
|
||||
api.property.read_write()
|
||||
assert api.option('od.dodval1.stval1').value.get() is None
|
||||
assert api.option('od.dodval2.stval2').value.get() is None
|
||||
api.option('od.dodval2.stval2').value.set('yes')
|
||||
assert api.option('od.dodval1.stval1').value.get() is None
|
||||
assert api.option('od.dodval2.stval2').value.get() == 'yes'
|
||||
assert api.option('od.dodval1.stval1').owner.isdefault()
|
||||
assert api.option('od.dodval2.stval2').owner.get() == owner
|
||||
raises(AttributeError, "api.option('od.dodval3').value.get()")
|
||||
api.option('od.val1').value.set(['val1'])
|
||||
assert api.option('od.dodval1.stval1').value.get() is None
|
||||
raises(AttributeError, "api.option('od.dodval2').value.get()")
|
||||
raises(AttributeError, "api.option('od.dodval3').value.get()")
|
||||
assert api.option('od.dodval1.stval1').owner.isdefault()
|
||||
#FIXME
|
||||
# raises(AttributeError, "cfg.getowner(stval2)")
|
||||
raises(AttributeError, "api.option('od.dodval2.stval2').value.get()")
|
||||
#
|
||||
#
|
||||
#def test_requires_dyndescription():
|
||||
# boolean = BoolOption('boolean', '', True)
|
||||
# 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, boolean])
|
||||
# api = getapi(Config(od2))
|
||||
# api.property.read_write()
|
||||
# assert api.option('od.dodval1.stval1').value.get() is None
|
||||
# assert api.option('od.dodval2.stval2').value.get() is None
|
||||
# #
|
||||
# cfg.boolean = False
|
||||
# props = []
|
||||
# try:
|
||||
# cfg.od.dodval1.stval1
|
||||
# except PropertiesOptionError as err:
|
||||
# props = err.proptype
|
||||
# assert props == ['disabled']
|
||||
# props = []
|
||||
# try:
|
||||
# cfg.od.dodval2.stval2
|
||||
# except PropertiesOptionError as err:
|
||||
# props = err.proptype
|
||||
# assert props == ['disabled']
|
||||
# #
|
||||
# cfg.boolean = True
|
||||
# assert api.option('od.dodval1.stval1').value.get() is None
|
||||
# assert api.option('od.dodval2.stval2').value.get() is None
|
||||
# #transitive
|
||||
# cfg.cfgimpl_get_settings()[boolean].append('disabled')
|
||||
# props = []
|
||||
# try:
|
||||
# cfg.od.dodval1.stval1
|
||||
# except PropertiesOptionError as err:
|
||||
# props = err.proptype
|
||||
# assert props == ['disabled']
|
||||
# props = []
|
||||
# try:
|
||||
# cfg.od.dodval2.stval2
|
||||
# except PropertiesOptionError as err:
|
||||
# props = err.proptype
|
||||
# assert props == ['disabled']
|
||||
|
||||
|
||||
#def test_requires_dyndescription2():
|
||||
# boolean = BoolOption('boolean', '', True)
|
||||
# st = StrOption('st', '')
|
||||
# dod = DynOptionDescription('dod', '', [st], callback=return_list,
|
||||
# requires=[{'option': boolean, 'expected': False,
|
||||
# 'action': 'disabled'}])
|
||||
# od = OptionDescription('od', '', [dod])
|
||||
# od2 = OptionDescription('od', '', [od, boolean])
|
||||
# api = getapi(Config(od2))
|
||||
# api.property.read_write()
|
||||
# assert api.option('od.dodval1.stval1').value.get() is None
|
||||
# assert api.option('od.dodval2.stval2').value.get() is None
|
||||
# #
|
||||
# cfg.boolean = False
|
||||
# props = []
|
||||
# try:
|
||||
# cfg.od.dodval1.stval1
|
||||
# except PropertiesOptionError as err:
|
||||
# props = err.proptype
|
||||
# assert props == ['disabled']
|
||||
# props = []
|
||||
# try:
|
||||
# cfg.od.dodval2.stval2
|
||||
# except PropertiesOptionError as err:
|
||||
# props = err.proptype
|
||||
# assert props == ['disabled']
|
||||
# #
|
||||
# cfg.boolean = True
|
||||
# assert api.option('od.dodval1.stval1').value.get() is None
|
||||
# assert api.option('od.dodval2.stval2').value.get() is None
|
||||
# #transitive
|
||||
# cfg.cfgimpl_get_settings()[boolean].append('disabled')
|
||||
# props = []
|
||||
# try:
|
||||
# cfg.od.dodval1.stval1
|
||||
# except PropertiesOptionError as err:
|
||||
# props = err.proptype
|
||||
# assert props == ['disabled']
|
||||
# props = []
|
||||
# try:
|
||||
# cfg.od.dodval2.stval2
|
||||
# except PropertiesOptionError as err:
|
||||
# props = err.proptype
|
||||
# assert props == ['disabled']
|
||||
#
|
||||
#
|
||||
def test_validator_dyndescription():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', validator=return_true, validator_params={'': ('yes',)}, default='val')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
assert api.option('od.dodval1.stval1').value.get() == 'val'
|
||||
raises(ValueError, "api.option('od.dodval1.stval1').value.set('no')")
|
||||
api.option('od.dodval1.stval1').value.set('val')
|
||||
|
||||
|
||||
def test_makedict_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.option('od.dodval1.stval1').value.set('yes')
|
||||
assert api.option.make_dict() == {'od.val1': ['val1', 'val2'], 'od.dodval1.stval1': 'yes', 'od.dodval2.stval2': None}
|
||||
assert api.option.make_dict(flatten=True) == {'val1': ['val1', 'val2'], 'stval1': 'yes', 'stval2': None}
|
||||
assert api.option.make_dict(withoption='stval1') == {'od.dodval1.stval1': 'yes'}
|
||||
assert api.option('od').make_dict(withoption='stval1') == {'dodval1.stval1': 'yes'}
|
||||
assert api.option('od.dodval1').make_dict(withoption='stval1') == {'stval1': 'yes'}
|
||||
|
||||
|
||||
def test_find_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
api.option('od.dodval1.stval1').value.set('yes')
|
||||
assert api.option.find_first('stval1', type='value') == "yes"
|
||||
assert isinstance(api.option.find_first('stval1', type='option'), DynSymLinkOption)
|
||||
#assert api.option.find(bytype=StrOption, type='path') == ['od.dodval1.stval1', 'od.dodval2.stval2', 'od.val1']
|
||||
#opts = api.option.find(byvalue='yes')
|
||||
#assert len(opts) == 1
|
||||
#assert isinstance(opts[0], DynSymLinkOption)
|
||||
#assert opts[0].impl_getname() == 'stval1'
|
||||
raises(AttributeError, "api.option.find('strnotexists')")
|
||||
|
||||
|
||||
#def test_iter_all_dyndescription_context():
|
||||
# val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
# st = StrOption('st', '')
|
||||
# dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
# od = OptionDescription('od', '', [dod, val1])
|
||||
# od2 = OptionDescription('od', '', [od])
|
||||
# api = getapi(Config(od2))
|
||||
# for it in cfg.iter_all():
|
||||
# assert it[0] == 'od'
|
||||
# assert str(it[1]) == str(cfg.od)
|
||||
# #
|
||||
# list_od = []
|
||||
# for it in cfg.od.iter_all():
|
||||
# list_od.append(it[0])
|
||||
# assert list_od == ['dodval1', 'dodval2', 'val1']
|
||||
# #
|
||||
# list_od = []
|
||||
# for it in cfg.od.dodval1:
|
||||
# list_od.append(it[0])
|
||||
# assert list_od == ['stval1']
|
||||
|
||||
|
||||
def test_information_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
dod.impl_set_information('testod', 'val1')
|
||||
st.impl_set_information('testst', 'val2')
|
||||
api = getapi(Config(od2))
|
||||
api.information.set('testcfgod', 'val3')
|
||||
assert api.option('od.dodval1').information.get('testod') == 'val1'
|
||||
assert api.option('od.dodval2').information.get('testod') == 'val1'
|
||||
assert api.option('od.dodval1.stval1').information.get('testst') == 'val2'
|
||||
assert api.option('od.dodval2.stval2').information.get('testst') == 'val2'
|
||||
assert api.information.get('testcfgod') == 'val3'
|
||||
#
|
||||
#
|
||||
#def test_consistency_dyndescription():
|
||||
# st = StrOption('st', '')
|
||||
# st2 = StrOption('st2', '')
|
||||
# dod = DynOptionDescription('dod', '', [st, st2], callback=return_list)
|
||||
# od = OptionDescription('od', '', [dod])
|
||||
# st.impl_add_consistency('not_equal', st2)
|
||||
# od2 = OptionDescription('od', '', [od])
|
||||
# api = getapi(Config(od2))
|
||||
# api.option('od.dodval1.stval1').value.set('yes')
|
||||
# raises(ValueError, "cfg.od.dodval1.st2val1 = 'yes'")
|
||||
# api.option('od.dodval2.stval2').value.set('yes')
|
||||
# raises(ValueError, "cfg.od.dodval2.st2val2 = 'yes'")
|
||||
# raises(ValueError, "cfg.od.dodval1.st2val1 = 'yes'")
|
||||
# del(cfg.od.dodval2.stval2)
|
||||
# raises(ValueError, "cfg.od.dodval1.st2val1 = 'yes'")
|
||||
# cfg.od.dodval2.st2val2 = 'yes'
|
||||
# raises(ValueError, "api.option('od.dodval2.stval2').value.set('yes')")
|
||||
|
||||
|
||||
def test_consistency_dyndescription_default():
|
||||
st = StrOption('st', '', 'yes')
|
||||
st2 = StrOption('st2', '')
|
||||
dod = DynOptionDescription('dod', '', [st, st2], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
st.impl_add_consistency('not_equal', st2)
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
api = getapi(Config(od2))
|
||||
print('===>', api.option('od.dodval1.st2val1').value.get())
|
||||
raises(ValueError, "api.option('od.dodval1.st2val1').value.get()")
|
||||
raises(ValueError, "api.option('od.dodval2.st2val2').value.get()")
|
||||
|
||||
|
||||
def test_consistency_dyndescription_default_multi2():
|
||||
st = StrOption('st', '', ['yes'], multi=True)
|
||||
st2 = StrOption('st2', '', ['yes'], multi=True)
|
||||
dod = DynOptionDescription('dod', '', [st, st2], callback=return_list)
|
||||
dod
|
||||
raises(ValueError, "st.impl_add_consistency('not_equal', st2)")
|
||||
|
||||
|
||||
def test_consistency_only_one_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
st
|
||||
st2 = StrOption('st2', '')
|
||||
DynOptionDescription('dod', '', [st2], callback=return_list)
|
||||
raises(ConfigError, "st.impl_add_consistency('not_equal', st2)")
|
||||
raises(ConfigError, "st2.impl_add_consistency('not_equal', st)")
|
||||
|
||||
|
||||
def test_consistency_became_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
st2 = StrOption('st2', '')
|
||||
st2.impl_add_consistency('not_equal', st)
|
||||
od = DynOptionDescription('dod', '', [st2], callback=return_list)
|
||||
od2 = OptionDescription('od', '', [od, st])
|
||||
od2
|
||||
raises(ConfigError, "c = Config(od2)")
|
||||
|
||||
|
||||
def test_consistency_became_dyndescription2():
|
||||
st = StrOption('st', '')
|
||||
st2 = StrOption('st2', '')
|
||||
st.impl_add_consistency('not_equal', st2)
|
||||
od = DynOptionDescription('dod', '', [st2], callback=return_list)
|
||||
od2 = OptionDescription('od', '', [od, st])
|
||||
od2
|
||||
raises(ConfigError, "c = Config(od2)")
|
||||
|
||||
|
||||
def test_consistency_external_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
st1 = StrOption('st1', '')
|
||||
st2 = StrOption('st2', '')
|
||||
dod = DynOptionDescription('dod', '', [st1, st2], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, st])
|
||||
od
|
||||
raises(ConfigError, "st.impl_add_consistency('not_equal', st2)")
|
||||
|
||||
|
||||
def test_consistency_notsame_dyndescription():
|
||||
st1 = StrOption('st1', '')
|
||||
st2 = StrOption('st2', '')
|
||||
dod = DynOptionDescription('dod', '', [st1, st2], callback=return_list)
|
||||
tst1 = StrOption('tst1', '')
|
||||
tst2 = StrOption('tst2', '')
|
||||
tdod = DynOptionDescription('tdod', '', [tst1, tst2], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, tdod])
|
||||
od
|
||||
raises(ConfigError, "st1.impl_add_consistency('not_equal', tst1)")
|
||||
|
||||
|
||||
def test_all_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
ip = IPOption('ip', '')
|
||||
network = NetworkOption('network', '')
|
||||
netmask = NetmaskOption('netmask', '')
|
||||
ch = ChoiceOption('ch', '', ('val1', 'val2', 'val3'))
|
||||
ch1 = ChoiceOption('ch1', '', return_list)
|
||||
boo = BoolOption('boo', '')
|
||||
intr = IntOption('intr', '')
|
||||
floa = FloatOption('floa', '')
|
||||
uni = UnicodeOption('uni', '')
|
||||
port = PortOption('port', '')
|
||||
broad = BroadcastOption('broad', '')
|
||||
domain = DomainnameOption('domain', '')
|
||||
email = EmailOption('email', '')
|
||||
url = URLOption('url', '')
|
||||
username = UsernameOption('username', '')
|
||||
filename = FilenameOption('filename', '')
|
||||
dod = DynOptionDescription('dod', '', [st, ip, network, netmask, ch, ch1,
|
||||
boo, intr, floa, uni, port, broad,
|
||||
domain, email, url, username,
|
||||
filename], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
api = getapi(Config(od))
|
||||
assert api.option('dodval1.stval1').value.get() is None
|
||||
assert api.option('dodval1.ipval1').value.get() is None
|
||||
assert api.option('dodval1.networkval1').value.get() is None
|
||||
assert api.option('dodval1.netmaskval1').value.get() is None
|
||||
assert api.option('dodval1.chval1').value.get() is None
|
||||
assert api.option('dodval1.ch1val1').value.get() is None
|
||||
assert api.option('dodval1.booval1').value.get() is None
|
||||
assert api.option('dodval1.intrval1').value.get() is None
|
||||
assert api.option('dodval1.floaval1').value.get() is None
|
||||
assert api.option('dodval1.unival1').value.get() is None
|
||||
assert api.option('dodval1.portval1').value.get() is None
|
||||
assert api.option('dodval1.broadval1').value.get() is None
|
||||
assert api.option('dodval1.domainval1').value.get() is None
|
||||
assert api.option('dodval1.emailval1').value.get() is None
|
||||
assert api.option('dodval1.urlval1').value.get() is None
|
||||
assert api.option('dodval1.usernameval1').value.get() is None
|
||||
assert api.option('dodval1.filenameval1').value.get() is None
|
||||
#
|
||||
api.option('dodval1.stval1').value.set("no")
|
||||
api.option('dodval1.ipval1').value.set("1.1.1.1")
|
||||
api.option('dodval1.networkval1').value.set("1.1.1.0")
|
||||
api.option('dodval1.netmaskval1').value.set("255.255.255.0")
|
||||
api.option('dodval1.chval1').value.set("val1")
|
||||
api.option('dodval1.ch1val1').value.set("val2")
|
||||
api.option('dodval1.booval1').value.set(True)
|
||||
api.option('dodval1.intrval1').value.set(1)
|
||||
api.option('dodval1.floaval1').value.set(0.1)
|
||||
api.option('dodval1.unival1').value.set("no")
|
||||
api.option('dodval1.portval1').value.set(80)
|
||||
api.option('dodval1.broadval1').value.set("1.1.1.255")
|
||||
api.option('dodval1.domainval1').value.set("test.com")
|
||||
api.option('dodval1.emailval1').value.set("test@test.com")
|
||||
api.option('dodval1.urlval1').value.set("http://test.com")
|
||||
api.option('dodval1.usernameval1').value.set("user1")
|
||||
api.option('dodval1.filenameval1').value.set("/tmp")
|
||||
assert api.option('dodval1.stval1').value.get() == "no"
|
||||
assert api.option('dodval1.ipval1').value.get() == "1.1.1.1"
|
||||
assert api.option('dodval1.networkval1').value.get() == "1.1.1.0"
|
||||
assert api.option('dodval1.netmaskval1').value.get() == "255.255.255.0"
|
||||
assert api.option('dodval1.chval1').value.get() == "val1"
|
||||
assert api.option('dodval1.ch1val1').value.get() == "val2"
|
||||
assert api.option('dodval1.booval1').value.get() is True
|
||||
assert api.option('dodval1.intrval1').value.get() == 1
|
||||
assert api.option('dodval1.floaval1').value.get() == 0.1
|
||||
assert api.option('dodval1.unival1').value.get() == u"no"
|
||||
assert api.option('dodval1.portval1').value.get() == 80
|
||||
assert api.option('dodval1.broadval1').value.get() == "1.1.1.255"
|
||||
assert api.option('dodval1.domainval1').value.get() == "test.com"
|
||||
assert api.option('dodval1.emailval1').value.get() == "test@test.com"
|
||||
assert api.option('dodval1.urlval1').value.get() == "http://test.com"
|
||||
assert api.option('dodval1.usernameval1').value.get() == "user1"
|
||||
assert api.option('dodval1.filenameval1').value.get() == "/tmp"
|
||||
assert api.option('dodval2.stval2').value.get() is None
|
||||
assert api.option('dodval2.ipval2').value.get() is None
|
||||
assert api.option('dodval2.networkval2').value.get() is None
|
||||
assert api.option('dodval2.netmaskval2').value.get() is None
|
||||
assert api.option('dodval2.chval2').value.get() is None
|
||||
assert api.option('dodval2.ch1val2').value.get() is None
|
||||
assert api.option('dodval2.booval2').value.get() is None
|
||||
assert api.option('dodval2.intrval2').value.get() is None
|
||||
assert api.option('dodval2.floaval2').value.get() is None
|
||||
assert api.option('dodval2.unival2').value.get() is None
|
||||
assert api.option('dodval2.portval2').value.get() is None
|
||||
assert api.option('dodval2.broadval2').value.get() is None
|
||||
assert api.option('dodval2.domainval2').value.get() is None
|
||||
assert api.option('dodval2.emailval2').value.get() is None
|
||||
assert api.option('dodval2.urlval2').value.get() is None
|
||||
assert api.option('dodval2.usernameval2').value.get() is None
|
||||
assert api.option('dodval2.filenameval2').value.get() is None
|
||||
#
|
||||
#
|
||||
#def test_consistency_ip_netmask_dyndescription():
|
||||
# a = IPOption('a', '')
|
||||
# b = NetmaskOption('b', '')
|
||||
# dod = DynOptionDescription('dod', '', [a, b], callback=return_list)
|
||||
# b.impl_add_consistency('ip_netmask', a)
|
||||
# od = OptionDescription('od', '', [dod])
|
||||
# c = Config(od)
|
||||
# c.dodval1.aval1 = '192.168.1.1'
|
||||
# c.dodval1.bval1 = '255.255.255.0'
|
||||
# c.dodval2.aval2 = '192.168.1.2'
|
||||
# c.dodval2.bval2 = '255.255.255.255'
|
||||
## c.dodval2.bval2 = '255.255.255.0'
|
||||
#
|
||||
#
|
||||
#def test_consistency_ip_in_network_dyndescription():
|
||||
# a = NetworkOption('a', '')
|
||||
# b = NetmaskOption('b', '')
|
||||
# c = IPOption('c', '')
|
||||
# dod = DynOptionDescription('dod', '', [a, b, c], callback=return_list)
|
||||
# c.impl_add_consistency('in_network', a, b)
|
||||
# od = OptionDescription('od', '', [dod])
|
||||
# cfg = Config(od)
|
||||
# cfg.dodval1.aval1 = '192.168.1.0'
|
||||
# cfg.dodval1.bval1 = '255.255.255.0'
|
||||
# cfg.dodval1.cval1 = '192.168.1.1'
|
||||
|
||||
|
||||
#def test_masterslaves_dyndescription():
|
||||
# st1 = StrOption('st1', "", multi=True)
|
||||
# st2 = StrOption('st2', "", multi=True)
|
||||
# stm = MasterSlaves('st1', '', [st1, st2])
|
||||
# #stm.impl_set_group_type(groups.master)
|
||||
# st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
# od = OptionDescription('od', '', [st])
|
||||
# od2 = OptionDescription('od', '', [od])
|
||||
# api = getapi(Config(od2))
|
||||
# print('--------------- 1')
|
||||
# owner = api.owner.get()
|
||||
# print('--------------- 2')
|
||||
# st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
|
||||
# print('--------------- 3')
|
||||
# st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
|
||||
# print('--------------- 4')
|
||||
# st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
|
||||
# print('--------------- 5')
|
||||
# st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
|
||||
# print('--------------- 6')
|
||||
# assert api.option.make_dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
|
||||
# print('--------------- 7')
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
# print('--------------- 8')
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
# print('--------------- 9')
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# print('--------------- 10')
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# print('--------------- 11')
|
||||
# assert cfg.getowner(st1val1) == owners.default
|
||||
# print('--------------- 12')
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# print('--------------- 13')
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# print('--------------- 14')
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
# print('--------------- 15')
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
# print('--------------- 16')
|
||||
# assert api.option.make_dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
|
||||
# print('--------------- 17')
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
# print('--------------- 18')
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == [None]
|
||||
# print('--------------- 19')
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# print('--------------- 20')
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# print('--------------- 21')
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# print('--------------- 22')
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# print('--------------- 23')
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# print('--------------- 24')
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
# print('--------------- 25')
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st1val1 = ['yes']
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == [None]
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st2val1 = ['no']
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == ['no']
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1, 0) == owner
|
||||
## assert cfg.getowner(st2val2) == owners.default
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st1val1.pop(0)
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
## assert cfg.getowner(st2val1) == owner
|
||||
## assert cfg.getowner(st2val2) == owners.default
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st1val1 = ['yes']
|
||||
# cfg.od.stval1.st1val1.st2val1 = ['yes']
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st2val1, 0) == owner
|
||||
# del(cfg.od.stval1.st1val1.st2val1)
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
## assert cfg.getowner(st2val1) == owners.default
|
||||
## assert cfg.getowner(st2val2) == owners.default
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st1val1 = ['yes']
|
||||
# cfg.od.stval1.st1val1.st2val1 = ['yes']
|
||||
# del(cfg.od.stval1.st1val1.st1val1)
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owners.default
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
#
|
||||
#def test_masterslaves_default_multi_dyndescription():
|
||||
# st1 = StrOption('st1', "", multi=True)
|
||||
# st2 = StrOption('st2', "", multi=True, default_multi='no')
|
||||
# stm = MasterSlaves('st1', '', [st1, st2])
|
||||
# #stm.impl_set_group_type(groups.master)
|
||||
# st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
# od = OptionDescription('od', '', [st])
|
||||
# od2 = OptionDescription('od', '', [od])
|
||||
# api = getapi(Config(od2))
|
||||
# owner = api.owner.get()
|
||||
# st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
|
||||
# st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
|
||||
# st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
|
||||
# st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owners.default
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
# cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == ['no']
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
#
|
||||
#def test_masterslaves_submulti_dyndescription():
|
||||
# st1 = StrOption('st1', "", multi=True)
|
||||
# st2 = StrOption('st2', "", multi=submulti)
|
||||
# stm = MasterSlaves('st1', '', [st1, st2])
|
||||
# #stm.impl_set_group_type(groups.master)
|
||||
# st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
# od = OptionDescription('od', '', [st])
|
||||
# od2 = OptionDescription('od', '', [od])
|
||||
# api = getapi(Config(od2))
|
||||
# owner = api.owner.get()
|
||||
# st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
|
||||
# st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
|
||||
# st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
|
||||
# st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owners.default
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
# cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == [[]]
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st2val1[0].append('no')
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == [['no']]
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1, 0) == owner
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
|
||||
|
||||
#def test_masterslaves_consistency_ip_dyndescription():
|
||||
# a = NetworkOption('net', '', multi=True)
|
||||
# b = NetmaskOption('mask', '', multi=True)
|
||||
# c = BroadcastOption('broad', '', multi=True)
|
||||
# b.impl_add_consistency('network_netmask', a)
|
||||
# c.impl_add_consistency('broadcast', a, b)
|
||||
# dod = DynOptionDescription('net', '', [a, b, c], callback=return_list)
|
||||
# dod.impl_set_group_type(groups.master)
|
||||
# od = OptionDescription('od', '', [dod])
|
||||
# cfg = Config(od)
|
||||
# cfg.netval1.netval1 = ['192.168.1.0']
|
||||
# cfg.netval1.maskval1 = ['255.255.255.0']
|
||||
# cfg.netval1.broadval1 = ['192.168.1.255']
|
||||
#
|
||||
# cfg.netval1.netval1 = ['192.168.1.0', '192.168.2.128']
|
||||
# cfg.netval1.maskval1 = ['255.255.255.0', '255.255.255.128']
|
||||
# cfg.netval1.broadval1 = ['192.168.1.255', '192.168.2.255']
|
||||
# cfg.netval1.broadval1[1] = '192.168.2.255'
|
||||
# #
|
||||
# assert cfg.netval1.netval1 == ['192.168.1.0', '192.168.2.128']
|
||||
# assert cfg.netval1.maskval1 == ['255.255.255.0', '255.255.255.128']
|
||||
# assert cfg.netval1.broadval1 == ['192.168.1.255', '192.168.2.255']
|
||||
# assert cfg.netval2.netval2 == []
|
||||
# assert cfg.netval2.maskval2 == []
|
||||
# assert cfg.netval2.broadval2 == []
|
||||
|
||||
|
||||
#def test_masterslaves_consistency_ip_dyndescription_propertyerror():
|
||||
# a = NetworkOption('net', '', multi=True)
|
||||
# b = NetmaskOption('mask', '', multi=True, properties=('mandatory',))
|
||||
# c = BroadcastOption('broad', '', multi=True)
|
||||
# b.impl_add_consistency('network_netmask', a)
|
||||
# c.impl_add_consistency('broadcast', a, b)
|
||||
# dod = DynOptionDescription('net', '', [a, b, c], callback=return_list)
|
||||
# dod.impl_set_group_type(groups.master)
|
||||
# od = OptionDescription('od', '', [dod])
|
||||
# cfg = Config(od)
|
||||
# api.property.read_write()
|
||||
# cfg.netval1.netval1 = ['192.168.1.0']
|
||||
# api.property.read_only()
|
||||
# raises(PropertiesOptionError, "cfg.netval1.netval1")
|
||||
#
|
||||
#
|
||||
#def test_masterslaves_callback_dyndescription():
|
||||
# st1 = StrOption('st1', "", multi=True)
|
||||
# st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'value': ((st1, False),)})
|
||||
# stm = MasterSlaves('st1', '', [st1, st2])
|
||||
# #stm.impl_set_group_type(groups.master)
|
||||
# st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
# od = OptionDescription('od', '', [st])
|
||||
# od2 = OptionDescription('od', '', [od])
|
||||
# api = getapi(Config(od2))
|
||||
# owner = api.owner.get()
|
||||
# st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
|
||||
# st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
|
||||
# st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
|
||||
# st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
|
||||
# assert api.option.make_dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owners.default
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
# assert api.option.make_dict() == {'od.stval1.st1val1.st2val1': ['yes'], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == ['yes']
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st2val1 = ['no']
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == ['no']
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1, 0) == owner
|
||||
## assert cfg.getowner(st2val2) == owners.default
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st1val1.pop(0)
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
## assert cfg.getowner(st2val1) == owner
|
||||
## assert cfg.getowner(st2val2) == owners.default
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st1val1 = ['yes']
|
||||
# cfg.od.stval1.st1val1.st2val1 = ['yes']
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st2val1, 0) == owner
|
||||
# del(cfg.od.stval1.st1val1.st2val1)
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st1val1 = ['yes']
|
||||
# cfg.od.stval1.st1val1.st2val1 = ['yes']
|
||||
# del(cfg.od.stval1.st1val1.st1val1)
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.getowner(st1val1) == owners.default
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st2val1 = []
|
||||
# cfg.od.stval1.st1val1.st1val1 = ['yes']
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == ['yes']
|
||||
#
|
||||
#
|
||||
#def test_masterslaves_callback_value_dyndescription():
|
||||
# st1 = StrOption('st1', "", multi=True)
|
||||
# st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'value': ('val',)})
|
||||
# stm = MasterSlaves('st1', '', [st1, st2])
|
||||
# #stm.impl_set_group_type(groups.master)
|
||||
# st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
# od = OptionDescription('od', '', [st])
|
||||
# od2 = OptionDescription('od', '', [od])
|
||||
# api = getapi(Config(od2))
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
# cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
# assert cfg.od.stval1.st1val1.st2val1[0] == 'val'
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == ['val']
|
||||
#
|
||||
#
|
||||
#def test_masterslaves_callback_nomulti_dyndescription():
|
||||
# v1 = StrOption('v1', '', "val")
|
||||
# st1 = StrOption('st1', "", multi=True)
|
||||
# st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'': ((v1, False),)})
|
||||
# stm = MasterSlaves('st1', '', [st1, st2])
|
||||
# #stm.impl_set_group_type(groups.master)
|
||||
# st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
# od = OptionDescription('od', '', [st])
|
||||
# od2 = OptionDescription('od', '', [od, v1])
|
||||
# api = getapi(Config(od2))
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
# cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == ['val']
|
||||
#
|
||||
#
|
||||
#def test_masterslaves_callback_samegroup_dyndescription():
|
||||
# st1 = StrOption('st1', "", multi=True)
|
||||
# st2 = StrOption('st2', "", multi=True)
|
||||
# st3 = StrOption('st3', "", multi=True, callback=return_dynval, callback_params={'': ((st2, False),)})
|
||||
# stm = MasterSlaves('st1', '', [st1, st2, st3])
|
||||
# #stm.impl_set_group_type(groups.master)
|
||||
# st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
# od = OptionDescription('od', '', [st])
|
||||
# od2 = OptionDescription('od', '', [od])
|
||||
# api = getapi(Config(od2))
|
||||
# owner = api.owner.get()
|
||||
# st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
|
||||
# st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
|
||||
# st3val1 = cfg.unwrap_from_path('od.stval1.st1val1.st3val1')
|
||||
# st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
|
||||
# st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
|
||||
# st3val2 = cfg.unwrap_from_path('od.stval2.st1val2.st3val2')
|
||||
# assert api.option.make_dict() == {'od.stval1.st1val1.st1val1': [],
|
||||
# 'od.stval1.st1val1.st2val1': [],
|
||||
# 'od.stval1.st1val1.st3val1': [],
|
||||
# 'od.stval2.st1val2.st1val2': [],
|
||||
# 'od.stval2.st1val2.st2val2': [],
|
||||
# 'od.stval2.st1val2.st3val2': []}
|
||||
# assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
# assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
# assert cfg.od.stval1.st1val1.st3val1 == []
|
||||
# assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
# assert cfg.od.stval2.st1val2.st3val2 == []
|
||||
# assert cfg.getowner(st1val1) == owners.default
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
# assert cfg.getowner(st3val1) == owners.default
|
||||
# assert cfg.getowner(st3val2) == owners.default
|
||||
# ##
|
||||
# cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
# assert api.option.make_dict() == {'od.stval1.st1val1.st1val1': ['yes'],
|
||||
# 'od.stval1.st1val1.st2val1': [None],
|
||||
# 'od.stval1.st1val1.st3val1': [None],
|
||||
# 'od.stval2.st1val2.st1val2': [],
|
||||
# 'od.stval2.st1val2.st2val2': [],
|
||||
# 'od.stval2.st1val2.st3val2': []}
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# assert cfg.getowner(st2val1) == owners.default
|
||||
# assert cfg.getowner(st2val2) == owners.default
|
||||
# assert cfg.getowner(st3val1) == owners.default
|
||||
# assert cfg.getowner(st3val2) == owners.default
|
||||
# #
|
||||
# cfg.od.stval1.st1val1.st2val1[0] = 'yes'
|
||||
# assert api.option.make_dict() == {'od.stval1.st1val1.st1val1': ['yes'],
|
||||
# 'od.stval1.st1val1.st2val1': ['yes'],
|
||||
# 'od.stval1.st1val1.st3val1': ['yes'],
|
||||
# 'od.stval2.st1val2.st1val2': [],
|
||||
# 'od.stval2.st1val2.st2val2': [],
|
||||
# 'od.stval2.st1val2.st3val2': []}
|
||||
# assert cfg.getowner(st1val1) == owner
|
||||
# assert cfg.getowner(st2val1, 0) == owner
|
||||
# assert cfg.getowner(st3val1, 0) == owners.default
|
||||
# assert cfg.getowner(st1val2) == owners.default
|
||||
# #assert cfg.getowner(st2val2) == owners.default
|
||||
# #assert cfg.getowner(st3val2) == owners.default
|
||||
|
||||
|
||||
def test_invalid_conflict_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
dodinvalid = StrOption('dodinvalid', '')
|
||||
dod, dodinvalid
|
||||
raises(ConflictError, "OptionDescription('od', '', [dod, dodinvalid])")
|
||||
|
||||
|
||||
def test_invalid_subod_dyndescription():
|
||||
st2 = StrOption('st2', '')
|
||||
od1 = OptionDescription('od1', '', [st2])
|
||||
od1
|
||||
raises(ConfigError, "DynOptionDescription('dod', '', [od1], callback=return_list)")
|
||||
|
||||
|
||||
def test_invalid_subdynod_dyndescription():
|
||||
st2 = StrOption('st2', '')
|
||||
od1 = DynOptionDescription('od1', '', [st2], callback=return_list)
|
||||
od1
|
||||
raises(ConfigError, "DynOptionDescription('dod', '', [od1], callback=return_list)")
|
||||
|
||||
|
||||
def test_invalid_symlink_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
st2 = SymLinkOption('st2', st)
|
||||
st2
|
||||
raises(ConfigError, "DynOptionDescription('dod', '', [st, st2], callback=return_list)")
|
||||
|
||||
|
||||
def test_nocallback_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
st2 = StrOption('st2', '')
|
||||
st, st2
|
||||
raises(ConfigError, "DynOptionDescription('dod', '', [st, st2])")
|
||||
|
||||
|
||||
#def test_invalid_samevalue_dyndescription():
|
||||
# st = StrOption('st', '')
|
||||
# dod = DynOptionDescription('dod', '', [st], callback=return_same_list)
|
||||
# od = OptionDescription('od', '', [dod])
|
||||
# cfg = Config(od)
|
||||
# cfg
|
||||
# raises(ConfigError, "print(cfg)")
|
||||
#
|
||||
#
|
||||
#def test_invalid_name_dyndescription():
|
||||
# st = StrOption('st', '')
|
||||
# dod = DynOptionDescription('dod', '', [st], callback=return_wrong_list)
|
||||
# od = OptionDescription('od', '', [dod])
|
||||
# cfg = Config(od)
|
||||
# cfg
|
||||
# raises(ValueError, "print(cfg)")
|
221
test/new_api/test_freeze.py
Normal file
221
test/new_api/test_freeze.py
Normal file
@ -0,0 +1,221 @@
|
||||
# coding: utf-8
|
||||
"frozen and hidden values"
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.setting import owners, groups
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config, \
|
||||
getapi
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
|
||||
|
||||
#____________________________________________________________
|
||||
#freeze
|
||||
def make_description_freeze():
|
||||
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")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=[True], multi=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value',),
|
||||
requires=({'option': booloption, 'expected': True, 'action': 'hidden'},))
|
||||
wantref2_option = BoolOption('wantref2', 'Test requires', default=False, properties=('force_store_value', 'hidden'))
|
||||
wantref3_option = BoolOption('wantref3', 'Test requires', default=[False], multi=True, properties=('force_store_value',))
|
||||
st2 = SymLinkOption('st2', wantref3_option)
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=({'option': booloption, 'expected': True, 'action': 'hidden'},))
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, wantref2_option, wantref3_option, st2, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
def return_val():
|
||||
return 1
|
||||
|
||||
|
||||
def return_val2(value):
|
||||
return value
|
||||
|
||||
|
||||
def return_val3(context, value):
|
||||
return value
|
||||
|
||||
|
||||
def test_freeze_whole_config():
|
||||
descr = make_description_freeze()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.add('everything_frozen')
|
||||
assert api.option('gc.dummy').value.get() is False
|
||||
prop = []
|
||||
try:
|
||||
api.option('gc.dummy').value.set(True)
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
assert api.option('gc.dummy').value.get() is False
|
||||
#
|
||||
api.property.pop('everything_frozen')
|
||||
api.option('gc.dummy').value.set(True)
|
||||
assert api.option('gc.dummy').value.get() is True
|
||||
#
|
||||
api.property.add('everything_frozen')
|
||||
owners.addowner("everythingfrozen")
|
||||
prop = []
|
||||
try:
|
||||
api.option('gc.dummy').owner.set('everythingfrozen')
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
||||
|
||||
def test_freeze_one_option():
|
||||
"freeze an option "
|
||||
descr = make_description_freeze()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
#freeze only one option
|
||||
api.option('gc.dummy').property.add('frozen')
|
||||
assert api.option('gc.dummy').value.get() is False
|
||||
prop = []
|
||||
try:
|
||||
api.option('gc.dummy').value.set(True)
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
||||
|
||||
def test_frozen_value():
|
||||
"setattr a frozen value at the config level"
|
||||
s = StrOption("string", "", default="string")
|
||||
descr = OptionDescription("options", "", [s])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.add('frozen')
|
||||
api.option('string').property.add('frozen')
|
||||
prop = []
|
||||
try:
|
||||
api.option('string').value.set('egg')
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
||||
|
||||
def test_freeze():
|
||||
"freeze a whole configuration object"
|
||||
descr = make_description_freeze()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.add('frozen')
|
||||
api.option('gc.name').property.add('frozen')
|
||||
prop = []
|
||||
try:
|
||||
api.option('gc.name').value.set('framework')
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
||||
|
||||
def test_freeze_multi():
|
||||
descr = make_description_freeze()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
api.property.add('frozen')
|
||||
api.option('boolop').property.add('frozen')
|
||||
prop = []
|
||||
try:
|
||||
api.option('boolop').value.set([True])
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'frozen' in prop
|
||||
|
||||
|
||||
def test_force_store_value():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
api = getapi(conf)
|
||||
assert api.value.get() == {'wantref': ('forced', False),
|
||||
'wantref2': ('forced', False),
|
||||
'wantref3': ('forced', (False,))}
|
||||
api.option('wantref').value.set(True)
|
||||
assert api.value.get() == {'wantref': ('user', True),
|
||||
'wantref2': ('forced', False),
|
||||
'wantref3': ('forced', (False,))}
|
||||
api.option('wantref').value.reset()
|
||||
assert api.value.get() == {'wantref': ('forced', False),
|
||||
'wantref2': ('forced', False),
|
||||
'wantref3': ('forced', (False,))}
|
||||
|
||||
|
||||
def test_force_store_value_no_requirement():
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
try:
|
||||
BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=({'option': booloption, 'expected': True, 'action': 'force_store_value'},))
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_force_store_value_masterslaves_slave():
|
||||
b = IntOption('int', 'Test int option', multi=True)
|
||||
c = StrOption('str', 'Test string option', multi=True, properties=('force_store_value',))
|
||||
descr = MasterSlaves("int", "", [b, c])
|
||||
raises(ConfigError, "conf = Config(descr)")
|
||||
|
||||
|
||||
#def test_force_store_value_masterslaves():
|
||||
# b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
|
||||
# c = StrOption('str', 'Test string option', multi=True)
|
||||
# descr = MasterSlaves("int", "", [b, c])
|
||||
# api = getapi(Config(descr))
|
||||
# assert api.value.get() == {'int': ('forced', ())}
|
||||
|
||||
|
||||
def test_force_store_value_masterslaves_sub():
|
||||
b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
|
||||
c = StrOption('str', 'Test string option', multi=True)
|
||||
descr = MasterSlaves("int", "", [b, c])
|
||||
odr = OptionDescription('odr', '', [descr])
|
||||
api = getapi(Config(odr))
|
||||
assert api.value.get() == {'int.int': ('forced', ())}
|
||||
|
||||
|
||||
def test_force_store_value_callback():
|
||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val)
|
||||
descr = OptionDescription("int", "", [b])
|
||||
api = getapi(Config(descr))
|
||||
assert api.value.get() == {'int': ('forced', 1)}
|
||||
|
||||
|
||||
def test_force_store_value_callback_params():
|
||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': (2,)})
|
||||
descr = OptionDescription("int", "", [b])
|
||||
api = getapi(Config(descr))
|
||||
assert api.value.get() == {'int': ('forced', 2)}
|
||||
|
||||
|
||||
def test_force_store_value_callback_params_2():
|
||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val3, callback_params={'': ((None,),), 'value': (2,)})
|
||||
descr = OptionDescription("int", "", [b])
|
||||
api = getapi(Config(descr))
|
||||
assert api.value.get() == {'int': ('forced', 2)}
|
||||
|
||||
|
||||
def test_force_store_value_callback_params_with_opt():
|
||||
a = IntOption('val1', "", 2)
|
||||
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': ((a, False),)})
|
||||
descr = OptionDescription("int", "", [a, b])
|
||||
api = getapi(Config(descr))
|
||||
assert api.value.get() == {'int': ('forced', 2)}
|
575
test/new_api/test_mandatory.py
Normal file
575
test/new_api/test_mandatory.py
Normal file
@ -0,0 +1,575 @@
|
||||
# coding: utf-8
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
from tiramisu.config import Config
|
||||
from tiramisu import IntOption, StrOption, UnicodeOption, OptionDescription, \
|
||||
SymLinkOption, MasterSlaves, getapi, undefined
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.setting import groups
|
||||
|
||||
|
||||
def make_description():
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
properties=('mandatory', ))
|
||||
stroption1 = StrOption('str1', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption2 = UnicodeOption('unicode2', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
||||
properties=('mandatory', ))
|
||||
stroption4 = StrOption('str4', 'Test string option', multi=True,
|
||||
properties=('mandatory', ), allow_empty_list=True)
|
||||
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, stroption4])
|
||||
return descr
|
||||
|
||||
|
||||
def return_value(value):
|
||||
return value
|
||||
|
||||
|
||||
def make_description2():
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
properties=('mandatory', ))
|
||||
stroption1 = StrOption('str1', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption2 = SymLinkOption('unicode2', stroption1)
|
||||
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
||||
properties=('mandatory', ))
|
||||
unicode1 = UnicodeOption('unicode1', 'Test string option', callback=return_value, callback_params={'': ((stroption, False),)}, properties=('mandatory', ))
|
||||
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1])
|
||||
return descr
|
||||
|
||||
|
||||
def make_description_sym():
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
properties=('mandatory', ))
|
||||
stroption1 = StrOption('str1', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption2 = SymLinkOption('unicode2', stroption1)
|
||||
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
||||
properties=('mandatory', ))
|
||||
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
|
||||
return descr
|
||||
|
||||
|
||||
def make_description3():
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
properties=('mandatory', ))
|
||||
stroption1 = StrOption('str1', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption2 = SymLinkOption('unicode2', stroption1)
|
||||
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
||||
properties=('mandatory', ))
|
||||
unicode1 = UnicodeOption('unicode1', 'Test string option', callback=return_value, callback_params={'': ((stroption, False),)}, properties=('mandatory', ))
|
||||
int1 = IntOption('int1', '', callback=return_value, callback_params={'': ((stroption, False),)}, properties=('mandatory', ))
|
||||
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1, int1])
|
||||
return descr
|
||||
|
||||
|
||||
def make_description4():
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
properties=('mandatory', ))
|
||||
stroption1 = StrOption('str1', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption2 = UnicodeOption('unicode2', 'Test string option',
|
||||
properties=('mandatory', ))
|
||||
stroption3 = StrOption('str3', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
|
||||
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
|
||||
return descr
|
||||
|
||||
|
||||
def test_mandatory_ro():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
api.property.read_write()
|
||||
api.option('str1').value.set('yes')
|
||||
api.property.read_only()
|
||||
assert api.option('str1').value.get() == 'yes'
|
||||
|
||||
|
||||
def test_mandatory_rw():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
#not mandatory in rw
|
||||
api.option('str1').value.get()
|
||||
api.option('str1').value.set('yes')
|
||||
assert api.option('str1').value.get() == 'yes'
|
||||
|
||||
|
||||
def test_mandatory_default():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
#not mandatory in rw
|
||||
api.option('str').value.get()
|
||||
api.property.read_write()
|
||||
api.option('str').value.set('yes')
|
||||
api.property.read_only()
|
||||
api.option('str').value.get()
|
||||
api.property.read_write()
|
||||
api.option('str').value.set(None)
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_delete():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
api.option('str').value.get()
|
||||
try:
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
api.property.read_write()
|
||||
api.option('str1').value.set('yes')
|
||||
api.property.read_only()
|
||||
assert api.option('str1').value.get() == 'yes'
|
||||
api.property.pop('everything_frozen')
|
||||
prop = []
|
||||
try:
|
||||
api.option('str1').value.reset()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
api.option('str').value.reset()
|
||||
|
||||
assert api.option('str1').value.get() == 'yes'
|
||||
|
||||
|
||||
#valeur vide : None, '', u'', ...
|
||||
def test_mandatory_none():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str1').value.set(None)
|
||||
assert api.option('str1').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_empty():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str1').value.set('')
|
||||
assert api.option('str1').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_multi_none():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str3').value.set([None])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
api.property.read_write()
|
||||
api.option('str3').value.set(['yes', None])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_multi_empty():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str3').value.set([])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('str3').value.set([''])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('str3').value.set(['yes', ''])
|
||||
assert api.option('str3').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str3').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_multi_empty_allow_empty_list():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str4').value.set([])
|
||||
assert api.option('str4').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
api.option('str4').value.get()
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('str4').value.set([''])
|
||||
assert api.option('str4').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str4').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('str4').value.set(['yes', ''])
|
||||
assert api.option('str4').owner.get() == 'user'
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('str4').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_multi_append():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str3').value.set(['yes'])
|
||||
api.property.read_write()
|
||||
api.option('str3').value.get().append(None)
|
||||
|
||||
|
||||
def test_mandatory_disabled():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str1').value.get()
|
||||
api.option('str1').property.add('disabled')
|
||||
api.property.read_only()
|
||||
pop = []
|
||||
try:
|
||||
api.option('str1').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert set(prop) == set(['disabled', 'mandatory'])
|
||||
|
||||
|
||||
def test_mandatory_unicode():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('unicode2').value.get()
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('unicode2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
api.property.read_write()
|
||||
api.option('unicode2').value.set('')
|
||||
api.property.read_only()
|
||||
prop = []
|
||||
try:
|
||||
api.option('unicode2').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
|
||||
|
||||
def test_mandatory_warnings_ro():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_only()
|
||||
proc = []
|
||||
try:
|
||||
api.option('str').value.get()
|
||||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
api.property.read_write()
|
||||
api.option('str').value.set('a')
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
|
||||
|
||||
def test_mandatory_warnings_rw():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
api.option('str').value.set('a')
|
||||
assert list(api.value.mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
|
||||
|
||||
def test_mandatory_warnings_disabled():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
api.option('str').property.add('disabled')
|
||||
assert set(api.value.mandatory_warnings()) == {'str1', 'unicode2', 'str3'}
|
||||
|
||||
|
||||
def test_mandatory_warnings_hidden():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.permissive.set(('hidden',))
|
||||
api.option('str').value.get()
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
api.option('str').property.add('hidden')
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
|
||||
|
||||
def test_mandatory_warnings_frozen():
|
||||
descr = make_description()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
api.option('str').property.add('frozen')
|
||||
api.property.read_only()
|
||||
assert set(api.value.mandatory_warnings()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
|
||||
|
||||
def test_mandatory_master():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
|
||||
properties=('mandatory', ))
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
||||
multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
|
||||
|
||||
def test_mandatory_warnings_master():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
|
||||
properties=('mandatory', ))
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
||||
multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
|
||||
|
||||
def test_mandatory_master_empty():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
||||
multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
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.netmask_admin_eth0', 0).value.get() == None
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
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.netmask_admin_eth0', 0).value.get() == None
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()")
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
api.property.read_write()
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip2'])
|
||||
api.property.read_only()
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.reset()")
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
|
||||
|
||||
def test_mandatory_warnings_master_empty():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
||||
multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_write()
|
||||
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.netmask_admin_eth0', 0).value.get() == None
|
||||
assert list(api.value.mandatory_warnings()) == ['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.set([''])
|
||||
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 list(api.value.mandatory_warnings()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
assert list(api.value.mandatory_warnings()) == []
|
||||
|
||||
|
||||
def test_mandatory_slave():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
||||
multi=True, properties=('mandatory', ))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('')
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
|
||||
#
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('ip')
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
|
||||
|
||||
|
||||
def test_mandatory_warnings_slave():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau",
|
||||
multi=True, properties=('mandatory', ))
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
#interface1.impl_set_group_type(groups.master)
|
||||
descr = OptionDescription('o', '', [interface1])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
api.property.read_write()
|
||||
assert list(api.value.mandatory_warnings()) == []
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
assert list(api.value.mandatory_warnings()) == ['ip_admin_eth0.netmask_admin_eth0']
|
||||
|
||||
|
||||
def test_mandatory_warnings_symlink():
|
||||
descr = make_description_sym()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'str3']
|
||||
api.option('str').property.add('frozen')
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'str3']
|
||||
|
||||
|
||||
#def test_mandatory_warnings_validate():
|
||||
# descr = make_description3()
|
||||
# api = getapi(Config(descr))
|
||||
# api.option('str').value.set('')
|
||||
# raises(ValueError, "list(api.value.mandatory_warnings())")
|
||||
# api.option('str').value.set('test')
|
||||
# raises(ValueError, "list(api.value.mandatory_warnings())")
|
||||
|
||||
|
||||
def test_mandatory_warnings_validate_empty():
|
||||
descr = make_description2()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'str3', 'unicode1']
|
||||
|
||||
|
||||
def test_mandatory_warnings_requires():
|
||||
descr = make_description4()
|
||||
api = getapi(Config(descr))
|
||||
api.option('str').value.set('')
|
||||
api.property.read_write()
|
||||
api.option('str').value.get()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2']
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['str', 'str1', 'unicode2']
|
||||
api.property.read_write()
|
||||
api.option('str').value.set('yes')
|
||||
assert list(api.value.mandatory_warnings()) == ['str1', 'unicode2', 'str3']
|
||||
|
||||
|
||||
def test_mandatory_od_disabled():
|
||||
descr = make_description()
|
||||
descr = OptionDescription('od', '', [descr])
|
||||
api = getapi(Config(descr))
|
||||
api.property.read_only()
|
||||
assert list(api.value.mandatory_warnings()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
|
||||
api.option('tiram').property.add('disabled')
|
||||
assert list(api.value.mandatory_warnings()) == []
|
Reference in New Issue
Block a user