This commit is contained in:
Emmanuel Garette 2017-07-21 22:34:41 +02:00
parent 32e88299e2
commit 5ca2e32ac5
6 changed files with 61 additions and 32 deletions

View File

@ -494,6 +494,30 @@ def test_requires_multi_disabled_new_format():
assert props == ['disabled'] assert props == ['disabled']
def test_requires_unknown_operator():
a = BoolOption('activate_service', '')
b = IntOption('num_service', '')
raises(ValueError, """IPOption('ip_address_service', '',
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}],
'action': 'disabled', 'operator': 'unknown'}])""")
def test_requires_keys():
a = BoolOption('activate_service', '')
b = IntOption('num_service', '')
raises(ValueError, """IPOption('ip_address_service', '',
requires=[{'expected': [{'option': a, 'value2': True}, {'option': b, 'value': 1}],
'action': 'disabled', 'operator': 'and'}])""")
def test_requires_unvalid():
a = BoolOption('activate_service', '')
b = IntOption('num_service', '')
raises(ValueError, """IPOption('ip_address_service', '',
requires=[{'expected': [{'option': a, 'value': 'unvalid'}, {'option': b, 'value': 1}],
'action': 'disabled', 'operator': 'and'}])""")
def test_requires_multi_disabled_new_format_and(): def test_requires_multi_disabled_new_format_and():
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')

View File

@ -2,8 +2,9 @@
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
#from py.test import raises from py.test import raises
from tiramisu.error import ConfigError
from tiramisu.config import Config from tiramisu.config import Config
from tiramisu.option import BoolOption, OptionDescription from tiramisu.option import BoolOption, OptionDescription
from tiramisu.setting import groups, owners from tiramisu.setting import groups, owners
@ -37,6 +38,15 @@ def test_create_persistent():
pass pass
def test_create_delete_not_persistent():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
try:
Config(o, session_id='test_persistent', persistent=True)
except ValueError:
raises(ConfigError, "delete_session('option', 'test_persistent')")
def test_list_sessions_persistent(): def test_list_sessions_persistent():
b = BoolOption('b', '') b = BoolOption('b', '')
o = OptionDescription('od', '', [b]) o = OptionDescription('od', '', [b])

View File

@ -29,8 +29,7 @@ from .option import OptionDescription, Option, SymLinkOption, \
DynSymLinkOption, SynDynOptionDescription DynSymLinkOption, SynDynOptionDescription
from .option.baseoption import valid_name from .option.baseoption import valid_name
from .setting import groups, Settings, default_encoding, undefined from .setting import groups, Settings, default_encoding, undefined
from .storage import get_storages, get_storage, set_storage, \ from .storage import get_storages, set_storage, get_default_values_storages
get_default_values_storages
from .value import Values, Multi from .value import Values, Multi
from .i18n import _ from .i18n import _

View File

@ -23,7 +23,7 @@ from types import FunctionType
import warnings import warnings
import sys import sys
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3: # pragma: no cover
from inspect import signature from inspect import signature
else: else:
from inspect import getargspec from inspect import getargspec
@ -190,7 +190,7 @@ class Base(StorageBase):
if defaults is None: if defaults is None:
defaults = [] defaults = []
args = func_args.args[0:len(func_args.args)-len(defaults)] args = func_args.args[0:len(func_args.args)-len(defaults)]
else: else: # pragma: no cover
func_params = signature(validator).parameters func_params = signature(validator).parameters
args = [f.name for f in func_params.values() if f.default is f.empty] args = [f.name for f in func_params.values() if f.default is f.empty]
if validator_params is not None: if validator_params is not None:
@ -273,14 +273,9 @@ class BaseOption(Base):
is_readonly = False is_readonly = False
# never change _name dans _opt # never change _name dans _opt
if name == '_name': if name == '_name':
try:
if self.impl_getname() is not None: if self.impl_getname() is not None:
#so _name is already set #so _name is already set
is_readonly = True is_readonly = True
except (KeyError, AttributeError):
pass
elif name == '_opt':
pass
elif name != '_readonly': elif name != '_readonly':
is_readonly = self.impl_is_readonly() is_readonly = self.impl_is_readonly()
if is_readonly: if is_readonly:
@ -635,10 +630,6 @@ class Option(OnlyOption):
def impl_get_master_slaves(self): def impl_get_master_slaves(self):
masterslaves = self._get_master_slave() masterslaves = self._get_master_slave()
if masterslaves is None:
return None
if not isinstance(masterslaves, MasterSlaves):
return MasterSlaves(masterslaves)
return masterslaves return masterslaves
def impl_getdoc(self): def impl_getdoc(self):
@ -906,8 +897,8 @@ def validate_requires_arg(new_option, multi, requires, name):
def get_operator(require): def get_operator(require):
operator = require.get('operator', 'or') operator = require.get('operator', 'or')
if operator not in ['and', 'or']: if operator not in ['and', 'or']:
raise ValueError(_('malformed requirements for option: {0}' raise ValueError(_('malformed requirements for option: "{0}"'
' operator must be "or" or "and"')) ' operator must be "or" or "and"').format(operator))
return operator return operator
@ -968,10 +959,6 @@ class SymLinkOption(OnlyOption):
self.commit(session) self.commit(session)
def __getattr__(self, name, context=undefined): def __getattr__(self, name, context=undefined):
if name in ('_opt', '_readonly', 'impl_getpath', '_name',
'_impl_setopt'):
return object.__getattr__(self, name)
else:
return getattr(self._impl_getopt(), name) return getattr(self._impl_getopt(), name)
def impl_get_information(self, key, default=undefined): def impl_get_information(self, key, default=undefined):
@ -1012,9 +999,6 @@ class DynSymLinkOption(object):
self._opt = opt self._opt = opt
def __getattr__(self, name, context=undefined): def __getattr__(self, name, context=undefined):
if name in ('_opt', '_readonly', 'impl_getpath', '_name'):
return object.__getattr__(self, name)
else:
return getattr(self._impl_getopt(), name) return getattr(self._impl_getopt(), name)
def impl_getname(self): def impl_getname(self):

View File

@ -760,7 +760,7 @@ class Settings(object):
else: else:
if operator == 'and': if operator == 'and':
calc_properties.add(action) calc_properties.add(action)
continue continue # pragma: no cover
if breaked: if breaked:
break break
return calc_properties return calc_properties

View File

@ -83,6 +83,18 @@ default_validation = StorageType()
default_validation.set(DEFAULT_STORAGE) default_validation.set(DEFAULT_STORAGE)
def set_storage(type_, name): # pragma: optional cover
"""Change storage's configuration
:params name: is the storage name. If storage is already set, cannot
reset storage name
Other attributes are differents according to the selected storage's name
"""
storage_type.set(name)
setting = storage_type.get().setting
def get_storages(context, session_id, persistent): def get_storages(context, session_id, persistent):
def gen_id(config): def gen_id(config):
return 'c' + str(id(config)) + str(int(time())) + str(randint(0, 500)) return 'c' + str(id(config)) + str(int(time())) + str(randint(0, 500))
@ -135,11 +147,11 @@ def delete_session(type_, session_id): # pragma: optional cover
use by an other instance use by an other instance
:params session_id: id of session to delete :params session_id: id of session to delete
""" """
if type_ == 'option':
storage_option_type.get().delete_session(session_id)
else:
storage_module = storage_type.get() storage_module = storage_type.get()
session = storage_module.storage.getsession() session = storage_module.storage.getsession()
if type_ == 'option':
storage_option_type.get().delete_session(session_id, session)
else:
storage_module.value.delete_session(session_id, session) storage_module.value.delete_session(session_id, session)
storage_module.storage.delete_session(session_id, session) storage_module.storage.delete_session(session_id, session)
if session: if session: