Skip to content

Commit 3f183de

Browse files
committed
tests for engines and errors
1 parent 94cd34e commit 3f183de

4 files changed

Lines changed: 41 additions & 5 deletions

File tree

‎.coveragerc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ exclude_lines =
77
no-cov
88
def __repr__
99
raise NotImplementedError
10+
__name__ == "__main__":
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
import mock
3+
4+
from paths_cli.tests.wizard.mock_wizard import mock_wizard
5+
6+
from paths_cli.wizard.engines import engines, SUPPORTED_ENGINES
7+
8+
def test_engines():
9+
wizard = mock_wizard(['foo'])
10+
with mock.patch.dict(SUPPORTED_ENGINES,
11+
{'foo': mock.Mock(return_value='ran foo')}):
12+
foo = engines(wizard)
13+
assert foo == 'ran foo'
14+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
import mock
3+
4+
from paths_cli.tests.wizard.mock_wizard import mock_wizard
5+
6+
from paths_cli.wizard.errors import *
7+
8+
def test_impossible_error_default():
9+
with pytest.raises(ImpossibleError, match="You should never see this."):
10+
raise ImpossibleError()
11+
12+
@pytest.mark.parametrize('inputs', ['r', 'q'])
13+
def test_not_installed(inputs):
14+
expected = {'r': RestartObjectException, 'q': SystemExit}[inputs]
15+
wizard = mock_wizard([inputs])
16+
with pytest.raises(expected):
17+
not_installed(wizard, 'foo', 'widget')
18+
log = wizard.console.log_text
19+
assert 'foo installed' in log
20+
assert 'different widget' in log
21+

‎paths_cli/wizard/errors.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ def __init__(self, msg=None):
77
class RestartObjectException(BaseException):
88
pass
99

10-
def not_installed(package, obj_type):
11-
retry = wizard.ask("Hey, it looks like you don't have {package} "
10+
def not_installed(wizard, package, obj_type):
11+
retry = wizard.ask(f"Hey, it looks like you don't have {package} "
1212
"installed. Do you want to try a different "
13-
"{obj_type}, or do you want to quit?",
13+
f"{obj_type}, or do you want to quit?",
1414
options=["[R]etry", "[Q]uit"])
1515
if retry == 'r':
16-
return
16+
raise RestartObjectException()
1717
elif retry == 'q':
1818
exit()
19-
else:
19+
else: # no-cov
2020
raise ImpossibleError()
2121

2222

0 commit comments

Comments
 (0)