help in API became usable
This commit is contained in:
parent
fbff3d9ced
commit
290f687f6c
12 changed files with 716 additions and 620 deletions
|
@ -136,14 +136,17 @@ def test_information_config():
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
string = 'some informations'
|
string = 'some informations'
|
||||||
#
|
#
|
||||||
|
assert list(config.information.list()) == []
|
||||||
config.information.set('info', string)
|
config.information.set('info', string)
|
||||||
assert config.information.get('info') == string
|
assert config.information.get('info') == string
|
||||||
|
assert list(config.information.list()) == ['info']
|
||||||
#
|
#
|
||||||
raises(ValueError, "config.information.get('noinfo')")
|
raises(ValueError, "config.information.get('noinfo')")
|
||||||
assert config.information.get('noinfo', 'default') == 'default'
|
assert config.information.get('noinfo', 'default') == 'default'
|
||||||
config.information.reset('info')
|
config.information.reset('info')
|
||||||
raises(ValueError, "config.information.get('info')")
|
raises(ValueError, "config.information.get('info')")
|
||||||
raises(ValueError, "config.information.reset('noinfo')")
|
raises(ValueError, "config.information.reset('noinfo')")
|
||||||
|
assert list(config.information.list()) == []
|
||||||
|
|
||||||
|
|
||||||
def test_information_option():
|
def test_information_option():
|
||||||
|
@ -151,14 +154,17 @@ def test_information_option():
|
||||||
config = Config(descr)
|
config = Config(descr)
|
||||||
string = 'some informations'
|
string = 'some informations'
|
||||||
#
|
#
|
||||||
|
list(config.option('gc.name').information.list()) == []
|
||||||
config.option('gc.name').information.set('info', string)
|
config.option('gc.name').information.set('info', string)
|
||||||
assert config.option('gc.name').information.get('info') == string
|
assert config.option('gc.name').information.get('info') == string
|
||||||
|
list(config.option('gc.name').information.list()) == ['info']
|
||||||
#
|
#
|
||||||
raises(ValueError, "config.option('gc.name').information.get('noinfo')")
|
raises(ValueError, "config.option('gc.name').information.get('noinfo')")
|
||||||
assert config.option('gc.name').information.get('noinfo', 'default') == 'default'
|
assert config.option('gc.name').information.get('noinfo', 'default') == 'default'
|
||||||
config.option('gc.name').information.reset('info')
|
config.option('gc.name').information.reset('info')
|
||||||
raises(ValueError, "config.option('gc.name').information.get('info')")
|
raises(ValueError, "config.option('gc.name').information.get('info')")
|
||||||
raises(ValueError, "config.option('gc.name').information.reset('noinfo')")
|
raises(ValueError, "config.option('gc.name').information.reset('noinfo')")
|
||||||
|
list(config.option('gc.name').information.list()) == []
|
||||||
#
|
#
|
||||||
assert config.option('wantref').information.get('info') == 'default value'
|
assert config.option('wantref').information.get('info') == 'default value'
|
||||||
config.option('wantref').information.set('info', 'default value')
|
config.option('wantref').information.set('info', 'default value')
|
||||||
|
|
|
@ -149,14 +149,14 @@ def test_find_in_config():
|
||||||
conf = Config(descr)
|
conf = Config(descr)
|
||||||
conf.property.read_only()
|
conf.property.read_only()
|
||||||
conf.permissive.set(frozenset(['hidden']))
|
conf.permissive.set(frozenset(['hidden']))
|
||||||
ret = conf.option.find('dummy')
|
ret = list(conf.option.find('dummy'))
|
||||||
assert len(ret) == 1
|
assert len(ret) == 1
|
||||||
_is_same_opt(ret[0].option.get(), conf.option('gc.dummy').option.get())
|
_is_same_opt(ret[0].option.get(), conf.option('gc.dummy').option.get())
|
||||||
#
|
#
|
||||||
ret = conf.option.find('dummy', first=True).option.get()
|
ret = conf.option.find('dummy', first=True).option.get()
|
||||||
_is_same_opt(ret, conf.option('gc.dummy').option.get())
|
_is_same_opt(ret, conf.option('gc.dummy').option.get())
|
||||||
#
|
#
|
||||||
ret = conf.option.find('float')
|
ret = list(conf.option.find('float'))
|
||||||
assert len(ret) == 2
|
assert len(ret) == 2
|
||||||
_is_same_opt(ret[0].option.get(), conf.option('gc.float').option.get())
|
_is_same_opt(ret[0].option.get(), conf.option('gc.float').option.get())
|
||||||
_is_same_opt(ret[1].option.get(), conf.option('float').option.get())
|
_is_same_opt(ret[1].option.get(), conf.option('float').option.get())
|
||||||
|
@ -177,48 +177,49 @@ def test_find_in_config():
|
||||||
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.name'))
|
#_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'))
|
#_is_same_opt(conf.find_first(byvalue='ref'), conf.unwrap_from_path('gc.name'))
|
||||||
#
|
#
|
||||||
ret = conf.option.find('prop')
|
ret = list(conf.option.find('prop'))
|
||||||
assert len(ret) == 1
|
assert len(ret) == 1
|
||||||
_is_same_opt(ret[0].option.get(), conf.option('gc.prop').option.get())
|
_is_same_opt(ret[0].option.get(), conf.option('gc.prop').option.get())
|
||||||
#
|
#
|
||||||
ret = conf.option.find('prop', value=None)
|
ret = list(conf.option.find('prop', value=None))
|
||||||
ret = conf.option.find('prop')
|
assert len(ret) == 1
|
||||||
|
ret = list(conf.option.find('prop'))
|
||||||
assert len(ret) == 1
|
assert len(ret) == 1
|
||||||
_is_same_opt(ret[0].option.get(), conf.option('gc.prop').option.get())
|
_is_same_opt(ret[0].option.get(), conf.option('gc.prop').option.get())
|
||||||
#
|
#
|
||||||
conf.property.read_write()
|
conf.property.read_write()
|
||||||
raises(AttributeError, "assert conf.option.find('prop').option.get()")
|
raises(AttributeError, "assert conf.option.find('prop').option.get()")
|
||||||
ret = conf.unrestraint.option.find(name='prop')
|
ret = list(conf.unrestraint.option.find(name='prop'))
|
||||||
assert len(ret) == 2
|
assert len(ret) == 2
|
||||||
_is_same_opt(ret[0].option.get(), conf.unrestraint.option('gc.gc2.prop').option.get())
|
_is_same_opt(ret[0].option.get(), conf.unrestraint.option('gc.gc2.prop').option.get())
|
||||||
_is_same_opt(ret[1].option.get(), conf.forcepermissive.option('gc.prop').option.get())
|
_is_same_opt(ret[1].option.get(), conf.forcepermissive.option('gc.prop').option.get())
|
||||||
#
|
#
|
||||||
ret = conf.forcepermissive.option.find('prop')
|
ret = list(conf.forcepermissive.option.find('prop'))
|
||||||
assert len(ret) == 1
|
assert len(ret) == 1
|
||||||
_is_same_opt(ret[0].option.get(), conf.forcepermissive.option('gc.prop').option.get())
|
_is_same_opt(ret[0].option.get(), conf.forcepermissive.option('gc.prop').option.get())
|
||||||
#
|
#
|
||||||
_is_same_opt(conf.forcepermissive.option.find('prop', first=True).option.get(), conf.forcepermissive.option('gc.prop').option.get())
|
_is_same_opt(conf.forcepermissive.option.find('prop', first=True).option.get(), conf.forcepermissive.option('gc.prop').option.get())
|
||||||
# combinaison of filters
|
# combinaison of filters
|
||||||
ret = conf.unrestraint.option.find('prop', type=BoolOption)
|
ret = list(conf.unrestraint.option.find('prop', type=BoolOption))
|
||||||
assert len(ret) == 1
|
assert len(ret) == 1
|
||||||
_is_same_opt(ret[0].option.get(), conf.unrestraint.option('gc.gc2.prop').option.get())
|
_is_same_opt(ret[0].option.get(), conf.unrestraint.option('gc.gc2.prop').option.get())
|
||||||
_is_same_opt(conf.unrestraint.option.find('prop', type=BoolOption, first=True).option.get(), conf.unrestraint.option('gc.gc2.prop').option.get())
|
_is_same_opt(conf.unrestraint.option.find('prop', type=BoolOption, first=True).option.get(), conf.unrestraint.option('gc.gc2.prop').option.get())
|
||||||
#
|
#
|
||||||
ret = conf.option.find('dummy', value=False)
|
ret = list(conf.option.find('dummy', value=False))
|
||||||
assert len(ret) == 1
|
assert len(ret) == 1
|
||||||
_is_same_opt(ret[0].option.get(), conf.option('gc.dummy').option.get())
|
_is_same_opt(ret[0].option.get(), conf.option('gc.dummy').option.get())
|
||||||
#
|
#
|
||||||
_is_same_opt(conf.option.find('dummy', value=False, first=True).option.get(), conf.option('gc.dummy').option.get())
|
_is_same_opt(conf.option.find('dummy', value=False, first=True).option.get(), conf.option('gc.dummy').option.get())
|
||||||
#subconfig
|
#subconfig
|
||||||
ret = conf.option('gc').find('dummy')
|
ret = list(conf.option('gc').find('dummy'))
|
||||||
assert len(ret) == 1
|
assert len(ret) == 1
|
||||||
_is_same_opt(ret[0].option.get(), conf.option('gc.dummy').option.get())
|
_is_same_opt(ret[0].option.get(), conf.option('gc.dummy').option.get())
|
||||||
#
|
#
|
||||||
ret = conf.option('gc').find('float')
|
ret = list(conf.option('gc').find('float'))
|
||||||
assert len(ret) == 1
|
assert len(ret) == 1
|
||||||
_is_same_opt(ret[0].option.get(), conf.option('gc.float').option.get())
|
_is_same_opt(ret[0].option.get(), conf.option('gc.float').option.get())
|
||||||
#
|
#
|
||||||
ret = conf.option('gc').find('bool')
|
ret = list(conf.option('gc').find('bool'))
|
||||||
assert len(ret) == 1
|
assert len(ret) == 1
|
||||||
_is_same_opt(ret[0].option.get(), conf.option('gc.gc2.bool').option.get())
|
_is_same_opt(ret[0].option.get(), conf.option('gc.gc2.bool').option.get())
|
||||||
_is_same_opt(conf.option('gc').find('bool', value=False, first=True).option.get(), conf.option('gc.gc2.bool').option.get())
|
_is_same_opt(conf.option('gc').find('bool', value=False, first=True).option.get(), conf.option('gc.gc2.bool').option.get())
|
||||||
|
@ -227,13 +228,13 @@ def test_find_in_config():
|
||||||
#
|
#
|
||||||
raises(AttributeError, "conf.option('gc').find('wantref').option.get()")
|
raises(AttributeError, "conf.option('gc').find('wantref').option.get()")
|
||||||
#
|
#
|
||||||
ret = conf.unrestraint.option('gc').find('prop')
|
ret = list(conf.unrestraint.option('gc').find('prop'))
|
||||||
assert len(ret) == 2
|
assert len(ret) == 2
|
||||||
_is_same_opt(ret[0].option.get(), conf.unrestraint.option('gc.gc2.prop').option.get())
|
_is_same_opt(ret[0].option.get(), conf.unrestraint.option('gc.gc2.prop').option.get())
|
||||||
_is_same_opt(ret[1].option.get(), conf.forcepermissive.option('gc.prop').option.get())
|
_is_same_opt(ret[1].option.get(), conf.forcepermissive.option('gc.prop').option.get())
|
||||||
#
|
#
|
||||||
conf.property.read_only()
|
conf.property.read_only()
|
||||||
ret = conf.option('gc').find('prop')
|
ret = list(conf.option('gc').find('prop'))
|
||||||
assert len(ret) == 1
|
assert len(ret) == 1
|
||||||
_is_same_opt(ret[0].option.get(), conf.option('gc.prop').option.get())
|
_is_same_opt(ret[0].option.get(), conf.option('gc.prop').option.get())
|
||||||
# not OptionDescription
|
# not OptionDescription
|
||||||
|
@ -246,16 +247,16 @@ def test_find_multi():
|
||||||
o = OptionDescription('od', '', [b])
|
o = OptionDescription('od', '', [b])
|
||||||
conf = Config(o)
|
conf = Config(o)
|
||||||
#
|
#
|
||||||
raises(AttributeError, "conf.option.find('bool', value=True)")
|
raises(AttributeError, "list(conf.option.find('bool', value=True))")
|
||||||
raises(AttributeError, "conf.option.find('bool', value=True, first=True)")
|
raises(AttributeError, "list(conf.option.find('bool', value=True, first=True))")
|
||||||
conf.option('bool').value.set([False])
|
conf.option('bool').value.set([False])
|
||||||
raises(AttributeError, "conf.option.find('bool', value=True)")
|
raises(AttributeError, "list(conf.option.find('bool', value=True))")
|
||||||
raises(AttributeError, "conf.option.find('bool', value=True, first=True)")
|
raises(AttributeError, "list(conf.option.find('bool', value=True, first=True))")
|
||||||
conf.option('bool').value.set([False, False])
|
conf.option('bool').value.set([False, False])
|
||||||
raises(AttributeError, "conf.option.find('bool', value=True)")
|
raises(AttributeError, "list(conf.option.find('bool', value=True))")
|
||||||
raises(AttributeError, "conf.option.find('bool', value=True, first=True)")
|
raises(AttributeError, "list(conf.option.find('bool', value=True, first=True))")
|
||||||
conf.option('bool').value.set([False, False, True])
|
conf.option('bool').value.set([False, False, True])
|
||||||
ret = conf.option.find('bool', value=True)
|
ret = list(conf.option.find('bool', value=True))
|
||||||
assert len(ret) == 1
|
assert len(ret) == 1
|
||||||
_is_same_opt(ret[0].option.get(), b)
|
_is_same_opt(ret[0].option.get(), b)
|
||||||
_is_same_opt(conf.option.find('bool', value=True, first=True).option.get(), b)
|
_is_same_opt(conf.option.find('bool', value=True, first=True).option.get(), b)
|
||||||
|
@ -264,7 +265,7 @@ def test_find_multi():
|
||||||
def test_does_not_find_in_config():
|
def test_does_not_find_in_config():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
conf = Config(descr)
|
conf = Config(descr)
|
||||||
raises(AttributeError, "conf.option.find('IDontExist')")
|
raises(AttributeError, "list(conf.option.find('IDontExist'))")
|
||||||
|
|
||||||
|
|
||||||
def test_filename():
|
def test_filename():
|
||||||
|
@ -341,7 +342,11 @@ def test_help():
|
||||||
od1 = OptionDescription('o', '', [stro])
|
od1 = OptionDescription('o', '', [stro])
|
||||||
od2 = OptionDescription('o', '', [od1])
|
od2 = OptionDescription('o', '', [od1])
|
||||||
cfg = Config(od2)
|
cfg = Config(od2)
|
||||||
cfg.help(_display=False, _valid=True)
|
cfg.help(_display=False)
|
||||||
|
cfg.config.help(_display=False)
|
||||||
|
cfg.option.help(_display=False)
|
||||||
|
cfg.option('o').help(_display=False)
|
||||||
|
cfg.option('o.s').help(_display=False)
|
||||||
|
|
||||||
|
|
||||||
def test_config_reset():
|
def test_config_reset():
|
||||||
|
|
|
@ -689,7 +689,7 @@ def test_find_dyndescription_context():
|
||||||
#assert len(opts) == 1
|
#assert len(opts) == 1
|
||||||
#assert isinstance(opts[0], DynSymLinkOption)
|
#assert isinstance(opts[0], DynSymLinkOption)
|
||||||
#assert opts[0].impl_getname() == 'stval1'
|
#assert opts[0].impl_getname() == 'stval1'
|
||||||
raises(AttributeError, "api.option.find('strnotexists')")
|
raises(AttributeError, "list(api.option.find('strnotexists'))")
|
||||||
|
|
||||||
|
|
||||||
def test_information_dyndescription_context():
|
def test_information_dyndescription_context():
|
||||||
|
|
|
@ -145,7 +145,7 @@ def test_contexts():
|
||||||
|
|
||||||
def test_find():
|
def test_find():
|
||||||
meta = make_metaconfig()
|
meta = make_metaconfig()
|
||||||
ret = meta.option.find('i2')
|
ret = list(meta.option.find('i2'))
|
||||||
assert len(ret) == 1
|
assert len(ret) == 1
|
||||||
assert 1 == ret[0].value.get()
|
assert 1 == ret[0].value.get()
|
||||||
assert 1 == meta.option.find('i2', first=True).value.get()
|
assert 1 == meta.option.find('i2', first=True).value.get()
|
||||||
|
|
|
@ -383,7 +383,7 @@ def test_allow_multiple_changes_from_config():
|
||||||
def test_access_by_get():
|
def test_access_by_get():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
api = Config(descr)
|
api = Config(descr)
|
||||||
raises(AttributeError, "api.option.find('idontexist')")
|
raises(AttributeError, "list(api.option.find('idontexist'))")
|
||||||
assert api.option.find('wantref', first=True).value.get() is False
|
assert api.option.find('wantref', first=True).value.get() is False
|
||||||
assert api.option.find('dummy', first=True).value.get() is False
|
assert api.option.find('dummy', first=True).value.get() is False
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
from .function import Params, ParamOption, ParamValue, ParamContext
|
from .function import Params, ParamOption, ParamValue, ParamContext
|
||||||
from .option import *
|
from .option import *
|
||||||
from .error import APIError
|
from .error import APIError
|
||||||
from .api import getapi, Config, MetaConfig, GroupConfig
|
from .api import Config, MetaConfig, GroupConfig
|
||||||
from .option import __all__ as all_options
|
from .option import __all__ as all_options
|
||||||
from .setting import owners, undefined
|
from .setting import owners, undefined
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ allfuncs = ['Params',
|
||||||
'MetaConfig',
|
'MetaConfig',
|
||||||
'GroupConfig',
|
'GroupConfig',
|
||||||
'Config',
|
'Config',
|
||||||
'getapi',
|
|
||||||
'APIError',
|
'APIError',
|
||||||
'undefined']
|
'undefined']
|
||||||
allfuncs.extend(all_options)
|
allfuncs.extend(all_options)
|
||||||
|
|
1248
tiramisu/api.py
1248
tiramisu/api.py
File diff suppressed because it is too large
Load diff
|
@ -645,6 +645,9 @@ class _CommonConfig(SubConfig):
|
||||||
def impl_del_information(self, key, raises=True):
|
def impl_del_information(self, key, raises=True):
|
||||||
self._impl_values.del_information(key, raises)
|
self._impl_values.del_information(key, raises)
|
||||||
|
|
||||||
|
def impl_list_information(self):
|
||||||
|
return self._impl_values.list_information()
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
|
@ -244,8 +244,6 @@ class OptionDescriptionWalk(CacheOptionDescription):
|
||||||
subpath = None
|
subpath = None
|
||||||
for child in self._children[1]:
|
for child in self._children[1]:
|
||||||
if dyn and child.impl_is_dynoptiondescription():
|
if dyn and child.impl_is_dynoptiondescription():
|
||||||
if config_bag.context is None: # pragma: no cover
|
|
||||||
raise ConfigError(_('need context'))
|
|
||||||
if subpath is None:
|
if subpath is None:
|
||||||
if config_bag.context.cfgimpl_get_description() == self:
|
if config_bag.context.cfgimpl_get_description() == self:
|
||||||
subpath = ''
|
subpath = ''
|
||||||
|
|
|
@ -289,6 +289,12 @@ class Values(Cache):
|
||||||
if raises:
|
if raises:
|
||||||
raise ValueError(_("information's item not found {0}").format(key))
|
raise ValueError(_("information's item not found {0}").format(key))
|
||||||
|
|
||||||
|
def list_information(self, path):
|
||||||
|
if path in self._informations:
|
||||||
|
return self._informations[path].keys()
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
def del_informations(self):
|
def del_informations(self):
|
||||||
self._informations = {}
|
self._informations = {}
|
||||||
|
|
||||||
|
|
|
@ -228,6 +228,14 @@ class Values(Sqlite3DB):
|
||||||
self._storage.execute("DELETE FROM information WHERE key = ? AND session_id = ? AND path = ?",
|
self._storage.execute("DELETE FROM information WHERE key = ? AND session_id = ? AND path = ?",
|
||||||
(key, self._session_id, path))
|
(key, self._session_id, path))
|
||||||
|
|
||||||
|
def list_information(self, path):
|
||||||
|
path = self._sqlite_encode_path(path)
|
||||||
|
rows = self._storage.select("SELECT key FROM information WHERE session_id = ? AND path = ?",
|
||||||
|
(self._session_id, path),
|
||||||
|
only_one=False)
|
||||||
|
for row in rows:
|
||||||
|
yield self._sqlite_decode_path(row[0])
|
||||||
|
|
||||||
def del_informations(self):
|
def del_informations(self):
|
||||||
self._storage.execute("DELETE FROM information WHERE session_id = ?",
|
self._storage.execute("DELETE FROM information WHERE session_id = ?",
|
||||||
(self._session_id,))
|
(self._session_id,))
|
||||||
|
|
|
@ -513,6 +513,9 @@ class Values(object):
|
||||||
def del_information(self, key, raises=True, path=None):
|
def del_information(self, key, raises=True, path=None):
|
||||||
self._p_.del_information(path, key, raises)
|
self._p_.del_information(path, key, raises)
|
||||||
|
|
||||||
|
def list_information(self, path=None):
|
||||||
|
return self._p_.list_information(path)
|
||||||
|
|
||||||
#______________________________________________________________________
|
#______________________________________________________________________
|
||||||
# mandatory warnings
|
# mandatory warnings
|
||||||
def _mandatory_warnings(self,
|
def _mandatory_warnings(self,
|
||||||
|
|
Loading…
Reference in a new issue