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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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()
32
39
class TestCommandHelp(tests.TestCase):
33
40
"""Tests for help on commands."""
114
121
'Usage: bzr Demo\n'
124
' --usage Show usage message and options.\n'
117
125
' -v, --verbose Display more information.\n'
118
126
' -q, --quiet Only display errors and warnings.\n'
119
127
' -h, --help Show help message.\n'
133
141
':Usage: bzr Demo\n'
144
' --usage Show usage message and options.\n'
136
145
' -v, --verbose Display more information.\n'
137
146
' -q, --quiet Only display errors and warnings.\n'
138
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'
150
252
def test_help_text_custom_usage(self):
151
253
"""Help text may contain a custom usage section."""
152
254
class cmd_Demo(commands.Command):
153
255
"""A sample command.
156
258
cmd Demo [opts] args
275
' --usage Show usage message and options.\n'
173
276
' -v, --verbose Display more information.\n'
174
277
' -q, --quiet Only display errors and warnings.\n'
175
278
' -h, --help Show help message.\n'
178
281
' Blah blah blah.\n\n')
181
class TestRegisteredTopic(tests.TestCase):
284
class TestRegisteredTopic(TestHelp):
182
285
"""Tests for the RegisteredTopic class."""
184
287
def test_contruct(self):
185
288
"""Construction takes the help topic name for the registered item."""
187
290
self.assertTrue('basic' in help_topics.topic_registry)
188
291
topic = help_topics.RegisteredTopic('basic')
189
292
self.assertEqual('basic', topic.topic)
204
307
def test_get_help_text_loaded_from_file(self):
205
308
# Pick a known topic stored in an external file
206
topic = help_topics.RegisteredTopic('hooks')
309
topic = help_topics.RegisteredTopic('authentication')
207
310
self.assertStartsWith(topic.get_help_text(),
311
'Authentication Settings\n'
312
'=======================\n'
212
315
def test_get_help_topic(self):
217
320
self.assertEqual('baz', topic.get_help_topic())
220
class TestTopicIndex(tests.TestCase):
323
class TestTopicIndex(TestHelp):
221
324
"""Tests for the HelpTopicIndex class."""
223
326
def test_default_constructable(self):
250
353
self.assertEqual('', index.prefix)
253
class TestCommandIndex(tests.TestCase):
356
class TestCommandIndex(TestHelp):
254
357
"""Tests for the HelpCommandIndex class."""
256
359
def test_default_constructable(self):