40
40
helptext = cmd.get_help_text()
41
41
self.assertEndsWith(
43
' -h, --help show help message\n'
43
' -v, --verbose Display more information.\n'
44
' -q, --quiet Only display errors and warnings.\n'
45
' -h, --help Show help message.\n'
45
47
'See also: bar, foo\n')
50
52
"""A sample command."""
52
54
helptext = cmd.get_help_text()
53
self.assertStartsWith(helptext, 'usage: bzr Demo')
54
self.assertEndsWith(helptext, 'show help message\n')
55
self.assertStartsWith(helptext,
56
'Purpose: A sample command.\n'
58
self.assertEndsWith(helptext,
59
' -h, --help Show help message.\n\n')
56
61
def test_command_with_additional_see_also(self):
57
62
class cmd_WithSeeAlso(commands.Command):
61
66
helptext = cmd.get_help_text(['gam'])
62
67
self.assertEndsWith(
64
' -h, --help show help message\n'
69
' -v, --verbose Display more information.\n'
70
' -q, --quiet Only display errors and warnings.\n'
71
' -h, --help Show help message.\n'
66
73
'See also: bar, foo, gam\n')
72
79
helptext = cmd.get_help_text(['gam'])
73
80
self.assertEndsWith(
75
' -h, --help show help message\n'
82
' -v, --verbose Display more information.\n'
83
' -q, --quiet Only display errors and warnings.\n'
84
' -h, --help Show help message.\n'
82
91
"""A sample command."""
83
92
cmd = cmd_foo_bar()
84
93
self.assertEqual(cmd.name(), cmd.get_help_topic())
95
def test_formatted_help_text(self):
96
"""Help text should be plain text by default."""
97
class cmd_Demo(commands.Command):
110
helptext = cmd.get_help_text()
113
'Purpose: A sample command.\n'
117
' -v, --verbose Display more information.\n'
118
' -q, --quiet Only display errors and warnings.\n'
119
' -h, --help Show help message.\n'
130
helptext = cmd.get_help_text(plain=False)
131
self.assertEquals(helptext,
132
':Purpose: A sample command.\n'
136
' -v, --verbose Display more information.\n'
137
' -q, --quiet Only display errors and warnings.\n'
138
' -h, --help Show help message.\n'
150
def test_help_text_custom_usage(self):
151
"""Help text may contain a custom usage section."""
152
class cmd_Demo(commands.Command):
163
helptext = cmd.get_help_text()
164
self.assertEquals(helptext,
165
'Purpose: A sample command.\n'
167
' cmd Demo [opts] args\n'
173
' -v, --verbose Display more information.\n'
174
' -q, --quiet Only display errors and warnings.\n'
175
' -h, --help Show help message.\n'
178
' Blah blah blah.\n\n')
87
181
class TestRegisteredTopic(tests.TestCase):
88
182
"""Tests for the RegisteredTopic class."""
108
202
'See also: bar, foo\n')
204
def test_get_help_text_loaded_from_file(self):
205
# Pick a known topic stored in an external file
206
topic = help_topics.RegisteredTopic('hooks')
207
self.assertStartsWith(topic.get_help_text(),
110
212
def test_get_help_topic(self):
111
213
"""The help topic for a RegisteredTopic is its topic from construction."""
112
214
topic = help_topics.RegisteredTopic('foobar')