40
40
helptext = cmd.get_help_text()
41
41
self.assertEndsWith(
43
' -v, --verbose Display more information.\n'
44
' -q, --quiet Only display errors and warnings.\n'
45
' -h, --help Show help message.\n'
43
' -h, --help show help message\n'
47
45
'See also: bar, foo\n')
52
50
"""A sample command."""
54
52
helptext = cmd.get_help_text()
55
self.assertStartsWith(helptext,
56
'Purpose: A sample command.\n'
58
self.assertEndsWith(helptext,
59
' -h, --help Show help message.\n\n')
53
self.assertStartsWith(helptext, 'usage: bzr Demo')
54
self.assertEndsWith(helptext, 'show help message\n')
61
56
def test_command_with_additional_see_also(self):
62
57
class cmd_WithSeeAlso(commands.Command):
66
61
helptext = cmd.get_help_text(['gam'])
67
62
self.assertEndsWith(
69
' -v, --verbose Display more information.\n'
70
' -q, --quiet Only display errors and warnings.\n'
71
' -h, --help Show help message.\n'
64
' -h, --help show help message\n'
73
66
'See also: bar, foo, gam\n')
79
72
helptext = cmd.get_help_text(['gam'])
80
73
self.assertEndsWith(
82
' -v, --verbose Display more information.\n'
83
' -q, --quiet Only display errors and warnings.\n'
84
' -h, --help Show help message.\n'
75
' -h, --help show help message\n'
91
82
"""A sample command."""
92
83
cmd = cmd_foo_bar()
93
84
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')
181
87
class TestRegisteredTopic(tests.TestCase):
182
88
"""Tests for the RegisteredTopic class."""
202
108
'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(),
212
110
def test_get_help_topic(self):
213
111
"""The help topic for a RegisteredTopic is its topic from construction."""
214
112
topic = help_topics.RegisteredTopic('foobar')