13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Unit tests for the bzrlib.help module."""
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
53
self.assertStartsWith(helptext,
63
54
'Purpose: A sample command.\n'
65
self.assertEndsWith(helptext,
66
' -h, --help Show help message.\n\n')
56
self.assertEndsWith(helptext, 'Show help message.\n\n')
68
58
def test_command_with_additional_see_also(self):
69
59
class cmd_WithSeeAlso(commands.Command):
70
__doc__ = """A sample command."""
60
"""A sample command."""
71
61
_see_also = ['foo', 'bar']
72
62
cmd = cmd_WithSeeAlso()
73
63
helptext = cmd.get_help_text(['gam'])
74
64
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'
66
' -h, --help Show help message.\n'
80
68
'See also: bar, foo, gam\n')
82
70
def test_command_only_additional_see_also(self):
83
71
class cmd_WithSeeAlso(commands.Command):
84
__doc__ = """A sample command."""
72
"""A sample command."""
85
73
cmd = cmd_WithSeeAlso()
86
74
helptext = cmd.get_help_text(['gam'])
87
75
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'
77
' -h, --help Show help message.\n'
95
81
def test_get_help_topic(self):
96
82
"""The help topic for a Command is its name()."""
97
83
class cmd_foo_bar(commands.Command):
98
__doc__ = """A sample command."""
84
"""A sample command."""
99
85
cmd = cmd_foo_bar()
100
86
self.assertEqual(cmd.name(), cmd.get_help_topic())
102
88
def test_formatted_help_text(self):
103
89
"""Help text should be plain text by default."""
104
90
class cmd_Demo(commands.Command):
105
__doc__ = """A sample command.
159
def test_concise_help_text(self):
160
"""Concise help text excludes the descriptive sections."""
161
class cmd_Demo(commands.Command):
162
__doc__ = """A sample 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):
209
__doc__ = """A sample 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
139
def test_help_text_custom_usage(self):
253
140
"""Help text may contain a custom usage section."""
254
141
class cmd_Demo(commands.Command):
255
__doc__ = """A sample command.
258
145
cmd Demo [opts] args
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'
162
' -h, --help Show help message.\n'
281
165
' Blah blah blah.\n\n')
284
class TestRegisteredTopic(TestHelp):
168
class TestRegisteredTopic(tests.TestCase):
285
169
"""Tests for the RegisteredTopic class."""
287
171
def test_contruct(self):
288
172
"""Construction takes the help topic name for the registered item."""
290
174
self.assertTrue('basic' in help_topics.topic_registry)
291
175
topic = help_topics.RegisteredTopic('basic')
292
176
self.assertEqual('basic', topic.topic)
305
189
'See also: bar, foo\n')
307
def test_get_help_text_loaded_from_file(self):
308
# Pick a known topic stored in an external file
309
topic = help_topics.RegisteredTopic('authentication')
310
self.assertStartsWith(topic.get_help_text(),
311
'Authentication Settings\n'
312
'=======================\n'
315
191
def test_get_help_topic(self):
316
192
"""The help topic for a RegisteredTopic is its topic from construction."""
317
193
topic = help_topics.RegisteredTopic('foobar')