~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_help.py

  • Committer: Vincent Ladeuil
  • Date: 2008-01-03 08:49:38 UTC
  • mfrom: (3111.1.31 175524)
  • mto: This revision was merged to the branch mainline in revision 3158.
  • Revision ID: v.ladeuil+lp@free.fr-20080103084938-7kvurk5uvde2ui54
Fix bug #175524, http test servers are 1.1 compliant

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
        helptext = cmd.get_help_text()
41
41
        self.assertEndsWith(
42
42
            helptext,
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'
44
46
            '\n'
45
47
            'See also: bar, foo\n')
46
48
 
50
52
            """A sample command."""
51
53
        cmd = cmd_Demo()
52
54
        helptext = cmd.get_help_text()
53
 
        self.assertStartsWith(helptext, 'usage: bzr Demo')
54
 
        self.assertEndsWith(helptext, 'show help message\n')
 
55
        self.assertStartsWith(helptext,
 
56
            'Purpose: A sample command.\n'
 
57
            'Usage:   bzr Demo')
 
58
        self.assertEndsWith(helptext,
 
59
            '  -h, --help     Show help message.\n\n')
55
60
 
56
61
    def test_command_with_additional_see_also(self):
57
62
        class cmd_WithSeeAlso(commands.Command):
61
66
        helptext = cmd.get_help_text(['gam'])
62
67
        self.assertEndsWith(
63
68
            helptext,
64
 
            '  -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'
65
72
            '\n'
66
73
            'See also: bar, foo, gam\n')
67
74
 
72
79
        helptext = cmd.get_help_text(['gam'])
73
80
        self.assertEndsWith(
74
81
            helptext,
75
 
            '  -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'
76
85
            '\n'
77
86
            'See also: gam\n')
78
87
 
82
91
            """A sample command."""
83
92
        cmd = cmd_foo_bar()
84
93
        self.assertEqual(cmd.name(), cmd.get_help_topic())
85
 
    
 
94
 
 
95
    def test_formatted_help_text(self):
 
96
        """Help text should be plain text by default."""
 
97
        class cmd_Demo(commands.Command):
 
98
            """A sample command.
 
99
 
 
100
            :Examples:
 
101
                Example 1::
 
102
 
 
103
                    cmd arg1
 
104
 
 
105
                Example 2::
 
106
 
 
107
                    cmd arg2
 
108
            """
 
109
        cmd = cmd_Demo()
 
110
        helptext = cmd.get_help_text()
 
111
        self.assertEquals(
 
112
            helptext,
 
113
            'Purpose: A sample command.\n'
 
114
            'Usage:   bzr Demo\n'
 
115
            '\n'
 
116
            'Options:\n'
 
117
            '  -v, --verbose  Display more information.\n'
 
118
            '  -q, --quiet    Only display errors and warnings.\n'
 
119
            '  -h, --help     Show help message.\n'
 
120
            '\n'
 
121
            'Examples:\n'
 
122
            '    Example 1:\n'
 
123
            '\n'
 
124
            '        cmd arg1\n'
 
125
            '\n'
 
126
            '    Example 2:\n'
 
127
            '\n'
 
128
            '        cmd arg2\n'
 
129
            '\n')
 
130
        helptext = cmd.get_help_text(plain=False)
 
131
        self.assertEquals(helptext,
 
132
            ':Purpose: A sample command.\n'
 
133
            ':Usage:   bzr Demo\n'
 
134
            '\n'
 
135
            ':Options:\n'
 
136
            '  -v, --verbose  Display more information.\n'
 
137
            '  -q, --quiet    Only display errors and warnings.\n'
 
138
            '  -h, --help     Show help message.\n'
 
139
            '\n'
 
140
            ':Examples:\n'
 
141
            '    Example 1::\n'
 
142
            '\n'
 
143
            '        cmd arg1\n'
 
144
            '\n'
 
145
            '    Example 2::\n'
 
146
            '\n'
 
147
            '        cmd arg2\n'
 
148
            '\n')
 
149
 
 
150
    def test_help_text_custom_usage(self):
 
151
        """Help text may contain a custom usage section."""
 
152
        class cmd_Demo(commands.Command):
 
153
            """A sample command.
 
154
 
 
155
            :Usage:
 
156
                cmd Demo [opts] args
 
157
 
 
158
                cmd Demo -h
 
159
 
 
160
            Blah blah blah.
 
161
            """
 
162
        cmd = cmd_Demo()
 
163
        helptext = cmd.get_help_text()
 
164
        self.assertEquals(helptext,
 
165
            'Purpose: A sample command.\n'
 
166
            'Usage:\n'
 
167
            '    cmd Demo [opts] args\n'
 
168
            '\n'
 
169
            '    cmd Demo -h\n'
 
170
            '\n'
 
171
            '\n'
 
172
            '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\n')
 
179
 
86
180
 
87
181
class TestRegisteredTopic(tests.TestCase):
88
182
    """Tests for the RegisteredTopic class."""
107
201
            '\n'
108
202
            'See also: bar, foo\n')
109
203
 
 
204
    def test_get_help_text_loaded_from_file(self):
 
205
        # Pick a known topic stored in an external file
 
206
        topic = help_topics.RegisteredTopic('hooks')
 
207
        self.assertStartsWith(topic.get_help_text(),
 
208
            'Hooks\n'
 
209
            '=====\n'
 
210
            '\n')
 
211
 
110
212
    def test_get_help_topic(self):
111
213
        """The help topic for a RegisteredTopic is its topic from construction."""
112
214
        topic = help_topics.RegisteredTopic('foobar')