coverage
This commit is contained in:
parent
32e88299e2
commit
5ca2e32ac5
6 changed files with 61 additions and 32 deletions
|
@ -494,6 +494,30 @@ def test_requires_multi_disabled_new_format():
|
|||
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():
|
||||
a = BoolOption('activate_service', '')
|
||||
b = IntOption('num_service', '')
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
from .autopath import 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.option import BoolOption, OptionDescription
|
||||
from tiramisu.setting import groups, owners
|
||||
|
@ -37,6 +38,15 @@ def test_create_persistent():
|
|||
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():
|
||||
b = BoolOption('b', '')
|
||||
o = OptionDescription('od', '', [b])
|
||||
|
|
|
@ -29,8 +29,7 @@ from .option import OptionDescription, Option, SymLinkOption, \
|
|||
DynSymLinkOption, SynDynOptionDescription
|
||||
from .option.baseoption import valid_name
|
||||
from .setting import groups, Settings, default_encoding, undefined
|
||||
from .storage import get_storages, get_storage, set_storage, \
|
||||
get_default_values_storages
|
||||
from .storage import get_storages, set_storage, get_default_values_storages
|
||||
from .value import Values, Multi
|
||||
from .i18n import _
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ from types import FunctionType
|
|||
import warnings
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
if sys.version_info[0] >= 3: # pragma: no cover
|
||||
from inspect import signature
|
||||
else:
|
||||
from inspect import getargspec
|
||||
|
@ -190,7 +190,7 @@ class Base(StorageBase):
|
|||
if defaults is None:
|
||||
defaults = []
|
||||
args = func_args.args[0:len(func_args.args)-len(defaults)]
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
func_params = signature(validator).parameters
|
||||
args = [f.name for f in func_params.values() if f.default is f.empty]
|
||||
if validator_params is not None:
|
||||
|
@ -273,14 +273,9 @@ class BaseOption(Base):
|
|||
is_readonly = False
|
||||
# never change _name dans _opt
|
||||
if name == '_name':
|
||||
try:
|
||||
if self.impl_getname() is not None:
|
||||
#so _name is already set
|
||||
is_readonly = True
|
||||
except (KeyError, AttributeError):
|
||||
pass
|
||||
elif name == '_opt':
|
||||
pass
|
||||
if self.impl_getname() is not None:
|
||||
#so _name is already set
|
||||
is_readonly = True
|
||||
elif name != '_readonly':
|
||||
is_readonly = self.impl_is_readonly()
|
||||
if is_readonly:
|
||||
|
@ -635,10 +630,6 @@ class Option(OnlyOption):
|
|||
|
||||
def impl_get_master_slaves(self):
|
||||
masterslaves = self._get_master_slave()
|
||||
if masterslaves is None:
|
||||
return None
|
||||
if not isinstance(masterslaves, MasterSlaves):
|
||||
return MasterSlaves(masterslaves)
|
||||
return masterslaves
|
||||
|
||||
def impl_getdoc(self):
|
||||
|
@ -906,8 +897,8 @@ def validate_requires_arg(new_option, multi, requires, name):
|
|||
def get_operator(require):
|
||||
operator = require.get('operator', 'or')
|
||||
if operator not in ['and', 'or']:
|
||||
raise ValueError(_('malformed requirements for option: {0}'
|
||||
' operator must be "or" or "and"'))
|
||||
raise ValueError(_('malformed requirements for option: "{0}"'
|
||||
' operator must be "or" or "and"').format(operator))
|
||||
return operator
|
||||
|
||||
|
||||
|
@ -968,11 +959,7 @@ class SymLinkOption(OnlyOption):
|
|||
self.commit(session)
|
||||
|
||||
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):
|
||||
return self._impl_getopt().impl_get_information(key, default)
|
||||
|
@ -1012,10 +999,7 @@ class DynSymLinkOption(object):
|
|||
self._opt = opt
|
||||
|
||||
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):
|
||||
return self._name
|
||||
|
|
|
@ -760,7 +760,7 @@ class Settings(object):
|
|||
else:
|
||||
if operator == 'and':
|
||||
calc_properties.add(action)
|
||||
continue
|
||||
continue # pragma: no cover
|
||||
if breaked:
|
||||
break
|
||||
return calc_properties
|
||||
|
|
|
@ -83,6 +83,18 @@ default_validation = StorageType()
|
|||
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 gen_id(config):
|
||||
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
|
||||
:params session_id: id of session to delete
|
||||
"""
|
||||
storage_module = storage_type.get()
|
||||
session = storage_module.storage.getsession()
|
||||
if type_ == 'option':
|
||||
storage_option_type.get().delete_session(session_id)
|
||||
storage_option_type.get().delete_session(session_id, session)
|
||||
else:
|
||||
storage_module = storage_type.get()
|
||||
session = storage_module.storage.getsession()
|
||||
storage_module.value.delete_session(session_id, session)
|
||||
storage_module.storage.delete_session(session_id, session)
|
||||
if session:
|
||||
|
|
Loading…
Reference in a new issue