From 509d902e72468ed9cae9ae65566c5aaaf36b7283 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 29 Sep 2018 21:58:41 +0200 Subject: [PATCH] coverage --- tiramisu/error.py | 2 +- tiramisu/option/masterslaves.py | 6 +++--- tiramisu/option/option.py | 13 +++---------- tiramisu/setting.py | 7 +++---- tiramisu/storage/__init__.py | 6 +++--- tiramisu/storage/dictionary/storage.py | 8 ++++---- tiramisu/storage/sqlalchemy/storage.py | 6 +++--- 7 files changed, 20 insertions(+), 28 deletions(-) diff --git a/tiramisu/error.py b/tiramisu/error.py index 4334e3d..7292d1a 100644 --- a/tiramisu/error.py +++ b/tiramisu/error.py @@ -154,7 +154,7 @@ class ConstError(TypeError): #Warning -class ValueWarning(UserWarning): # pragma: optional cover +class ValueWarning(UserWarning): """Option could warn user and not raise ValueError. Example: diff --git a/tiramisu/option/masterslaves.py b/tiramisu/option/masterslaves.py index 4968780..8c6aadf 100644 --- a/tiramisu/option/masterslaves.py +++ b/tiramisu/option/masterslaves.py @@ -52,13 +52,13 @@ class MasterSlaves(OptionDescription): raise ValueError(_('a master and a slave are mandatories in masterslaves "{}"').format(name)) master = children[0] for idx, child in enumerate(children): - if child.impl_is_symlinkoption(): # pragma: optional cover + if child.impl_is_symlinkoption(): raise ValueError(_('masterslaves "{0}" shall not have ' "a symlinkoption").format(self.impl_get_display_name())) - if not isinstance(child, Option): # pragma: optional cover + if not isinstance(child, Option): raise ValueError(_('masterslaves "{0}" shall not have ' 'a subgroup').format(self.impl_get_display_name())) - if not child.impl_is_multi(): # pragma: optional cover + if not child.impl_is_multi(): raise ValueError(_('only multi option allowed in masterslaves "{0}" but option ' '"{1}" is not a multi').format(self.impl_get_display_name(), child.impl_get_display_name())) diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index 64ea62a..3b1cd6a 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -164,11 +164,6 @@ class Option(OnlyOption): def impl_is_multi(self): return getattr(self, '_multi', 1) != 1 - def _validate(self, - *args, - **kwargs): # pragma: no cover - pass - def impl_is_unique(self): return getattr(self, '_unique', False) @@ -237,7 +232,7 @@ class Option(OnlyOption): def do_validation(_value, _index): - if isinstance(_value, list): # pragma: no cover + if isinstance(_value, list): raise ValueError(_('which must not be a list').format(_value, self.impl_get_display_name())) if _value is not None: @@ -477,10 +472,8 @@ class Option(OnlyOption): for opt in other_opts: if isinstance(opt, weakref.ReferenceType): opt = opt() - if opt.impl_is_submulti(): # pragma: no cover - raise ConfigError(_('cannot add consistency with submulti option')) - if not isinstance(opt, Option): # pragma: no cover - raise ConfigError(_('consistency must be set with an option, not {}').format(opt)) + assert not opt.impl_is_submulti(), _('cannot add consistency with submulti option') + assert isinstance(opt, Option), _('consistency must be set with an option, not {}').format(opt) if opt.issubdyn(): if dynod is None: raise ConfigError(_('almost one option in consistency is ' diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 6121ed4..404fd51 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -568,7 +568,7 @@ class Settings(object): else: if operator == 'and': calc_properties.add(action) - continue # pragma: no cover + continue if breaked: break return calc_properties @@ -666,9 +666,8 @@ class Settings(object): opt = None else: opt = option_bag.option - if all_properties and option_bag: # pragma: no cover - raise ValueError(_('opt and all_properties must not be set ' - 'together in reset')) + assert all_properties is False or option_bag is None, _('opt and all_properties must not be' + ' set together in reset') if opt and opt.impl_is_symlinkoption(): raise TypeError(_("can't reset properties to the symlinkoption \"{}\"" "").format(opt.impl_get_display_name())) diff --git a/tiramisu/storage/__init__.py b/tiramisu/storage/__init__.py index 0911c2c..1668b5f 100644 --- a/tiramisu/storage/__init__.py +++ b/tiramisu/storage/__init__.py @@ -47,7 +47,7 @@ class StorageType(object): storage_type = None mod = None - def set(self, name): # pragma: optional cover + def set(self, name): if self.storage_type is not None: # pragma: no cover if self.storage_type == name: return @@ -115,7 +115,7 @@ def get_default_settings_storages(): return properties, permissives -def list_sessions(type_): # pragma: optional cover +def list_sessions(type_): """List all available session (persistent or not persistent) """ #if type_ == 'option': @@ -124,7 +124,7 @@ def list_sessions(type_): # pragma: optional cover return storage_type.get().list_sessions() -def delete_session(session_id): # pragma: optional cover +def delete_session(session_id): """Delete a selected session, be careful, you can deleted a session use by an other instance :params session_id: id of session to delete diff --git a/tiramisu/storage/dictionary/storage.py b/tiramisu/storage/dictionary/storage.py index 2aef94f..0b92d8b 100644 --- a/tiramisu/storage/dictionary/storage.py +++ b/tiramisu/storage/dictionary/storage.py @@ -28,7 +28,7 @@ setting = Setting() _list_sessions = [] -def list_sessions(): # pragma: optional cover +def list_sessions(): return _list_sessions @@ -39,9 +39,9 @@ class Storage(object): serializable = True def __init__(self, session_id, persistent, test=False): - if not test and session_id in _list_sessions: # pragma: optional cover + if not test and session_id in _list_sessions: raise ConflictError(_('session "{}" already used').format(session_id)) - if persistent: # pragma: optional cover + if persistent: raise ValueError(_('a dictionary cannot be persistent')) self.session_id = session_id self.persistent = persistent @@ -50,7 +50,7 @@ class Storage(object): def __del__(self): try: _list_sessions.remove(self.session_id) - except AttributeError: # pragma: optional cover + except AttributeError: pass diff --git a/tiramisu/storage/sqlalchemy/storage.py b/tiramisu/storage/sqlalchemy/storage.py index a8b1940..179ea38 100644 --- a/tiramisu/storage/sqlalchemy/storage.py +++ b/tiramisu/storage/sqlalchemy/storage.py @@ -41,7 +41,7 @@ class Session(SqlAlchemyBase): self.session = session_id -def list_sessions(): # pragma: optional cover +def list_sessions(): session = util.Session() ret = [] for val in session.query(Session).all(): @@ -50,7 +50,7 @@ def list_sessions(): # pragma: optional cover return ret -def delete_session(session_id, session): # pragma: optional cover +def delete_session(session_id, session): session.delete(session.query(Session).filter_by(session=session_id).first()) session.commit() @@ -69,7 +69,7 @@ class Storage(object): session = getsession() self.session_id = session_id self.persistent = persistent - if not session.query(Session).filter_by(session=session_id).first(): # pragma: optional cover + if not session.query(Session).filter_by(session=session_id).first(): session.add(Session(session_id)) session.commit() del(session)