/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_help.py

  • Committer: Martin Pool
  • Date: 2007-10-03 08:06:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2901.
  • Revision ID: mbp@sourcefrog.net-20071003080644-oivy0gkg98sex0ed
Avoid internal error tracebacks on failure to lock on readonly transport (#129701).

Add new LockFailed, which doesn't imply that we failed to get it because of
contention.  Raise this if we fail to create the pending or lock directories
because of Transport errors.

UnlockableTransport is not an internal error.

ReadOnlyLockError has a message which didn't match its name or usage; it's now
deprecated and callers are updated to use LockFailed which is more appropriate.

Add zero_ninetytwo deprecation symbol.

Unify assertMatchesRe with TestCase.assertContainsRe.

When the constructor is deprecated, just say that the class is deprecated, not
the __init__ method - this works better with applyDeprecated in tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
 
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()
56
49
    def test_get_help_text(self):
57
50
        """Commands have a get_help_text method which returns their help."""
58
51
        class cmd_Demo(commands.Command):
59
 
            __doc__ = """A sample command."""
 
52
            """A sample command."""
60
53
        cmd = cmd_Demo()
61
54
        helptext = cmd.get_help_text()
62
55
        self.assertStartsWith(helptext,
67
60
 
68
61
    def test_command_with_additional_see_also(self):
69
62
        class cmd_WithSeeAlso(commands.Command):
70
 
            __doc__ = """A sample command."""
 
63
            """A sample command."""
71
64
            _see_also = ['foo', 'bar']
72
65
        cmd = cmd_WithSeeAlso()
73
66
        helptext = cmd.get_help_text(['gam'])
81
74
 
82
75
    def test_command_only_additional_see_also(self):
83
76
        class cmd_WithSeeAlso(commands.Command):
84
 
            __doc__ = """A sample command."""
 
77
            """A sample command."""
85
78
        cmd = cmd_WithSeeAlso()
86
79
        helptext = cmd.get_help_text(['gam'])
87
80
        self.assertEndsWith(
95
88
    def test_get_help_topic(self):
96
89
        """The help topic for a Command is its name()."""
97
90
        class cmd_foo_bar(commands.Command):
98
 
            __doc__ = """A sample command."""
 
91
            """A sample command."""
99
92
        cmd = cmd_foo_bar()
100
93
        self.assertEqual(cmd.name(), cmd.get_help_topic())
101
94
 
102
95
    def test_formatted_help_text(self):
103
96
        """Help text should be plain text by default."""
104
97
        class cmd_Demo(commands.Command):
105
 
            __doc__ = """A sample command.
106
 
 
 
98
            """A sample command.
 
99
 
107
100
            :Examples:
108
101
                Example 1::
109
 
 
 
102
 
110
103
                    cmd arg1
111
 
 
 
104
 
112
105
                Example 2::
113
 
 
 
106
 
114
107
                    cmd arg2
115
108
            """
116
109
        cmd = cmd_Demo()
121
114
            'Usage:   bzr Demo\n'
122
115
            '\n'
123
116
            'Options:\n'
124
 
            '  --usage        Show usage message and options.\n'
125
117
            '  -v, --verbose  Display more information.\n'
126
118
            '  -q, --quiet    Only display errors and warnings.\n'
127
119
            '  -h, --help     Show help message.\n'
141
133
            ':Usage:   bzr Demo\n'
142
134
            '\n'
143
135
            ':Options:\n'
144
 
            '  --usage        Show usage message and options.\n'
145
136
            '  -v, --verbose  Display more information.\n'
146
137
            '  -q, --quiet    Only display errors and warnings.\n'
147
138
            '  -h, --help     Show help message.\n'
156
147
            '        cmd arg2\n'
157
148
            '\n')
158
149
 
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.
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
 
            __doc__ = """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
150
    def test_help_text_custom_usage(self):
253
151
        """Help text may contain a custom usage section."""
254
152
        class cmd_Demo(commands.Command):
255
 
            __doc__ = """A sample command.
256
 
 
 
153
            """A sample command.
 
154
 
257
155
            :Usage:
258
156
                cmd Demo [opts] args
259
 
 
 
157
 
260
158
                cmd Demo -h
261
 
 
 
159
 
262
160
            Blah blah blah.
263
161
            """
264
162
        cmd = cmd_Demo()
272
170
            '\n'
273
171
            '\n'
274
172
            'Options:\n'
275
 
            '  --usage        Show usage message and options.\n'
276
173
            '  -v, --verbose  Display more information.\n'
277
174
            '  -q, --quiet    Only display errors and warnings.\n'
278
175
            '  -h, --help     Show help message.\n'
281
178
            '  Blah blah blah.\n\n')
282
179
 
283
180
 
284
 
class TestRegisteredTopic(TestHelp):
 
181
class TestRegisteredTopic(tests.TestCase):
285
182
    """Tests for the RegisteredTopic class."""
286
183
 
287
184
    def test_contruct(self):
288
185
        """Construction takes the help topic name for the registered item."""
289
 
        # validate our test
 
186
        # validate our test 
290
187
        self.assertTrue('basic' in help_topics.topic_registry)
291
188
        topic = help_topics.RegisteredTopic('basic')
292
189
        self.assertEqual('basic', topic.topic)
304
201
            '\n'
305
202
            'See also: bar, foo\n')
306
203
 
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
204
    def test_get_help_topic(self):
316
205
        """The help topic for a RegisteredTopic is its topic from construction."""
317
206
        topic = help_topics.RegisteredTopic('foobar')
320
209
        self.assertEqual('baz', topic.get_help_topic())
321
210
 
322
211
 
323
 
class TestTopicIndex(TestHelp):
 
212
class TestTopicIndex(tests.TestCase):
324
213
    """Tests for the HelpTopicIndex class."""
325
214
 
326
215
    def test_default_constructable(self):
353
242
        self.assertEqual('', index.prefix)
354
243
 
355
244
 
356
 
class TestCommandIndex(TestHelp):
 
245
class TestCommandIndex(tests.TestCase):
357
246
    """Tests for the HelpCommandIndex class."""
358
247
 
359
248
    def test_default_constructable(self):