~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_help.py

  • Committer: Vincent Ladeuil
  • Date: 2017-01-30 14:30:10 UTC
  • mfrom: (6615.3.7 merges)
  • mto: This revision was merged to the branch mainline in revision 6621.
  • Revision ID: v.ladeuil+lp@free.fr-20170130143010-p31t1ranfeqbaeki
Merge  2.7 into trunk including fix for bug #1657238

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009-2012, 2016 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
19
19
"""
20
20
 
21
21
 
22
 
import bzrlib
23
 
from bzrlib.tests.blackbox import ExternalBase
24
 
from bzrlib.config import (ensure_config_dir_exists, config_filename)
25
 
 
26
 
 
27
 
class TestHelp(ExternalBase):
 
22
from bzrlib import (
 
23
    config,
 
24
    i18n,
 
25
    tests,
 
26
    )
 
27
 
 
28
from bzrlib.tests.test_i18n import ZzzTranslations
 
29
 
 
30
 
 
31
class TestHelp(tests.TestCaseWithTransport):
28
32
 
29
33
    def test_help_basic(self):
30
34
        for cmd in ['--help', 'help', '-h', '-?']:
99
103
        long_help  = self.run_bzr('help --long')[0]
100
104
        qmark_long = self.run_bzr('? --long')[0]
101
105
        qmark_cmds = self.run_bzr('? commands')[0]
102
 
        self.assertEquals(dash_help, commands)
103
 
        self.assertEquals(dash_help, long_help)
104
 
        self.assertEquals(dash_help, qmark_long)
105
 
        self.assertEquals(dash_help, qmark_cmds)
 
106
        self.assertEqual(dash_help, commands)
 
107
        self.assertEqual(dash_help, long_help)
 
108
        self.assertEqual(dash_help, qmark_long)
 
109
        self.assertEqual(dash_help, qmark_cmds)
 
110
 
 
111
    def test_help_width_zero(self):
 
112
        self.overrideEnv('BZR_COLUMNS', '0')
 
113
        self.run_bzr('help commands')
106
114
 
107
115
    def test_hidden(self):
108
 
        commands = self.run_bzr('help commands')[0]
109
 
        hidden = self.run_bzr('help hidden-commands')[0]
 
116
        help_commands = self.run_bzr('help commands')[0]
 
117
        help_hidden = self.run_bzr('help hidden-commands')[0]
 
118
 
 
119
        def extract_cmd_names(help_output):
 
120
            # keep only the command names to avoid matching on help text (there
 
121
            # is a high risk to fail a test when a plugin get installed
 
122
            # otherwise)
 
123
            cmds = []
 
124
            for line in help_output.split('\n'):
 
125
                if line.startswith(' '):
 
126
                    continue # help on more than one line
 
127
                cmd = line.split(' ')[0]
 
128
                if line:
 
129
                    cmds.append(cmd)
 
130
            return cmds
 
131
        commands = extract_cmd_names(help_commands)
 
132
        hidden = extract_cmd_names(help_hidden)
110
133
        self.assertTrue('commit' in commands)
111
134
        self.assertTrue('commit' not in hidden)
112
135
        self.assertTrue('rocks' in hidden)
115
138
    def test_help_detail(self):
116
139
        dash_h  = self.run_bzr('diff -h')[0]
117
140
        help_x  = self.run_bzr('help diff')[0]
118
 
        self.assertEquals(dash_h, help_x)
 
141
        self.assertEqual(dash_h, help_x)
119
142
        self.assertContainsRe(help_x, "Purpose:")
120
143
        self.assertContainsRe(help_x, "Usage:")
121
144
        self.assertContainsRe(help_x, "Options:")
137
160
    def test_help_help(self):
138
161
        help = self.run_bzr('help help')[0]
139
162
        qmark = self.run_bzr('? ?')[0]
140
 
        self.assertEquals(help, qmark)
 
163
        self.assertEqual(help, qmark)
141
164
        for line in help.split('\n'):
142
165
            if '--long' in line:
143
166
                self.assertContainsRe(line,
146
169
    def test_help_with_aliases(self):
147
170
        original = self.run_bzr('help cat')[0]
148
171
 
149
 
        ensure_config_dir_exists()
150
 
        CONFIG=("[ALIASES]\n"
151
 
        "c=cat\n"
152
 
        "cat=cat\n")
153
 
 
154
 
        open(config_filename(),'wb').write(CONFIG)
 
172
        conf = config.GlobalConfig.from_string('''[ALIASES]
 
173
c=cat
 
174
cat=cat
 
175
''', save=True)
155
176
 
156
177
        expected = original + "'bzr cat' is an alias for 'bzr cat'.\n"
157
178
        self.assertEqual(expected, self.run_bzr('help cat')[0])
158
179
 
159
180
        self.assertEqual("'bzr c' is an alias for 'bzr cat'.\n",
160
181
                         self.run_bzr('help c')[0])
 
182
 
 
183
 
 
184
class TestTranslatedHelp(tests.TestCaseWithTransport):
 
185
    """Tests for display of translated help topics"""
 
186
 
 
187
    def setUp(self):
 
188
        super(TestTranslatedHelp, self).setUp()
 
189
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
 
190
 
 
191
    def test_help_command_utf8(self):
 
192
        out, err = self.run_bzr(["help", "push"], encoding="utf-8")
 
193
        self.assertContainsRe(out, "zz\xc3\xa5{{:See also:")
 
194
 
 
195
    def test_help_switch_utf8(self):
 
196
        out, err = self.run_bzr(["push", "--help"], encoding="utf-8")
 
197
        self.assertContainsRe(out, "zz\xc3\xa5{{:See also:")
 
198
 
 
199
    def test_help_command_ascii(self):
 
200
        out, err = self.run_bzr(["help", "push"], encoding="ascii")
 
201
        self.assertContainsRe(out, "zz\\?{{:See also:")
 
202
 
 
203
    def test_help_switch_ascii(self):
 
204
        out, err = self.run_bzr(["push", "--help"], encoding="ascii")
 
205
        self.assertContainsRe(out, "zz\\?{{:See also:")