82
98
"""A sample command."""
83
99
cmd = cmd_foo_bar()
84
100
self.assertEqual(cmd.name(), cmd.get_help_topic())
87
class TestRegisteredTopic(tests.TestCase):
102
def test_formatted_help_text(self):
103
"""Help text should be plain text by default."""
104
class cmd_Demo(commands.Command):
117
helptext = cmd.get_help_text()
120
'Purpose: A sample command.\n'
124
' --usage Show usage message and options.\n'
125
' -v, --verbose Display more information.\n'
126
' -q, --quiet Only display errors and warnings.\n'
127
' -h, --help Show help message.\n'
138
helptext = cmd.get_help_text(plain=False)
139
self.assertEquals(helptext,
140
':Purpose: A sample command.\n'
144
' --usage Show usage message and options.\n'
145
' -v, --verbose Display more information.\n'
146
' -q, --quiet Only display errors and warnings.\n'
147
' -h, --help Show help message.\n'
159
def test_concise_help_text(self):
160
"""Concise help text excludes the descriptive sections."""
161
class cmd_Demo(commands.Command):
172
helptext = cmd.get_help_text()
173
self.assertEqualDiff(
175
'Purpose: A sample command.\n'
179
' --usage Show usage message and options.\n'
180
' -v, --verbose Display more information.\n'
181
' -q, --quiet Only display errors and warnings.\n'
182
' -h, --help Show help message.\n'
192
helptext = cmd.get_help_text(verbose=False)
193
self.assertEquals(helptext,
194
'Purpose: A sample command.\n'
198
' --usage Show usage message and options.\n'
199
' -v, --verbose Display more information.\n'
200
' -q, --quiet Only display errors and warnings.\n'
201
' -h, --help Show help message.\n'
203
'See bzr help Demo for more details and examples.\n'
206
def test_help_custom_section_ordering(self):
207
"""Custom descriptive sections should remain in the order given."""
208
class cmd_Demo(commands.Command):
214
Interesting stuff about formats.
222
Clever things to keep in mind.
225
helptext = cmd.get_help_text()
226
self.assertEqualDiff(
228
'Purpose: A sample command.\n'
232
' --usage Show usage message and options.\n'
233
' -v, --verbose Display more information.\n'
234
' -q, --quiet Only display errors and warnings.\n'
235
' -h, --help Show help message.\n'
241
' Interesting stuff about formats.\n'
249
' Clever things to keep in mind.\n'
252
def test_help_text_custom_usage(self):
253
"""Help text may contain a custom usage section."""
254
class cmd_Demo(commands.Command):
265
helptext = cmd.get_help_text()
266
self.assertEquals(helptext,
267
'Purpose: A sample command.\n'
269
' cmd Demo [opts] args\n'
275
' --usage Show usage message and options.\n'
276
' -v, --verbose Display more information.\n'
277
' -q, --quiet Only display errors and warnings.\n'
278
' -h, --help Show help message.\n'
281
' Blah blah blah.\n\n')
284
class TestRegisteredTopic(TestHelp):
88
285
"""Tests for the RegisteredTopic class."""
90
287
def test_contruct(self):
91
288
"""Construction takes the help topic name for the registered item."""
93
290
self.assertTrue('basic' in help_topics.topic_registry)
94
291
topic = help_topics.RegisteredTopic('basic')
95
292
self.assertEqual('basic', topic.topic)