32
class TestHelp(tests.TestCase):
35
tests.TestCase.setUp(self)
36
commands.install_bzr_command_hooks()
39
32
class TestCommandHelp(tests.TestCase):
40
33
"""Tests for help on commands."""
42
35
def test_command_help_includes_see_also(self):
43
36
class cmd_WithSeeAlso(commands.Command):
44
__doc__ = """A sample command."""
37
"""A sample command."""
45
38
_see_also = ['foo', 'bar']
46
39
cmd = cmd_WithSeeAlso()
47
40
helptext = cmd.get_help_text()
48
41
self.assertEndsWith(
50
' -v, --verbose Display more information.\n'
51
' -q, --quiet Only display errors and warnings.\n'
52
' -h, --help Show help message.\n'
43
' -h, --help Show help message.\n'
54
45
'See also: bar, foo\n')
56
47
def test_get_help_text(self):
57
48
"""Commands have a get_help_text method which returns their help."""
58
49
class cmd_Demo(commands.Command):
59
__doc__ = """A sample command."""
50
"""A sample command."""
61
52
helptext = cmd.get_help_text()
62
self.assertStartsWith(helptext,
63
'Purpose: A sample command.\n'
65
self.assertEndsWith(helptext,
66
' -h, --help Show help message.\n\n')
53
self.assertStartsWith(helptext, 'usage: bzr Demo')
54
self.assertEndsWith(helptext, 'Show help message.\n')
68
56
def test_command_with_additional_see_also(self):
69
57
class cmd_WithSeeAlso(commands.Command):
70
__doc__ = """A sample command."""
58
"""A sample command."""
71
59
_see_also = ['foo', 'bar']
72
60
cmd = cmd_WithSeeAlso()
73
61
helptext = cmd.get_help_text(['gam'])
74
62
self.assertEndsWith(
76
' -v, --verbose Display more information.\n'
77
' -q, --quiet Only display errors and warnings.\n'
78
' -h, --help Show help message.\n'
64
' -h, --help Show help message.\n'
80
66
'See also: bar, foo, gam\n')
82
68
def test_command_only_additional_see_also(self):
83
69
class cmd_WithSeeAlso(commands.Command):
84
__doc__ = """A sample command."""
70
"""A sample command."""
85
71
cmd = cmd_WithSeeAlso()
86
72
helptext = cmd.get_help_text(['gam'])
87
73
self.assertEndsWith(
89
' -v, --verbose Display more information.\n'
90
' -q, --quiet Only display errors and warnings.\n'
91
' -h, --help Show help message.\n'
75
' -h, --help Show help message.\n'
95
79
def test_get_help_topic(self):
96
80
"""The help topic for a Command is its name()."""
97
81
class cmd_foo_bar(commands.Command):
98
__doc__ = """A sample command."""
82
"""A sample command."""
99
83
cmd = cmd_foo_bar()
100
84
self.assertEqual(cmd.name(), cmd.get_help_topic())
102
def test_formatted_help_text(self):
103
"""Help text should be plain text by default."""
104
class cmd_Demo(commands.Command):
105
__doc__ = """A sample command.
117
helptext = cmd.get_help_text()
120
'Purpose: A sample command.\n'
124
' --usage Show usage message and options.\n'
125
' -0, --null Use an ASCII NUL (\\0) separator rather than a newline.\n'
126
' -v, --verbose Display more information.\n'
127
' -q, --quiet Only display errors and warnings.\n'
128
' -h, --help Show help message.\n'
139
helptext = cmd.get_help_text(plain=False)
140
self.assertEquals(helptext,
141
':Purpose: A sample command.\n'
145
' --usage Show usage message and options.\n'
146
' -0, --null Use an ASCII NUL (\\0) separator rather than a newline.\n'
147
' -v, --verbose Display more information.\n'
148
' -q, --quiet Only display errors and warnings.\n'
149
' -h, --help Show help message.\n'
161
def test_concise_help_text(self):
162
"""Concise help text excludes the descriptive sections."""
163
class cmd_Demo(commands.Command):
164
__doc__ = """A sample command.
174
helptext = cmd.get_help_text()
175
self.assertEqualDiff(
177
'Purpose: A sample command.\n'
181
' --usage Show usage message and options.\n'
182
' -0, --null Use an ASCII NUL (\\0) separator rather than a newline.\n'
183
' -v, --verbose Display more information.\n'
184
' -q, --quiet Only display errors and warnings.\n'
185
' -h, --help Show help message.\n'
195
helptext = cmd.get_help_text(verbose=False)
196
self.assertEquals(helptext,
197
'Purpose: A sample command.\n'
201
' --usage Show usage message and options.\n'
202
' -0, --null Use an ASCII NUL (\\0) separator rather than a newline.\n'
203
' -v, --verbose Display more information.\n'
204
' -q, --quiet Only display errors and warnings.\n'
205
' -h, --help Show help message.\n'
207
'See bzr help Demo for more details and examples.\n'
210
def test_help_custom_section_ordering(self):
211
"""Custom descriptive sections should remain in the order given."""
212
class cmd_Demo(commands.Command):
213
__doc__ = """A sample command.
218
Interesting stuff about formats.
226
Clever things to keep in mind.
229
helptext = cmd.get_help_text()
230
self.assertEqualDiff(
232
'Purpose: A sample command.\n'
236
' --usage Show usage message and options.\n'
237
' -0, --null Use an ASCII NUL (\\0) separator rather than a newline.\n'
238
' -v, --verbose Display more information.\n'
239
' -q, --quiet Only display errors and warnings.\n'
240
' -h, --help Show help message.\n'
246
' Interesting stuff about formats.\n'
254
' Clever things to keep in mind.\n'
257
def test_help_text_custom_usage(self):
258
"""Help text may contain a custom usage section."""
259
class cmd_Demo(commands.Command):
260
__doc__ = """A sample command.
270
helptext = cmd.get_help_text()
271
self.assertEquals(helptext,
272
'Purpose: A sample command.\n'
274
' cmd Demo [opts] args\n'
280
' --usage Show usage message and options.\n'
281
' -0, --null Use an ASCII NUL (\\0) separator rather than a newline.\n'
282
' -v, --verbose Display more information.\n'
283
' -q, --quiet Only display errors and warnings.\n'
284
' -h, --help Show help message.\n'
287
' Blah blah blah.\n\n')
290
class TestRegisteredTopic(TestHelp):
87
class TestRegisteredTopic(tests.TestCase):
291
88
"""Tests for the RegisteredTopic class."""
293
90
def test_contruct(self):
294
91
"""Construction takes the help topic name for the registered item."""
296
93
self.assertTrue('basic' in help_topics.topic_registry)
297
94
topic = help_topics.RegisteredTopic('basic')
298
95
self.assertEqual('basic', topic.topic)