/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2007-2012, 2016 Canonical Ltd
2425.2.2 by Robert Collins
``bzr help`` now provides cross references to other help topics using the
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2425.2.2 by Robert Collins
``bzr help`` now provides cross references to other help topics using the
16
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
17
"""Unit tests for the breezy.help module."""
2425.2.2 by Robert Collins
``bzr help`` now provides cross references to other help topics using the
18
5875.3.23 by Vincent Ladeuil
Put the '\n' back into the formats and fix tests accordingly (reducing code duplication).
19
import textwrap
20
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
21
from .. import (
2432.1.13 by Robert Collins
HelpCommandContext now implementes get_topics.
22
    builtins,
2425.2.2 by Robert Collins
``bzr help`` now provides cross references to other help topics using the
23
    commands,
6059.3.2 by Vincent Ladeuil
Cough, with tests.
24
    config,
2432.1.5 by Robert Collins
Initial stub for topic searching.
25
    errors,
2425.2.2 by Robert Collins
``bzr help`` now provides cross references to other help topics using the
26
    help,
2432.1.1 by Robert Collins
Add a HelpTopicContext object.
27
    help_topics,
5875.3.12 by INADA Naoki
Add test for command help translation.
28
    i18n,
2432.1.24 by Robert Collins
Add plugins as a help index.
29
    plugin,
2425.2.2 by Robert Collins
``bzr help`` now provides cross references to other help topics using the
30
    tests,
31
    )
32
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
33
from .test_i18n import ZzzTranslations
5875.3.12 by INADA Naoki
Add test for command help translation.
34
import re
35
2425.2.2 by Robert Collins
``bzr help`` now provides cross references to other help topics using the
36
6734.1.22 by Jelmer Vernooij
review comments.
37
class TestErrors(tests.TestCase):
6731.1.2 by Jelmer Vernooij
Move NoHelpTopic error to breesy.help.
38
39
    def test_no_help_topic(self):
40
        error = help.NoHelpTopic("topic")
41
        self.assertEqualDiff("No help could be found for 'topic'. "
7143.15.2 by Jelmer Vernooij
Run autopep8.
42
                             "Please use 'brz help topics' to obtain a list of topics.",
43
                             str(error))
6731.1.2 by Jelmer Vernooij
Move NoHelpTopic error to breesy.help.
44
45
2425.2.2 by Robert Collins
``bzr help`` now provides cross references to other help topics using the
46
class TestCommandHelp(tests.TestCase):
47
    """Tests for help on commands."""
48
5875.3.26 by Vincent Ladeuil
Tweak test_help some more.
49
    def assertCmdHelp(self, expected, cmd):
50
        self.assertEqualDiff(textwrap.dedent(expected), cmd.get_help_text())
51
2425.2.2 by Robert Collins
``bzr help`` now provides cross references to other help topics using the
52
    def test_command_help_includes_see_also(self):
53
        class cmd_WithSeeAlso(commands.Command):
5131.2.1 by Martin
Permit bzrlib to run under python -OO by explictly assigning to __doc__ for user-visible docstrings
54
            __doc__ = """A sample command."""
2425.2.2 by Robert Collins
``bzr help`` now provides cross references to other help topics using the
55
            _see_also = ['foo', 'bar']
5875.3.26 by Vincent Ladeuil
Tweak test_help some more.
56
        self.assertCmdHelp('''\
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
57
Purpose: A sample command.
6622.1.4 by Jelmer Vernooij
Fix some more tests.
58
Usage:   brz WithSeeAlso
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
59
60
Options:
7045.4.23 by Jelmer Vernooij
Fix some help tests.
61
  -h, --help     Show help message.
62
  -q, --quiet    Only display errors and warnings.
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
63
  --usage        Show usage message and options.
64
  -v, --verbose  Display more information.
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
65
66
See also: bar, foo
67
''',
5875.3.26 by Vincent Ladeuil
Tweak test_help some more.
68
                           cmd_WithSeeAlso())
2432.1.1 by Robert Collins
Add a HelpTopicContext object.
69
2432.1.12 by Robert Collins
Relocate command help onto Command.
70
    def test_get_help_text(self):
71
        """Commands have a get_help_text method which returns their help."""
72
        class cmd_Demo(commands.Command):
5131.2.1 by Martin
Permit bzrlib to run under python -OO by explictly assigning to __doc__ for user-visible docstrings
73
            __doc__ = """A sample command."""
5875.3.26 by Vincent Ladeuil
Tweak test_help some more.
74
        self.assertCmdHelp('''\
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
75
Purpose: A sample command.
6622.1.4 by Jelmer Vernooij
Fix some more tests.
76
Usage:   brz Demo
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
77
78
Options:
7045.4.23 by Jelmer Vernooij
Fix some help tests.
79
  -h, --help     Show help message.
80
  -q, --quiet    Only display errors and warnings.
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
81
  --usage        Show usage message and options.
82
  -v, --verbose  Display more information.
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
83
84
''',
5875.3.26 by Vincent Ladeuil
Tweak test_help some more.
85
                           cmd_Demo())
2432.1.12 by Robert Collins
Relocate command help onto Command.
86
        cmd = cmd_Demo()
87
        helptext = cmd.get_help_text()
2666.1.4 by Ian Clatworthy
Add help formatting tests
88
        self.assertStartsWith(helptext,
7143.15.2 by Jelmer Vernooij
Run autopep8.
89
                              'Purpose: A sample command.\n'
90
                              'Usage:   brz Demo')
2768.1.6 by Ian Clatworthy
Fix existing option and help tests
91
        self.assertEndsWith(helptext,
7143.15.2 by Jelmer Vernooij
Run autopep8.
92
                            '  -v, --verbose  Display more information.\n\n')
2432.1.21 by Robert Collins
Teach Command.get_help_text to show additional help cross references when supplied.
93
94
    def test_command_with_additional_see_also(self):
95
        class cmd_WithSeeAlso(commands.Command):
5131.2.1 by Martin
Permit bzrlib to run under python -OO by explictly assigning to __doc__ for user-visible docstrings
96
            __doc__ = """A sample command."""
2432.1.21 by Robert Collins
Teach Command.get_help_text to show additional help cross references when supplied.
97
            _see_also = ['foo', 'bar']
98
        cmd = cmd_WithSeeAlso()
99
        helptext = cmd.get_help_text(['gam'])
100
        self.assertEndsWith(
101
            helptext,
7045.4.23 by Jelmer Vernooij
Fix some help tests.
102
            '  -h, --help     Show help message.\n'
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
103
            '  -q, --quiet    Only display errors and warnings.\n'
7045.4.23 by Jelmer Vernooij
Fix some help tests.
104
            '  --usage        Show usage message and options.\n'
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
105
            '  -v, --verbose  Display more information.\n'
2432.1.21 by Robert Collins
Teach Command.get_help_text to show additional help cross references when supplied.
106
            '\n'
107
            'See also: bar, foo, gam\n')
108
109
    def test_command_only_additional_see_also(self):
110
        class cmd_WithSeeAlso(commands.Command):
5131.2.1 by Martin
Permit bzrlib to run under python -OO by explictly assigning to __doc__ for user-visible docstrings
111
            __doc__ = """A sample command."""
2432.1.21 by Robert Collins
Teach Command.get_help_text to show additional help cross references when supplied.
112
        cmd = cmd_WithSeeAlso()
113
        helptext = cmd.get_help_text(['gam'])
114
        self.assertEndsWith(
115
            helptext,
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
116
            '  -v, --verbose  Display more information.\n'
2432.1.21 by Robert Collins
Teach Command.get_help_text to show additional help cross references when supplied.
117
            '\n'
118
            'See also: gam\n')
2432.1.28 by Robert Collins
Add a get_help_topic method to commands.Command.
119
120
    def test_get_help_topic(self):
121
        """The help topic for a Command is its name()."""
122
        class cmd_foo_bar(commands.Command):
5131.2.1 by Martin
Permit bzrlib to run under python -OO by explictly assigning to __doc__ for user-visible docstrings
123
            __doc__ = """A sample command."""
2432.1.28 by Robert Collins
Add a get_help_topic method to commands.Command.
124
        cmd = cmd_foo_bar()
125
        self.assertEqual(cmd.name(), cmd.get_help_topic())
2666.1.4 by Ian Clatworthy
Add help formatting tests
126
127
    def test_formatted_help_text(self):
128
        """Help text should be plain text by default."""
129
        class cmd_Demo(commands.Command):
5131.2.1 by Martin
Permit bzrlib to run under python -OO by explictly assigning to __doc__ for user-visible docstrings
130
            __doc__ = """A sample command.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
131
2666.1.4 by Ian Clatworthy
Add help formatting tests
132
            :Examples:
133
                Example 1::
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
134
2666.1.4 by Ian Clatworthy
Add help formatting tests
135
                    cmd arg1
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
136
2666.1.4 by Ian Clatworthy
Add help formatting tests
137
                Example 2::
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
138
2666.1.4 by Ian Clatworthy
Add help formatting tests
139
                    cmd arg2
5215.2.3 by John Szakmeister
Test help formatting of standalone code blocks.
140
141
                A code block follows.
142
143
                ::
144
6622.1.4 by Jelmer Vernooij
Fix some more tests.
145
                    brz Demo something
2666.1.4 by Ian Clatworthy
Add help formatting tests
146
            """
147
        cmd = cmd_Demo()
148
        helptext = cmd.get_help_text()
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
149
        self.assertEqualDiff('''\
150
Purpose: A sample command.
6622.1.4 by Jelmer Vernooij
Fix some more tests.
151
Usage:   brz Demo
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
152
153
Options:
7045.4.23 by Jelmer Vernooij
Fix some help tests.
154
  -h, --help     Show help message.
155
  -q, --quiet    Only display errors and warnings.
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
156
  --usage        Show usage message and options.
157
  -v, --verbose  Display more information.
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
158
159
Examples:
160
    Example 1:
161
162
        cmd arg1
163
164
    Example 2:
165
166
        cmd arg2
167
168
    A code block follows.
169
6622.1.4 by Jelmer Vernooij
Fix some more tests.
170
        brz Demo something
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
171
172
''',
7143.15.2 by Jelmer Vernooij
Run autopep8.
173
                             helptext)
2666.1.4 by Ian Clatworthy
Add help formatting tests
174
        helptext = cmd.get_help_text(plain=False)
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
175
        self.assertEqualDiff('''\
176
:Purpose: A sample command.
6622.1.4 by Jelmer Vernooij
Fix some more tests.
177
:Usage:   brz Demo
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
178
179
:Options:
7045.4.23 by Jelmer Vernooij
Fix some help tests.
180
  -h, --help     Show help message.
181
  -q, --quiet    Only display errors and warnings.
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
182
  --usage        Show usage message and options.
183
  -v, --verbose  Display more information.
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
184
185
:Examples:
186
    Example 1::
187
188
        cmd arg1
189
190
    Example 2::
191
192
        cmd arg2
193
194
    A code block follows.
195
196
    ::
197
6622.1.4 by Jelmer Vernooij
Fix some more tests.
198
        brz Demo something
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
199
200
''',
201
                             helptext)
2666.1.4 by Ian Clatworthy
Add help formatting tests
202
3984.4.1 by Ian Clatworthy
get_help_text() verbose parameter & keep custom sections ordered
203
    def test_concise_help_text(self):
204
        """Concise help text excludes the descriptive sections."""
205
        class cmd_Demo(commands.Command):
5131.2.1 by Martin
Permit bzrlib to run under python -OO by explictly assigning to __doc__ for user-visible docstrings
206
            __doc__ = """A sample command.
7195.5.1 by Martin
Fix remaining whitespace lint in codebase
207
3984.4.1 by Ian Clatworthy
get_help_text() verbose parameter & keep custom sections ordered
208
            Blah blah blah.
209
210
            :Examples:
211
                Example 1::
7195.5.1 by Martin
Fix remaining whitespace lint in codebase
212
3984.4.1 by Ian Clatworthy
get_help_text() verbose parameter & keep custom sections ordered
213
                    cmd arg1
214
            """
215
        cmd = cmd_Demo()
216
        helptext = cmd.get_help_text()
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
217
        self.assertEqualDiff('''\
218
Purpose: A sample command.
6622.1.4 by Jelmer Vernooij
Fix some more tests.
219
Usage:   brz Demo
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
220
221
Options:
7045.4.23 by Jelmer Vernooij
Fix some help tests.
222
  -h, --help     Show help message.
223
  -q, --quiet    Only display errors and warnings.
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
224
  --usage        Show usage message and options.
225
  -v, --verbose  Display more information.
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
226
227
Description:
228
  Blah blah blah.
229
230
Examples:
231
    Example 1:
232
233
        cmd arg1
234
235
''',
236
                             helptext)
3984.4.1 by Ian Clatworthy
get_help_text() verbose parameter & keep custom sections ordered
237
        helptext = cmd.get_help_text(verbose=False)
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
238
        self.assertEqualDiff('''\
239
Purpose: A sample command.
6622.1.4 by Jelmer Vernooij
Fix some more tests.
240
Usage:   brz Demo
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
241
242
Options:
7045.4.23 by Jelmer Vernooij
Fix some help tests.
243
  -h, --help     Show help message.
244
  -q, --quiet    Only display errors and warnings.
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
245
  --usage        Show usage message and options.
246
  -v, --verbose  Display more information.
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
247
6622.1.4 by Jelmer Vernooij
Fix some more tests.
248
See brz help Demo for more details and examples.
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
249
250
''',
251
                             helptext)
3984.4.1 by Ian Clatworthy
get_help_text() verbose parameter & keep custom sections ordered
252
253
    def test_help_custom_section_ordering(self):
254
        """Custom descriptive sections should remain in the order given."""
255
        class cmd_Demo(commands.Command):
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
256
            __doc__ = """\
257
A sample command.
258
259
Blah blah blah.
260
261
:Formats:
262
  Interesting stuff about formats.
263
264
:Examples:
265
  Example 1::
266
267
    cmd arg1
268
269
:Tips:
270
  Clever things to keep in mind.
271
"""
3984.4.1 by Ian Clatworthy
get_help_text() verbose parameter & keep custom sections ordered
272
        cmd = cmd_Demo()
273
        helptext = cmd.get_help_text()
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
274
        self.assertEqualDiff('''\
275
Purpose: A sample command.
6622.1.4 by Jelmer Vernooij
Fix some more tests.
276
Usage:   brz Demo
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
277
278
Options:
7045.4.23 by Jelmer Vernooij
Fix some help tests.
279
  -h, --help     Show help message.
280
  -q, --quiet    Only display errors and warnings.
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
281
  --usage        Show usage message and options.
282
  -v, --verbose  Display more information.
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
283
284
Description:
285
  Blah blah blah.
286
287
Formats:
288
  Interesting stuff about formats.
289
290
Examples:
291
  Example 1:
292
293
    cmd arg1
294
295
Tips:
296
  Clever things to keep in mind.
297
298
''',
299
                             helptext)
3984.4.1 by Ian Clatworthy
get_help_text() verbose parameter & keep custom sections ordered
300
2666.1.4 by Ian Clatworthy
Add help formatting tests
301
    def test_help_text_custom_usage(self):
302
        """Help text may contain a custom usage section."""
303
        class cmd_Demo(commands.Command):
5131.2.1 by Martin
Permit bzrlib to run under python -OO by explictly assigning to __doc__ for user-visible docstrings
304
            __doc__ = """A sample command.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
305
2666.1.4 by Ian Clatworthy
Add help formatting tests
306
            :Usage:
307
                cmd Demo [opts] args
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
308
2666.1.4 by Ian Clatworthy
Add help formatting tests
309
                cmd Demo -h
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
310
2666.1.4 by Ian Clatworthy
Add help formatting tests
311
            Blah blah blah.
312
            """
313
        cmd = cmd_Demo()
314
        helptext = cmd.get_help_text()
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
315
        self.assertEqualDiff('''\
316
Purpose: A sample command.
317
Usage:
318
    cmd Demo [opts] args
319
320
    cmd Demo -h
321
322
323
Options:
7045.4.23 by Jelmer Vernooij
Fix some help tests.
324
  -h, --help     Show help message.
325
  -q, --quiet    Only display errors and warnings.
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
326
  --usage        Show usage message and options.
327
  -v, --verbose  Display more information.
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
328
329
Description:
330
  Blah blah blah.
331
332
''',
333
                             helptext)
2666.1.4 by Ian Clatworthy
Add help formatting tests
334
2432.1.1 by Robert Collins
Add a HelpTopicContext object.
335
5875.3.12 by INADA Naoki
Add test for command help translation.
336
class ZzzTranslationsForDoc(ZzzTranslations):
337
6798.1.1 by Jelmer Vernooij
Properly escape backslashes.
338
    _section_pat = re.compile(':\\w+:\\n\\s+')
5875.3.12 by INADA Naoki
Add test for command help translation.
339
    _indent_pat = re.compile('\\s+')
340
341
    def zzz(self, s):
342
        m = self._section_pat.match(s)
343
        if m is None:
344
            m = self._indent_pat.match(s)
345
        if m:
346
            return u'%szz{{%s}}' % (m.group(0), s[m.end():])
347
        return u'zz{{%s}}' % s
348
349
350
class TestCommandHelpI18n(tests.TestCase):
351
    """Tests for help on translated commands."""
352
353
    def setUp(self):
354
        super(TestCommandHelpI18n, self).setUp()
5875.3.25 by Vincent Ladeuil
Fix test failures and make sure we don't rely on a default translation.
355
        self.overrideAttr(i18n, '_translations', ZzzTranslationsForDoc())
5875.3.12 by INADA Naoki
Add test for command help translation.
356
5875.3.23 by Vincent Ladeuil
Put the '\n' back into the formats and fix tests accordingly (reducing code duplication).
357
    def assertCmdHelp(self, expected, cmd):
358
        self.assertEqualDiff(textwrap.dedent(expected), cmd.get_help_text())
5875.3.12 by INADA Naoki
Add test for command help translation.
359
360
    def test_command_help_includes_see_also(self):
361
        class cmd_WithSeeAlso(commands.Command):
362
            __doc__ = """A sample command."""
363
            _see_also = ['foo', 'bar']
5875.3.23 by Vincent Ladeuil
Put the '\n' back into the formats and fix tests accordingly (reducing code duplication).
364
        self.assertCmdHelp('''\
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
365
zz{{:Purpose: zz{{A sample command.}}
6622.1.4 by Jelmer Vernooij
Fix some more tests.
366
}}zz{{:Usage:   brz WithSeeAlso
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
367
}}
368
zz{{:Options:
7045.4.23 by Jelmer Vernooij
Fix some help tests.
369
  -h, --help     zz{{Show help message.}}
370
  -q, --quiet    zz{{Only display errors and warnings.}}
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
371
  --usage        zz{{Show usage message and options.}}
372
  -v, --verbose  zz{{Display more information.}}
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
373
}}
374
zz{{:See also: bar, foo}}
375
''',
5875.3.23 by Vincent Ladeuil
Put the '\n' back into the formats and fix tests accordingly (reducing code duplication).
376
                           cmd_WithSeeAlso())
5875.3.12 by INADA Naoki
Add test for command help translation.
377
378
    def test_get_help_text(self):
379
        """Commands have a get_help_text method which returns their help."""
380
        class cmd_Demo(commands.Command):
381
            __doc__ = """A sample command."""
5875.3.23 by Vincent Ladeuil
Put the '\n' back into the formats and fix tests accordingly (reducing code duplication).
382
        self.assertCmdHelp('''\
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
383
zz{{:Purpose: zz{{A sample command.}}
6622.1.4 by Jelmer Vernooij
Fix some more tests.
384
}}zz{{:Usage:   brz Demo
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
385
}}
386
zz{{:Options:
7045.4.23 by Jelmer Vernooij
Fix some help tests.
387
  -h, --help     zz{{Show help message.}}
388
  -q, --quiet    zz{{Only display errors and warnings.}}
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
389
  --usage        zz{{Show usage message and options.}}
390
  -v, --verbose  zz{{Display more information.}}
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
391
}}
392
''',
5875.3.23 by Vincent Ladeuil
Put the '\n' back into the formats and fix tests accordingly (reducing code duplication).
393
                           cmd_Demo())
5875.3.12 by INADA Naoki
Add test for command help translation.
394
395
    def test_command_with_additional_see_also(self):
396
        class cmd_WithSeeAlso(commands.Command):
397
            __doc__ = """A sample command."""
398
            _see_also = ['foo', 'bar']
399
        cmd = cmd_WithSeeAlso()
400
        helptext = cmd.get_help_text(['gam'])
401
        self.assertEndsWith(
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
402
            helptext, '''\
7045.4.23 by Jelmer Vernooij
Fix some help tests.
403
  -h, --help     zz{{Show help message.}}
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
404
  -q, --quiet    zz{{Only display errors and warnings.}}
7045.4.23 by Jelmer Vernooij
Fix some help tests.
405
  --usage        zz{{Show usage message and options.}}
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
406
  -v, --verbose  zz{{Display more information.}}
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
407
}}
408
zz{{:See also: bar, foo, gam}}
409
''')
5875.3.12 by INADA Naoki
Add test for command help translation.
410
411
    def test_command_only_additional_see_also(self):
412
        class cmd_WithSeeAlso(commands.Command):
413
            __doc__ = """A sample command."""
414
        cmd = cmd_WithSeeAlso()
415
        helptext = cmd.get_help_text(['gam'])
416
        self.assertEndsWith(
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
417
            helptext, '''\
418
zz{{:Options:
7045.4.23 by Jelmer Vernooij
Fix some help tests.
419
  -h, --help     zz{{Show help message.}}
420
  -q, --quiet    zz{{Only display errors and warnings.}}
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
421
  --usage        zz{{Show usage message and options.}}
422
  -v, --verbose  zz{{Display more information.}}
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
423
}}
424
zz{{:See also: gam}}
425
''')
5875.3.12 by INADA Naoki
Add test for command help translation.
426
427
    def test_help_custom_section_ordering(self):
428
        """Custom descriptive sections should remain in the order given."""
5875.3.23 by Vincent Ladeuil
Put the '\n' back into the formats and fix tests accordingly (reducing code duplication).
429
        # The help formatter expect the class name to start with 'cmd_'
5875.3.12 by INADA Naoki
Add test for command help translation.
430
        class cmd_Demo(commands.Command):
431
            __doc__ = """A sample command.
7195.5.1 by Martin
Fix remaining whitespace lint in codebase
432
5875.3.12 by INADA Naoki
Add test for command help translation.
433
            Blah blah blah.
434
435
            :Formats:
436
              Interesting stuff about formats.
437
438
            :Examples:
439
              Example 1::
7195.5.1 by Martin
Fix remaining whitespace lint in codebase
440
5875.3.12 by INADA Naoki
Add test for command help translation.
441
                cmd arg1
442
443
            :Tips:
444
              Clever things to keep in mind.
445
            """
5875.3.23 by Vincent Ladeuil
Put the '\n' back into the formats and fix tests accordingly (reducing code duplication).
446
        self.assertCmdHelp('''\
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
447
zz{{:Purpose: zz{{A sample command.}}
6622.1.4 by Jelmer Vernooij
Fix some more tests.
448
}}zz{{:Usage:   brz Demo
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
449
}}
450
zz{{:Options:
7045.4.23 by Jelmer Vernooij
Fix some help tests.
451
  -h, --help     zz{{Show help message.}}
452
  -q, --quiet    zz{{Only display errors and warnings.}}
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
453
  --usage        zz{{Show usage message and options.}}
454
  -v, --verbose  zz{{Display more information.}}
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
455
}}
456
Description:
457
  zz{{zz{{Blah blah blah.}}
7195.5.1 by Martin
Fix remaining whitespace lint in codebase
458
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
459
}}:Formats:
460
  zz{{Interesting stuff about formats.}}
7195.5.1 by Martin
Fix remaining whitespace lint in codebase
461
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
462
Examples:
463
  zz{{Example 1::}}
7195.5.1 by Martin
Fix remaining whitespace lint in codebase
464
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
465
    zz{{cmd arg1}}
7195.5.1 by Martin
Fix remaining whitespace lint in codebase
466
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
467
Tips:
468
  zz{{Clever things to keep in mind.}}
7195.5.1 by Martin
Fix remaining whitespace lint in codebase
469
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
470
''',
5875.3.23 by Vincent Ladeuil
Put the '\n' back into the formats and fix tests accordingly (reducing code duplication).
471
                           cmd_Demo())
5875.3.12 by INADA Naoki
Add test for command help translation.
472
473
    def test_help_text_custom_usage(self):
474
        """Help text may contain a custom usage section."""
475
        class cmd_Demo(commands.Command):
476
            __doc__ = """A sample command.
477
478
            :Usage:
479
                cmd Demo [opts] args
480
481
                cmd Demo -h
482
483
            Blah blah blah.
484
            """
5875.3.23 by Vincent Ladeuil
Put the '\n' back into the formats and fix tests accordingly (reducing code duplication).
485
        self.assertCmdHelp('''\
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
486
zz{{:Purpose: zz{{A sample command.}}
487
}}zz{{:Usage:
488
    zz{{cmd Demo [opts] args}}
489
490
    zz{{cmd Demo -h}}
491
492
}}
493
zz{{:Options:
7045.4.23 by Jelmer Vernooij
Fix some help tests.
494
  -h, --help     zz{{Show help message.}}
495
  -q, --quiet    zz{{Only display errors and warnings.}}
6161.1.4 by Vincent Ladeuil
Follow the lead of other 'global' options which are not declared in option.py but handled in bzrlib.commands.run_bzr instead.
496
  --usage        zz{{Show usage message and options.}}
497
  -v, --verbose  zz{{Display more information.}}
6161.1.1 by Vincent Ladeuil
Allow config options to be overridden from the command line
498
}}
499
Description:
500
  zz{{zz{{Blah blah blah.}}
501
502
}}
503
''',
5875.3.23 by Vincent Ladeuil
Put the '\n' back into the formats and fix tests accordingly (reducing code duplication).
504
                           cmd_Demo())
5875.3.12 by INADA Naoki
Add test for command help translation.
505
506
5875.3.26 by Vincent Ladeuil
Tweak test_help some more.
507
class TestHelp(tests.TestCase):
508
509
    def setUp(self):
6552.1.3 by Vincent Ladeuil
Use super() instead of calling <base>.setup(self), as the original fix illustrated a too-easy-to-fall-into trap.
510
        super(TestHelp, self).setUp()
5875.3.26 by Vincent Ladeuil
Tweak test_help some more.
511
        commands.install_bzr_command_hooks()
512
513
4119.3.15 by Robert Collins
And fix tests for bzr help.
514
class TestRegisteredTopic(TestHelp):
2432.1.8 by Robert Collins
HelpTopicContext now returns RegisteredTopic objects for get_topics calls.
515
    """Tests for the RegisteredTopic class."""
516
517
    def test_contruct(self):
518
        """Construction takes the help topic name for the registered item."""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
519
        # validate our test
2432.1.8 by Robert Collins
HelpTopicContext now returns RegisteredTopic objects for get_topics calls.
520
        self.assertTrue('basic' in help_topics.topic_registry)
521
        topic = help_topics.RegisteredTopic('basic')
522
        self.assertEqual('basic', topic.topic)
523
2432.1.10 by Robert Collins
Add get_help_text() to RegisteredTopic to get the help as a string.
524
    def test_get_help_text(self):
5875.3.26 by Vincent Ladeuil
Tweak test_help some more.
525
        """RegisteredTopic returns the get_detail results for get_help_text."""
2432.1.10 by Robert Collins
Add get_help_text() to RegisteredTopic to get the help as a string.
526
        topic = help_topics.RegisteredTopic('commands')
527
        self.assertEqual(help_topics.topic_registry.get_detail('commands'),
5875.3.26 by Vincent Ladeuil
Tweak test_help some more.
528
                         topic.get_help_text())
2432.1.10 by Robert Collins
Add get_help_text() to RegisteredTopic to get the help as a string.
529
2432.1.22 by Robert Collins
Teach RegisteredTopic to support the additional_see_also list of related help terms.
530
    def test_get_help_text_with_additional_see_also(self):
531
        topic = help_topics.RegisteredTopic('commands')
532
        self.assertEndsWith(
533
            topic.get_help_text(['foo', 'bar']),
534
            '\n'
535
            'See also: bar, foo\n')
536
3089.3.5 by Ian Clatworthy
add test for loading help from a file
537
    def test_get_help_text_loaded_from_file(self):
538
        # Pick a known topic stored in an external file
4119.3.2 by Robert Collins
Migrate existing hooks over to the new HookPoint infrastructure.
539
        topic = help_topics.RegisteredTopic('authentication')
3089.3.5 by Ian Clatworthy
add test for loading help from a file
540
        self.assertStartsWith(topic.get_help_text(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
541
                              'Authentication Settings\n'
542
                              '=======================\n'
543
                              '\n')
3089.3.5 by Ian Clatworthy
add test for loading help from a file
544
2432.1.27 by Robert Collins
Add a get_help_topic method to RegisteredTopic.
545
    def test_get_help_topic(self):
5875.3.26 by Vincent Ladeuil
Tweak test_help some more.
546
        """The help topic for RegisteredTopic is its topic from construction."""
2432.1.27 by Robert Collins
Add a get_help_topic method to RegisteredTopic.
547
        topic = help_topics.RegisteredTopic('foobar')
548
        self.assertEqual('foobar', topic.get_help_topic())
549
        topic = help_topics.RegisteredTopic('baz')
550
        self.assertEqual('baz', topic.get_help_topic())
551
2432.1.8 by Robert Collins
HelpTopicContext now returns RegisteredTopic objects for get_topics calls.
552
4119.3.15 by Robert Collins
And fix tests for bzr help.
553
class TestTopicIndex(TestHelp):
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
554
    """Tests for the HelpTopicIndex class."""
2432.1.1 by Robert Collins
Add a HelpTopicContext object.
555
2432.1.3 by Robert Collins
Create a HelpContexts object to do help lookups.
556
    def test_default_constructable(self):
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
557
        index = help_topics.HelpTopicIndex()
2432.1.1 by Robert Collins
Add a HelpTopicContext object.
558
2432.1.8 by Robert Collins
HelpTopicContext now returns RegisteredTopic objects for get_topics calls.
559
    def test_get_topics_None(self):
560
        """Searching for None returns the basic help topic."""
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
561
        index = help_topics.HelpTopicIndex()
562
        topics = index.get_topics(None)
2432.1.8 by Robert Collins
HelpTopicContext now returns RegisteredTopic objects for get_topics calls.
563
        self.assertEqual(1, len(topics))
564
        self.assertIsInstance(topics[0], help_topics.RegisteredTopic)
565
        self.assertEqual('basic', topics[0].topic)
566
567
    def test_get_topics_topics(self):
568
        """Searching for a string returns the matching string."""
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
569
        index = help_topics.HelpTopicIndex()
570
        topics = index.get_topics('topics')
2432.1.8 by Robert Collins
HelpTopicContext now returns RegisteredTopic objects for get_topics calls.
571
        self.assertEqual(1, len(topics))
572
        self.assertIsInstance(topics[0], help_topics.RegisteredTopic)
573
        self.assertEqual('topics', topics[0].topic)
574
575
    def test_get_topics_no_topic(self):
576
        """Searching for something not registered returns []."""
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
577
        index = help_topics.HelpTopicIndex()
578
        self.assertEqual([], index.get_topics('nothing by this name'))
579
2432.1.17 by Robert Collins
Add prefixes to HelpIndexes.
580
    def test_prefix(self):
581
        """TopicIndex has a prefix of ''."""
582
        index = help_topics.HelpTopicIndex()
583
        self.assertEqual('', index.prefix)
584
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
585
6059.3.3 by Vincent Ladeuil
Fix typos caught by Jelmer.
586
class TestConfigOptionIndex(TestHelp):
6059.3.2 by Vincent Ladeuil
Cough, with tests.
587
    """Tests for the HelpCommandIndex class."""
588
589
    def setUp(self):
6059.3.3 by Vincent Ladeuil
Fix typos caught by Jelmer.
590
        super(TestConfigOptionIndex, self).setUp()
6059.3.2 by Vincent Ladeuil
Cough, with tests.
591
        self.index = help_topics.ConfigOptionHelpIndex()
592
593
    def test_get_topics_None(self):
594
        """Searching for None returns an empty list."""
595
        self.assertEqual([], self.index.get_topics(None))
596
597
    def test_get_topics_no_topic(self):
598
        self.assertEqual([], self.index.get_topics('nothing by this name'))
599
600
    def test_prefix(self):
601
        self.assertEqual('configuration/', self.index.prefix)
602
603
    def test_get_topic_with_prefix(self):
604
        topics = self.index.get_topics('configuration/default_format')
605
        self.assertLength(1, topics)
606
        opt = topics[0]
607
        self.assertIsInstance(opt, config.Option)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
608
        self.assertEqual('default_format', opt.name)
6059.3.2 by Vincent Ladeuil
Cough, with tests.
609
610
4119.3.15 by Robert Collins
And fix tests for bzr help.
611
class TestCommandIndex(TestHelp):
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
612
    """Tests for the HelpCommandIndex class."""
2432.1.2 by Robert Collins
Add a HelpCommandContext class for help from commands.
613
2432.1.3 by Robert Collins
Create a HelpContexts object to do help lookups.
614
    def test_default_constructable(self):
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
615
        index = commands.HelpCommandIndex()
2432.1.3 by Robert Collins
Create a HelpContexts object to do help lookups.
616
2432.1.13 by Robert Collins
HelpCommandContext now implementes get_topics.
617
    def test_get_topics_None(self):
618
        """Searching for None returns an empty list."""
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
619
        index = commands.HelpCommandIndex()
620
        self.assertEqual([], index.get_topics(None))
2432.1.13 by Robert Collins
HelpCommandContext now implementes get_topics.
621
622
    def test_get_topics_rocks(self):
623
        """Searching for 'rocks' returns the cmd_rocks command instance."""
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
624
        index = commands.HelpCommandIndex()
625
        topics = index.get_topics('rocks')
2432.1.13 by Robert Collins
HelpCommandContext now implementes get_topics.
626
        self.assertEqual(1, len(topics))
627
        self.assertIsInstance(topics[0], builtins.cmd_rocks)
628
629
    def test_get_topics_no_topic(self):
630
        """Searching for something that is not a command returns []."""
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
631
        index = commands.HelpCommandIndex()
632
        self.assertEqual([], index.get_topics('nothing by this name'))
633
2432.1.17 by Robert Collins
Add prefixes to HelpIndexes.
634
    def test_prefix(self):
635
        """CommandIndex has a prefix of 'commands/'."""
636
        index = commands.HelpCommandIndex()
637
        self.assertEqual('commands/', index.prefix)
638
2432.1.18 by Robert Collins
Add support for doing bzr help commands/COMMANDNAME.
639
    def test_get_topic_with_prefix(self):
640
        """Searching for commands/rocks returns the rocks command object."""
641
        index = commands.HelpCommandIndex()
642
        topics = index.get_topics('commands/rocks')
643
        self.assertEqual(1, len(topics))
644
        self.assertIsInstance(topics[0], builtins.cmd_rocks)
645
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
646
2432.1.16 by Robert Collins
Correct spelling of Indexs to Indices.
647
class TestHelpIndices(tests.TestCase):
648
    """Tests for the HelpIndices class."""
2432.1.3 by Robert Collins
Create a HelpContexts object to do help lookups.
649
650
    def test_default_search_path(self):
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
651
        """The default search path should include internal indexs."""
2432.1.16 by Robert Collins
Correct spelling of Indexs to Indices.
652
        indices = help.HelpIndices()
6059.3.1 by Vincent Ladeuil
Provide per-config option help
653
        self.assertEqual(4, len(indices.search_path))
2432.1.3 by Robert Collins
Create a HelpContexts object to do help lookups.
654
        # help topics should be searched in first.
2432.1.16 by Robert Collins
Correct spelling of Indexs to Indices.
655
        self.assertIsInstance(indices.search_path[0],
6059.3.1 by Vincent Ladeuil
Provide per-config option help
656
                              help_topics.HelpTopicIndex)
2432.1.3 by Robert Collins
Create a HelpContexts object to do help lookups.
657
        # with commands being search second.
2432.1.16 by Robert Collins
Correct spelling of Indexs to Indices.
658
        self.assertIsInstance(indices.search_path[1],
6059.3.1 by Vincent Ladeuil
Provide per-config option help
659
                              commands.HelpCommandIndex)
660
        # plugins are a third index.
2432.1.24 by Robert Collins
Add plugins as a help index.
661
        self.assertIsInstance(indices.search_path[2],
6059.3.1 by Vincent Ladeuil
Provide per-config option help
662
                              plugin.PluginsHelpIndex)
663
        # config options are a fourth index
664
        self.assertIsInstance(indices.search_path[3],
665
                              help_topics.ConfigOptionHelpIndex)
2432.1.5 by Robert Collins
Initial stub for topic searching.
666
667
    def test_search_for_unknown_topic_raises(self):
668
        """Searching for an unknown topic should raise NoHelpTopic."""
2432.1.16 by Robert Collins
Correct spelling of Indexs to Indices.
669
        indices = help.HelpIndices()
670
        indices.search_path = []
6731.1.2 by Jelmer Vernooij
Move NoHelpTopic error to breesy.help.
671
        error = self.assertRaises(help.NoHelpTopic, indices.search, 'foo')
2432.1.5 by Robert Collins
Initial stub for topic searching.
672
        self.assertEqual('foo', error.topic)
2432.1.6 by Robert Collins
HelpContexts.search now invokes get_topics on each context.
673
674
    def test_search_calls_get_topic(self):
675
        """Searching should call get_topics in all indexes in order."""
676
        calls = []
7143.15.2 by Jelmer Vernooij
Run autopep8.
677
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
678
        class RecordingIndex(object):
2432.1.6 by Robert Collins
HelpContexts.search now invokes get_topics on each context.
679
            def __init__(self, name):
2432.1.19 by Robert Collins
Ensure each HelpIndex has a unique prefix.
680
                self.prefix = name
7143.15.2 by Jelmer Vernooij
Run autopep8.
681
2432.1.6 by Robert Collins
HelpContexts.search now invokes get_topics on each context.
682
            def get_topics(self, topic):
2432.1.19 by Robert Collins
Ensure each HelpIndex has a unique prefix.
683
                calls.append(('get_topics', self.prefix, topic))
2432.1.6 by Robert Collins
HelpContexts.search now invokes get_topics on each context.
684
                return ['something']
2432.1.16 by Robert Collins
Correct spelling of Indexs to Indices.
685
        index = help.HelpIndices()
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
686
        index.search_path = [RecordingIndex('1'), RecordingIndex('2')]
2432.1.6 by Robert Collins
HelpContexts.search now invokes get_topics on each context.
687
        # try with None
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
688
        index.search(None)
2432.1.6 by Robert Collins
HelpContexts.search now invokes get_topics on each context.
689
        self.assertEqual([
690
            ('get_topics', '1', None),
691
            ('get_topics', '2', None),
692
            ],
693
            calls)
694
        # and with a string
695
        del calls[:]
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
696
        index.search('bar')
2432.1.6 by Robert Collins
HelpContexts.search now invokes get_topics on each context.
697
        self.assertEqual([
698
            ('get_topics', '1', 'bar'),
699
            ('get_topics', '2', 'bar'),
700
            ],
701
            calls)
2432.1.7 by Robert Collins
HelpContexts.search now returns the found topics.
702
2432.1.20 by Robert Collins
Modify the result of HelpIndices.search to include the index each result was found in.
703
    def test_search_returns_index_and_results(self):
704
        """Searching should return help topics with their index"""
2432.1.15 by Robert Collins
Rename Context (in bzrlib.help) to Index, for a clearer name.
705
        class CannedIndex(object):
2432.1.19 by Robert Collins
Ensure each HelpIndex has a unique prefix.
706
            def __init__(self, prefix, search_result):
707
                self.prefix = prefix
2432.1.7 by Robert Collins
HelpContexts.search now returns the found topics.
708
                self.result = search_result
7143.15.2 by Jelmer Vernooij
Run autopep8.
709
2432.1.7 by Robert Collins
HelpContexts.search now returns the found topics.
710
            def get_topics(self, topic):
711
                return self.result
2432.1.16 by Robert Collins
Correct spelling of Indexs to Indices.
712
        index = help.HelpIndices()
2432.1.20 by Robert Collins
Modify the result of HelpIndices.search to include the index each result was found in.
713
        index_one = CannedIndex('1', ['a'])
714
        index_two = CannedIndex('2', ['b', 'c'])
715
        index.search_path = [index_one, index_two]
716
        self.assertEqual([(index_one, 'a'), (index_two, 'b'), (index_two, 'c')],
7143.15.2 by Jelmer Vernooij
Run autopep8.
717
                         index.search(None))
2432.1.19 by Robert Collins
Ensure each HelpIndex has a unique prefix.
718
719
    def test_search_checks_for_duplicate_prefixes(self):
720
        """Its an error when there are multiple indices with the same prefix."""
721
        indices = help.HelpIndices()
722
        indices.search_path = [help_topics.HelpTopicIndex(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
723
                               help_topics.HelpTopicIndex()]
2432.1.19 by Robert Collins
Ensure each HelpIndex has a unique prefix.
724
        self.assertRaises(errors.DuplicateHelpPrefix, indices.search, None)