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."""
40
40
helptext = cmd.get_help_text()
41
41
self.assertEndsWith(
43
' -h, --help Show help message.\n'
43
' -v, --verbose Display more information.\n'
44
' -q, --quiet Only display errors and warnings.\n'
45
' -h, --help Show help message.\n'
45
47
'See also: bar, foo\n')
53
55
self.assertStartsWith(helptext,
54
56
'Purpose: A sample command.\n'
56
self.assertEndsWith(helptext, 'Show help message.\n\n')
58
self.assertEndsWith(helptext,
59
' -h, --help Show help message.\n\n')
58
61
def test_command_with_additional_see_also(self):
59
62
class cmd_WithSeeAlso(commands.Command):
63
66
helptext = cmd.get_help_text(['gam'])
64
67
self.assertEndsWith(
66
' -h, --help Show help message.\n'
69
' -v, --verbose Display more information.\n'
70
' -q, --quiet Only display errors and warnings.\n'
71
' -h, --help Show help message.\n'
68
73
'See also: bar, foo, gam\n')
74
79
helptext = cmd.get_help_text(['gam'])
75
80
self.assertEndsWith(
77
' -h, --help Show help message.\n'
82
' -v, --verbose Display more information.\n'
83
' -q, --quiet Only display errors and warnings.\n'
84
' -h, --help Show help message.\n'
107
114
'Usage: bzr Demo\n'
110
' -h, --help Show help message.\n'
117
' --usage Show usage message and options.\n'
118
' -v, --verbose Display more information.\n'
119
' -q, --quiet Only display errors and warnings.\n'
120
' -h, --help Show help message.\n'
124
134
':Usage: bzr Demo\n'
127
' -h, --help Show help message.\n'
137
' --usage Show usage message and options.\n'
138
' -v, --verbose Display more information.\n'
139
' -q, --quiet Only display errors and warnings.\n'
140
' -h, --help Show help message.\n'
152
def test_concise_help_text(self):
153
"""Concise help text excludes the descriptive sections."""
154
class cmd_Demo(commands.Command):
165
helptext = cmd.get_help_text()
166
self.assertEqualDiff(
168
'Purpose: A sample command.\n'
172
' --usage Show usage message and options.\n'
173
' -v, --verbose Display more information.\n'
174
' -q, --quiet Only display errors and warnings.\n'
175
' -h, --help Show help message.\n'
185
helptext = cmd.get_help_text(verbose=False)
186
self.assertEquals(helptext,
187
'Purpose: A sample command.\n'
191
' --usage Show usage message and options.\n'
192
' -v, --verbose Display more information.\n'
193
' -q, --quiet Only display errors and warnings.\n'
194
' -h, --help Show help message.\n'
196
'See bzr help Demo for more details and examples.\n'
199
def test_help_custom_section_ordering(self):
200
"""Custom descriptive sections should remain in the order given."""
201
class cmd_Demo(commands.Command):
207
Interesting stuff about formats.
215
Clever things to keep in mind.
218
helptext = cmd.get_help_text()
219
self.assertEqualDiff(
221
'Purpose: A sample command.\n'
225
' --usage Show usage message and options.\n'
226
' -v, --verbose Display more information.\n'
227
' -q, --quiet Only display errors and warnings.\n'
228
' -h, --help Show help message.\n'
234
' Interesting stuff about formats.\n'
242
' Clever things to keep in mind.\n'
139
245
def test_help_text_custom_usage(self):
140
246
"""Help text may contain a custom usage section."""
141
247
class cmd_Demo(commands.Command):
142
248
"""A sample command.
145
251
cmd Demo [opts] args
162
' -h, --help Show help message.\n'
268
' --usage Show usage message and options.\n'
269
' -v, --verbose Display more information.\n'
270
' -q, --quiet Only display errors and warnings.\n'
271
' -h, --help Show help message.\n'
165
274
' Blah blah blah.\n\n')
171
280
def test_contruct(self):
172
281
"""Construction takes the help topic name for the registered item."""
174
283
self.assertTrue('basic' in help_topics.topic_registry)
175
284
topic = help_topics.RegisteredTopic('basic')
176
285
self.assertEqual('basic', topic.topic)
189
298
'See also: bar, foo\n')
300
def test_get_help_text_loaded_from_file(self):
301
# Pick a known topic stored in an external file
302
topic = help_topics.RegisteredTopic('authentication')
303
self.assertStartsWith(topic.get_help_text(),
304
'Authentication Settings\n'
305
'=======================\n'
191
308
def test_get_help_topic(self):
192
309
"""The help topic for a RegisteredTopic is its topic from construction."""
193
310
topic = help_topics.RegisteredTopic('foobar')