~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_help.py

  • Committer: Aaron Bentley
  • Date: 2007-08-16 00:54:00 UTC
  • mto: This revision was merged to the branch mainline in revision 2711.
  • Revision ID: aaron.bentley@utoronto.ca-20070816005400-oxxtqiy310wx10h9
Fix typo

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
 
40
40
        helptext = cmd.get_help_text()
41
41
        self.assertEndsWith(
42
42
            helptext,
43
 
            '  -v, --verbose  Display more information.\n'
44
 
            '  -q, --quiet    Only display errors and warnings.\n'
45
 
            '  -h, --help     Show help message.\n'
 
43
            '  -h, --help  Show help message.\n'
46
44
            '\n'
47
45
            'See also: bar, foo\n')
48
46
 
55
53
        self.assertStartsWith(helptext,
56
54
            'Purpose: A sample command.\n'
57
55
            'Usage:   bzr Demo')
58
 
        self.assertEndsWith(helptext,
59
 
            '  -h, --help     Show help message.\n\n')
 
56
        self.assertEndsWith(helptext, 'Show help message.\n\n')
60
57
 
61
58
    def test_command_with_additional_see_also(self):
62
59
        class cmd_WithSeeAlso(commands.Command):
66
63
        helptext = cmd.get_help_text(['gam'])
67
64
        self.assertEndsWith(
68
65
            helptext,
69
 
            '  -v, --verbose  Display more information.\n'
70
 
            '  -q, --quiet    Only display errors and warnings.\n'
71
 
            '  -h, --help     Show help message.\n'
 
66
            '  -h, --help  Show help message.\n'
72
67
            '\n'
73
68
            'See also: bar, foo, gam\n')
74
69
 
79
74
        helptext = cmd.get_help_text(['gam'])
80
75
        self.assertEndsWith(
81
76
            helptext,
82
 
            '  -v, --verbose  Display more information.\n'
83
 
            '  -q, --quiet    Only display errors and warnings.\n'
84
 
            '  -h, --help     Show help message.\n'
 
77
            '  -h, --help  Show help message.\n'
85
78
            '\n'
86
79
            'See also: gam\n')
87
80
 
96
89
        """Help text should be plain text by default."""
97
90
        class cmd_Demo(commands.Command):
98
91
            """A sample command.
99
 
 
 
92
 
100
93
            :Examples:
101
94
                Example 1::
102
 
 
 
95
 
103
96
                    cmd arg1
104
 
 
 
97
 
105
98
                Example 2::
106
 
 
 
99
 
107
100
                    cmd arg2
108
101
            """
109
102
        cmd = cmd_Demo()
114
107
            'Usage:   bzr Demo\n'
115
108
            '\n'
116
109
            'Options:\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'
 
110
            '  -h, --help  Show help message.\n'
121
111
            '\n'
122
112
            'Examples:\n'
123
113
            '    Example 1:\n'
134
124
            ':Usage:   bzr Demo\n'
135
125
            '\n'
136
126
            ':Options:\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'
 
127
            '  -h, --help  Show help message.\n'
141
128
            '\n'
142
129
            ':Examples:\n'
143
130
            '    Example 1::\n'
149
136
            '        cmd arg2\n'
150
137
            '\n')
151
138
 
152
 
    def test_concise_help_text(self):
153
 
        """Concise help text excludes the descriptive sections."""
154
 
        class cmd_Demo(commands.Command):
155
 
            """A sample command.
156
 
 
157
 
            Blah blah blah.
158
 
 
159
 
            :Examples:
160
 
                Example 1::
161
 
 
162
 
                    cmd arg1
163
 
            """
164
 
        cmd = cmd_Demo()
165
 
        helptext = cmd.get_help_text()
166
 
        self.assertEqualDiff(
167
 
            helptext,
168
 
            'Purpose: A sample command.\n'
169
 
            'Usage:   bzr Demo\n'
170
 
            '\n'
171
 
            'Options:\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'
176
 
            '\n'
177
 
            'Description:\n'
178
 
            '  Blah blah blah.\n'
179
 
            '\n'
180
 
            'Examples:\n'
181
 
            '    Example 1:\n'
182
 
            '\n'
183
 
            '        cmd arg1\n'
184
 
            '\n')
185
 
        helptext = cmd.get_help_text(verbose=False)
186
 
        self.assertEquals(helptext,
187
 
            'Purpose: A sample command.\n'
188
 
            'Usage:   bzr Demo\n'
189
 
            '\n'
190
 
            'Options:\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'
195
 
            '\n'
196
 
            'See bzr help Demo for more details and examples.\n'
197
 
            '\n')
198
 
 
199
 
    def test_help_custom_section_ordering(self):
200
 
        """Custom descriptive sections should remain in the order given."""
201
 
        class cmd_Demo(commands.Command):
202
 
            """A sample command.
203
 
 
204
 
            Blah blah blah.
205
 
 
206
 
            :Formats:
207
 
              Interesting stuff about formats.
208
 
 
209
 
            :Examples:
210
 
              Example 1::
211
 
 
212
 
                cmd arg1
213
 
 
214
 
            :Tips:
215
 
              Clever things to keep in mind.
216
 
            """
217
 
        cmd = cmd_Demo()
218
 
        helptext = cmd.get_help_text()
219
 
        self.assertEqualDiff(
220
 
            helptext,
221
 
            'Purpose: A sample command.\n'
222
 
            'Usage:   bzr Demo\n'
223
 
            '\n'
224
 
            'Options:\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'
229
 
            '\n'
230
 
            'Description:\n'
231
 
            '  Blah blah blah.\n'
232
 
            '\n'
233
 
            'Formats:\n'
234
 
            '  Interesting stuff about formats.\n'
235
 
            '\n'
236
 
            'Examples:\n'
237
 
            '  Example 1:\n'
238
 
            '\n'
239
 
            '    cmd arg1\n'
240
 
            '\n'
241
 
            'Tips:\n'
242
 
            '  Clever things to keep in mind.\n'
243
 
            '\n')
244
 
 
245
139
    def test_help_text_custom_usage(self):
246
140
        """Help text may contain a custom usage section."""
247
141
        class cmd_Demo(commands.Command):
248
142
            """A sample command.
249
 
 
 
143
 
250
144
            :Usage:
251
145
                cmd Demo [opts] args
252
 
 
 
146
 
253
147
                cmd Demo -h
254
 
 
 
148
 
255
149
            Blah blah blah.
256
150
            """
257
151
        cmd = cmd_Demo()
265
159
            '\n'
266
160
            '\n'
267
161
            'Options:\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'
 
162
            '  -h, --help  Show help message.\n'
272
163
            '\n'
273
164
            'Description:\n'
274
165
            '  Blah blah blah.\n\n')
279
170
 
280
171
    def test_contruct(self):
281
172
        """Construction takes the help topic name for the registered item."""
282
 
        # validate our test
 
173
        # validate our test 
283
174
        self.assertTrue('basic' in help_topics.topic_registry)
284
175
        topic = help_topics.RegisteredTopic('basic')
285
176
        self.assertEqual('basic', topic.topic)
297
188
            '\n'
298
189
            'See also: bar, foo\n')
299
190
 
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'
306
 
            '\n')
307
 
 
308
191
    def test_get_help_topic(self):
309
192
        """The help topic for a RegisteredTopic is its topic from construction."""
310
193
        topic = help_topics.RegisteredTopic('foobar')