Skip to content

Commit

Permalink
Merge pull request #692 from lago-project/is_workdir_narrow_except
Browse files Browse the repository at this point in the history
workdir: Narrow except in is_workdir
  • Loading branch information
ovirt-infra authored Feb 4, 2018
2 parents d40a883 + 983dbd5 commit 103d944
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 31 deletions.
4 changes: 2 additions & 2 deletions lago/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def load_plugins(namespace, instantiate=True):
if instantiate:
plugins = dict(
(
ext.name, ext.plugin if isinstance(ext.plugin, Plugin) else
ext.plugin()
ext.name,
ext.plugin if isinstance(ext.plugin, Plugin) else ext.plugin()
) for ext in mgr
)
else:
Expand Down
2 changes: 1 addition & 1 deletion lago/workdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def is_workdir(cls, path):
"""
try:
cls(path=path).load()
except Exception:
except MalformedWorkdir:
return False

return True
Expand Down
108 changes: 80 additions & 28 deletions tests/unit/lago/test_workdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,14 @@ def test_load_positive_correct_link(
mock_workdir,
monkeypatch,
):
(mock_workdir, mock_walk, mock_islink,
mock_readlink, ) = self._prepare_load_positive_run(
tmpdir, mock_workdir, monkeypatch
) # noqa: E121
(
mock_workdir,
mock_walk,
mock_islink,
mock_readlink,
) = self._prepare_load_positive_run(
tmpdir, mock_workdir, monkeypatch
) # noqa: E121

assert mock_workdir.load() is None
assert mock_workdir.current == 'another'
Expand Down Expand Up @@ -617,12 +621,18 @@ def _destroy_mocks(self, monkeypatch, mock_workdir):
@pytest.mark.parametrize(
'to_destroy',
(
None, [], ['ni!'], ['nini!', 'ninini!'],
None,
[],
['ni!'],
['nini!', 'ninini!'],
['ni!', 'nini!', 'ninini!'],
),
ids=(
'None as prefixes', 'empty list as prefixes', 'one prefix',
'many prefixes', 'all prefixes',
'None as prefixes',
'empty list as prefixes',
'one prefix',
'many prefixes',
'all prefixes',
),
)
def test_destroy(
Expand Down Expand Up @@ -665,21 +675,46 @@ def test_destroy(
@pytest.mark.parametrize(
'workdir_parent,params,should_be_found',
(
(os.curdir, {
'start_path': 'auto'
}, True, ), (os.curdir, {}, True, ),
('/one/two', {
'start_path': '/one/two/three'
}, True, ), ('/one', {
'start_path': '/one/two/three'
}, True, ),
('shrubbery', {
'start_path': '/one/two/three'
}, False, ),
(
os.curdir,
{
'start_path': 'auto'
},
True,
),
(
os.curdir,
{},
True,
),
(
'/one/two',
{
'start_path': '/one/two/three'
},
True,
),
(
'/one',
{
'start_path': '/one/two/three'
},
True,
),
(
'shrubbery',
{
'start_path': '/one/two/three'
},
False,
),
),
ids=(
'auto uses curdir', 'default uses curdir', 'recurse one level',
'recurse many levels', 'not found',
'auto uses curdir',
'default uses curdir',
'recurse one level',
'recurse many levels',
'not found',
),
)
def test_resolve_workdir_path_from_outside_of_it(
Expand Down Expand Up @@ -716,14 +751,31 @@ def is_workdir(path):
@pytest.mark.parametrize(
'workdir_path,params,should_be_found',
(
(os.curdir, {
'start_path': 'auto'
}, True, ), (os.curdir, {}, True, ),
('shrubbery', {
'start_path': '/one/two/three'
}, False, ),
(
os.curdir,
{
'start_path': 'auto'
},
True,
),
(
os.curdir,
{},
True,
),
(
'shrubbery',
{
'start_path': '/one/two/three'
},
False,
),
),
ids=(
'auto uses curdir',
'default uses curdir',
'not found',
),
ids=('auto uses curdir', 'default uses curdir', 'not found', ),
)
def test_resolve_workdir_path_from_inside_of_it(
self,
Expand Down Expand Up @@ -756,7 +808,7 @@ def is_workdir(path):

def test_is_workdir_fails_if_load_raises_exception(self):
def load(*args, **kwargs):
raise Exception
raise lago.workdir.MalformedWorkdir()

mock_workdir_cls = mock.Mock(spec=lago.workdir.Workdir)
mock_workdir_cls().load = load
Expand Down

0 comments on commit 103d944

Please sign in to comment.