-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_help_mixin.py
129 lines (97 loc) · 3.75 KB
/
test_help_mixin.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import logging
from friendlyshell.base_shell import BaseShell
from friendlyshell.shell_help_mixin import ShellHelpMixin
from friendlyshell.basic_logger_mixin import BasicLoggerMixin
from mock import patch
import pytest
def test_list_commands(caplog):
caplog.set_level(logging.INFO)
class MyShell (BasicLoggerMixin, BaseShell, ShellHelpMixin):
def do_something(self):
"""Here's online help for my 'something' command"""
pass
obj = MyShell()
with patch('friendlyshell.base_shell.input') as MockInput:
MockInput.side_effect = ['help', 'exit']
obj.run()
assert 'exit' in caplog.text
assert 'help' in caplog.text
assert 'something' in caplog.text
assert '!' in caplog.text
assert obj.do_something.__doc__ in caplog.text
def test_help_missing_command(caplog):
caplog.set_level(logging.INFO)
class MyShell (BasicLoggerMixin, BaseShell, ShellHelpMixin):
pass
obj = MyShell()
with patch('friendlyshell.base_shell.input') as MockInput:
MockInput.side_effect = ['help something', 'exit']
obj.run()
assert "Command does not exist: something" in caplog.text
def test_missing_help(caplog):
caplog.set_level(logging.INFO)
class MyShell(BasicLoggerMixin, BaseShell, ShellHelpMixin):
def do_something(self):
pass
obj = MyShell()
with patch('friendlyshell.base_shell.input') as MockInput:
MockInput.side_effect = ['help something', 'exit']
obj.run()
assert 'No online help' in caplog.text
def test_default_help(caplog):
caplog.set_level(logging.INFO)
class MyShell(BasicLoggerMixin, BaseShell, ShellHelpMixin):
def do_something(self):
"""Here's online help"""
pass
obj = MyShell()
with patch('friendlyshell.base_shell.input') as MockInput:
MockInput.side_effect = ['help something', 'exit']
obj.run()
assert "Here's online help" in caplog.text
def test_command_help(caplog):
caplog.set_level(logging.INFO)
expected_help = "Here's my verbose help for something..."
class MyShell(BasicLoggerMixin, BaseShell, ShellHelpMixin):
def do_something(self):
"""Here's online help"""
pass
def help_something(self):
return expected_help
obj = MyShell()
with patch('friendlyshell.base_shell.input') as MockInput:
MockInput.side_effect = ['help something', 'exit']
obj.run()
assert expected_help in caplog.text
def test_help_help(caplog):
caplog.set_level(logging.INFO)
class MyShell(BasicLoggerMixin, BaseShell, ShellHelpMixin):
pass
obj = MyShell()
with patch('friendlyshell.base_shell.input') as MockInput:
MockInput.side_effect = ['help help', 'exit']
obj.run()
assert "Online help generation tool" in caplog.text
def test_occluded_help(caplog):
caplog.set_level(logging.INFO)
class MyShell(BasicLoggerMixin, BaseShell, ShellHelpMixin):
def do_something(self):
"""Here's online help"""
pass
help_something = "Should not see me"
obj = MyShell()
with patch('friendlyshell.base_shell.input') as MockInput:
MockInput.side_effect = ['help something', 'exit']
obj.run()
assert "Error: " in caplog.text
def test_occluded_command(caplog):
caplog.set_level(logging.INFO)
class MyShell (BasicLoggerMixin, BaseShell, ShellHelpMixin):
do_something = "Hello"
obj = MyShell()
with patch('friendlyshell.base_shell.input') as MockInput:
MockInput.side_effect = ['help something', 'exit']
obj.run()
assert "Error: " in caplog.text
if __name__ == "__main__":
pytest.main([__file__, "-v", "-s"])