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
|
try:
from StringIO import StringIO
except:
from io import StringIO
import mock
from cliff.app import App
from cliff.help import HelpCommand
from cliff.tests import utils
def test_show_help_for_command():
# FIXME(dhellmann): Are commands tied too closely to the app? Or
# do commands know too much about apps by using them to get to the
# command manager?
stdout = StringIO()
app = App('testing', '1',
utils.TestCommandManager(utils.TEST_NAMESPACE),
stdout=stdout)
app.NAME = 'test'
help_cmd = HelpCommand(app, mock.Mock())
parser = help_cmd.get_parser('test')
parsed_args = parser.parse_args(['one'])
try:
help_cmd.run(parsed_args)
except SystemExit:
pass
assert stdout.getvalue() == 'TestParser'
def test_list_matching_commands():
# FIXME(dhellmann): Are commands tied too closely to the app? Or
# do commands know too much about apps by using them to get to the
# command manager?
stdout = StringIO()
app = App('testing', '1',
utils.TestCommandManager(utils.TEST_NAMESPACE),
stdout=stdout)
app.NAME = 'test'
help_cmd = HelpCommand(app, mock.Mock())
parser = help_cmd.get_parser('test')
parsed_args = parser.parse_args(['t'])
try:
help_cmd.run(parsed_args)
except SystemExit:
pass
help_output = stdout.getvalue()
assert 'Command "t" matches:' in help_output
assert 'two' in help_output
assert 'three' in help_output
def test_list_matching_commands_no_match():
# FIXME(dhellmann): Are commands tied too closely to the app? Or
# do commands know too much about apps by using them to get to the
# command manager?
stdout = StringIO()
app = App('testing', '1',
utils.TestCommandManager(utils.TEST_NAMESPACE),
stdout=stdout)
app.NAME = 'test'
help_cmd = HelpCommand(app, mock.Mock())
parser = help_cmd.get_parser('test')
parsed_args = parser.parse_args(['z'])
try:
help_cmd.run(parsed_args)
except SystemExit:
pass
except ValueError:
pass
else:
assert False, 'Should have seen a ValueError'
def test_show_help_for_help():
# FIXME(dhellmann): Are commands tied too closely to the app? Or
# do commands know too much about apps by using them to get to the
# command manager?
stdout = StringIO()
app = App('testing', '1',
utils.TestCommandManager(utils.TEST_NAMESPACE),
stdout=stdout)
app.NAME = 'test'
help_cmd = HelpCommand(app, mock.Mock())
parser = help_cmd.get_parser('test')
parsed_args = parser.parse_args([])
try:
help_cmd.run(parsed_args)
except SystemExit:
pass
help_text = stdout.getvalue()
assert 'usage: test help [-h]' in help_text
|