-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_main.py
More file actions
55 lines (40 loc) · 1.61 KB
/
test_main.py
File metadata and controls
55 lines (40 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from unittest.mock import mock_open, patch
import pytest
import recommerce.main as main
from recommerce.configuration.path_manager import PathManager
handle_datapath_valid_testcases = [
'.',
'..'
]
@pytest.mark.parametrize('datapath', handle_datapath_valid_testcases)
def test_handle_datapath_valid(datapath):
with patch('builtins.open', mock_open(read_data=PathManager.user_path)), \
patch('recommerce.configuration.path_manager.PathManager._update_path_file'):
main.handle_datapath(datapath)
handle_datapath_invalid_testcases = [
'1:/invalid',
''
]
@pytest.mark.parametrize('datapath', handle_datapath_invalid_testcases)
def test_handle_datapath_invalid(datapath):
with patch('builtins.open', mock_open(read_data=PathManager.user_path)):
with pytest.raises(AssertionError) as assertion_message:
main.handle_datapath(datapath)
assert 'The provided path is not a valid directory' in str(assertion_message.value)
def test_handle_datapath_none():
# patch will make it so that the saved datapath is a MagicMock == invalid path
with patch('builtins.open', mock_open(read_data='1:/invalid')):
with pytest.raises(AssertionError) as assertion_message:
# Pass None as provided path i.e. no path provided by the user
main.handle_datapath(None)
assert 'The current saved data path is invalid:' in str(assertion_message.value)
handle_command_testcases = [
None,
'training',
'exampleprinter',
'agent_monitoring'
]
@pytest.mark.slow
@pytest.mark.parametrize('command', handle_command_testcases)
def test_handle_command(command):
main.handle_command(command)