~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_help.py

  • Committer: Ian Clatworthy
  • Date: 2007-08-14 03:59:22 UTC
  • mto: (2733.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2734.
  • Revision ID: ian.clatworthy@internode.on.net-20070814035922-siavg542cwvkf4r5
Fix pretty doc generation so works for all html docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
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
16
16
 
17
17
"""Unit tests for the bzrlib.help module."""
18
18
 
29
29
    )
30
30
 
31
31
 
32
 
class TestHelp(tests.TestCase):
33
 
 
34
 
    def setUp(self):
35
 
        tests.TestCase.setUp(self)
36
 
        commands.install_bzr_command_hooks()
37
 
 
38
 
 
39
32
class TestCommandHelp(tests.TestCase):
40
33
    """Tests for help on commands."""
41
34
 
47
40
        helptext = cmd.get_help_text()
48
41
        self.assertEndsWith(
49
42
            helptext,
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'
53
44
            '\n'
54
45
            'See also: bar, foo\n')
55
46
 
62
53
        self.assertStartsWith(helptext,
63
54
            'Purpose: A sample command.\n'
64
55
            'Usage:   bzr Demo')
65
 
        self.assertEndsWith(helptext,
66
 
            '  -h, --help     Show help message.\n\n')
 
56
        self.assertEndsWith(helptext, 'Show help message.\n\n')
67
57
 
68
58
    def test_command_with_additional_see_also(self):
69
59
        class cmd_WithSeeAlso(commands.Command):
73
63
        helptext = cmd.get_help_text(['gam'])
74
64
        self.assertEndsWith(
75
65
            helptext,
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'
79
67
            '\n'
80
68
            'See also: bar, foo, gam\n')
81
69
 
86
74
        helptext = cmd.get_help_text(['gam'])
87
75
        self.assertEndsWith(
88
76
            helptext,
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'
92
78
            '\n'
93
79
            'See also: gam\n')
94
80
 
103
89
        """Help text should be plain text by default."""
104
90
        class cmd_Demo(commands.Command):
105
91
            """A sample command.
106
 
 
 
92
 
107
93
            :Examples:
108
94
                Example 1::
109
 
 
 
95
 
110
96
                    cmd arg1
111
 
 
 
97
 
112
98
                Example 2::
113
 
 
 
99
 
114
100
                    cmd arg2
115
101
            """
116
102
        cmd = cmd_Demo()
121
107
            'Usage:   bzr Demo\n'
122
108
            '\n'
123
109
            'Options:\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'
 
110
            '  -h, --help  Show help message.\n'
128
111
            '\n'
129
112
            'Examples:\n'
130
113
            '    Example 1:\n'
141
124
            ':Usage:   bzr Demo\n'
142
125
            '\n'
143
126
            ':Options:\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'
 
127
            '  -h, --help  Show help message.\n'
148
128
            '\n'
149
129
            ':Examples:\n'
150
130
            '    Example 1::\n'
156
136
            '        cmd arg2\n'
157
137
            '\n')
158
138
 
159
 
    def test_concise_help_text(self):
160
 
        """Concise help text excludes the descriptive sections."""
161
 
        class cmd_Demo(commands.Command):
162
 
            """A sample command.
163
 
 
164
 
            Blah blah blah.
165
 
 
166
 
            :Examples:
167
 
                Example 1::
168
 
 
169
 
                    cmd arg1
170
 
            """
171
 
        cmd = cmd_Demo()
172
 
        helptext = cmd.get_help_text()
173
 
        self.assertEqualDiff(
174
 
            helptext,
175
 
            'Purpose: A sample command.\n'
176
 
            'Usage:   bzr Demo\n'
177
 
            '\n'
178
 
            'Options:\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'
183
 
            '\n'
184
 
            'Description:\n'
185
 
            '  Blah blah blah.\n'
186
 
            '\n'
187
 
            'Examples:\n'
188
 
            '    Example 1:\n'
189
 
            '\n'
190
 
            '        cmd arg1\n'
191
 
            '\n')
192
 
        helptext = cmd.get_help_text(verbose=False)
193
 
        self.assertEquals(helptext,
194
 
            'Purpose: A sample command.\n'
195
 
            'Usage:   bzr Demo\n'
196
 
            '\n'
197
 
            'Options:\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'
202
 
            '\n'
203
 
            'See bzr help Demo for more details and examples.\n'
204
 
            '\n')
205
 
 
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
 
            """A sample command.
210
 
 
211
 
            Blah blah blah.
212
 
 
213
 
            :Formats:
214
 
              Interesting stuff about formats.
215
 
 
216
 
            :Examples:
217
 
              Example 1::
218
 
 
219
 
                cmd arg1
220
 
 
221
 
            :Tips:
222
 
              Clever things to keep in mind.
223
 
            """
224
 
        cmd = cmd_Demo()
225
 
        helptext = cmd.get_help_text()
226
 
        self.assertEqualDiff(
227
 
            helptext,
228
 
            'Purpose: A sample command.\n'
229
 
            'Usage:   bzr Demo\n'
230
 
            '\n'
231
 
            'Options:\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'
236
 
            '\n'
237
 
            'Description:\n'
238
 
            '  Blah blah blah.\n'
239
 
            '\n'
240
 
            'Formats:\n'
241
 
            '  Interesting stuff about formats.\n'
242
 
            '\n'
243
 
            'Examples:\n'
244
 
            '  Example 1:\n'
245
 
            '\n'
246
 
            '    cmd arg1\n'
247
 
            '\n'
248
 
            'Tips:\n'
249
 
            '  Clever things to keep in mind.\n'
250
 
            '\n')
251
 
 
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
142
            """A sample command.
256
 
 
 
143
 
257
144
            :Usage:
258
145
                cmd Demo [opts] args
259
 
 
 
146
 
260
147
                cmd Demo -h
261
 
 
 
148
 
262
149
            Blah blah blah.
263
150
            """
264
151
        cmd = cmd_Demo()
272
159
            '\n'
273
160
            '\n'
274
161
            'Options:\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'
 
162
            '  -h, --help  Show help message.\n'
279
163
            '\n'
280
164
            'Description:\n'
281
165
            '  Blah blah blah.\n\n')
282
166
 
283
167
 
284
 
class TestRegisteredTopic(TestHelp):
 
168
class TestRegisteredTopic(tests.TestCase):
285
169
    """Tests for the RegisteredTopic class."""
286
170
 
287
171
    def test_contruct(self):
288
172
        """Construction takes the help topic name for the registered item."""
289
 
        # validate our test
 
173
        # validate our test 
290
174
        self.assertTrue('basic' in help_topics.topic_registry)
291
175
        topic = help_topics.RegisteredTopic('basic')
292
176
        self.assertEqual('basic', topic.topic)
304
188
            '\n'
305
189
            'See also: bar, foo\n')
306
190
 
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'
313
 
            '\n')
314
 
 
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')
320
196
        self.assertEqual('baz', topic.get_help_topic())
321
197
 
322
198
 
323
 
class TestTopicIndex(TestHelp):
 
199
class TestTopicIndex(tests.TestCase):
324
200
    """Tests for the HelpTopicIndex class."""
325
201
 
326
202
    def test_default_constructable(self):
353
229
        self.assertEqual('', index.prefix)
354
230
 
355
231
 
356
 
class TestCommandIndex(TestHelp):
 
232
class TestCommandIndex(tests.TestCase):
357
233
    """Tests for the HelpCommandIndex class."""
358
234
 
359
235
    def test_default_constructable(self):