/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) 2006, 2007, 2009-2012, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
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
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
16
17
6622.1.29 by Jelmer Vernooij
Fix some more tests.
18
"""Black-box tests for brz help.
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
19
"""
20
21
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
22
from breezy import (
6437.49.1 by Martin Packman
Add blackbox tests for display of translated help
23
    config,
24
    i18n,
25
    tests,
26
    )
27
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
28
from breezy.tests.test_i18n import ZzzTranslations
6437.49.1 by Martin Packman
Add blackbox tests for display of translated help
29
30
31
class TestHelp(tests.TestCaseWithTransport):
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
32
33
    def test_help_basic(self):
1616.1.15 by Martin Pool
Handle 'bzr ?', etc.
34
        for cmd in ['--help', 'help', '-h', '-?']:
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
35
            output = self.run_bzr(cmd)[0]
1616.1.15 by Martin Pool
Handle 'bzr ?', etc.
36
            line1 = output.split('\n')[0]
6622.1.33 by Jelmer Vernooij
Fix more tests (all?)
37
            if not line1.startswith('Breezy'):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
38
                self.fail("bad output from brz %s:\n%r" % (cmd, output))
1616.1.13 by Martin Pool
Fix 'bzr -h' to show help (#35940)
39
        # see https://launchpad.net/products/bzr/+bug/35940, -h doesn't work
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
40
2023.1.1 by ghigo
add topics help
41
    def test_help_topics(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
42
        """Smoketest for 'brz help topics'"""
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
43
        out, err = self.run_bzr('help topics')
2023.1.1 by ghigo
add topics help
44
        self.assertContainsRe(out, 'basic')
45
        self.assertContainsRe(out, 'topics')
2070.4.7 by ghigo
Updates on the basis of the Richard Wilbur suggestions
46
        self.assertContainsRe(out, 'commands')
47
        self.assertContainsRe(out, 'revisionspec')
2023.1.1 by ghigo
add topics help
48
49
    def test_help_revisionspec(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
50
        """Smoke test for 'brz help revisionspec'"""
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
51
        out, err = self.run_bzr('help revisionspec')
2023.1.1 by ghigo
add topics help
52
        self.assertContainsRe(out, 'revno:')
53
        self.assertContainsRe(out, 'date:')
2070.4.7 by ghigo
Updates on the basis of the Richard Wilbur suggestions
54
        self.assertContainsRe(out, 'revid:')
55
        self.assertContainsRe(out, 'last:')
56
        self.assertContainsRe(out, 'before:')
57
        self.assertContainsRe(out, 'ancestor:')
58
        self.assertContainsRe(out, 'branch:')
2023.1.1 by ghigo
add topics help
59
2245.7.1 by James Westby
Add a help topic describing checkouts and how they work.
60
    def test_help_checkouts(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
61
        """Smoke test for 'brz help checkouts'"""
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
62
        out, err = self.run_bzr('help checkouts')
2245.7.1 by James Westby
Add a help topic describing checkouts and how they work.
63
        self.assertContainsRe(out, 'checkout')
64
        self.assertContainsRe(out, 'lightweight')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
65
2241.2.11 by ghigo
On the basis of Robert Collins and John Arbash Meinel
66
    def test_help_urlspec(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
67
        """Smoke test for 'brz help urlspec'"""
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
68
        out, err = self.run_bzr('help urlspec')
6622.1.30 by Jelmer Vernooij
Some more test fixes.
69
        self.assertContainsRe(out, 'bzr://')
6963.1.1 by Jelmer Vernooij
Fix a bunch of tests on python3.
70
        self.assertContainsRe(out, 'bzr\\+ssh://')
2241.2.11 by ghigo
On the basis of Robert Collins and John Arbash Meinel
71
        self.assertContainsRe(out, 'file://')
72
        self.assertContainsRe(out, 'http://')
73
        self.assertContainsRe(out, 'https://')
74
        self.assertContainsRe(out, 'sftp://')
75
2401.2.1 by James Westby
Add a help topic for repositories.
76
    def test_help_repositories(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
77
        """Smoke test for 'brz help repositories'"""
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
78
        out, err = self.run_bzr('help repositories')
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
79
        from breezy.help_topics import help_as_plain_text, _repositories
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
80
        expected = help_as_plain_text(_repositories)
7045.1.1 by Jelmer Vernooij
Fix another 300 tests.
81
        self.assertEqual(expected, out)
2401.2.1 by James Westby
Add a help topic for repositories.
82
2401.2.2 by James Westby
Add a working-trees help topic.
83
    def test_help_working_trees(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
84
        """Smoke test for 'brz help working-trees'"""
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
85
        out, err = self.run_bzr('help working-trees')
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
86
        from breezy.help_topics import help_as_plain_text, _working_trees
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
87
        expected = help_as_plain_text(_working_trees)
88
        self.assertEqual(expected, out)
2401.2.2 by James Westby
Add a working-trees help topic.
89
2520.1.2 by Daniel Watkins
Added test for 'help status-flags'.
90
    def test_help_status_flags(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
91
        """Smoke test for 'brz help status-flags'"""
2571.1.2 by Ian Clatworthy
Fix PQM failure - use new test API
92
        out, err = self.run_bzr('help status-flags')
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
93
        from breezy.help_topics import help_as_plain_text, _status_flags
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
94
        expected = help_as_plain_text(_status_flags)
95
        self.assertEqual(expected, out)
2520.1.2 by Daniel Watkins
Added test for 'help status-flags'.
96
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
97
    def test_help_commands(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
98
        dash_help = self.run_bzr('--help commands')[0]
99
        commands = self.run_bzr('help commands')[0]
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
100
        hidden = self.run_bzr('help hidden-commands')[0]
7143.15.2 by Jelmer Vernooij
Run autopep8.
101
        long_help = self.run_bzr('help --long')[0]
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
102
        qmark_long = self.run_bzr('? --long')[0]
103
        qmark_cmds = self.run_bzr('? commands')[0]
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
104
        self.assertEqual(dash_help, commands)
105
        self.assertEqual(dash_help, long_help)
106
        self.assertEqual(dash_help, qmark_long)
107
        self.assertEqual(dash_help, qmark_cmds)
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
108
5582.7.1 by Neil Martinsen-Burrell
allow BZR_COLUMNS to be 0
109
    def test_help_width_zero(self):
6622.1.28 by Jelmer Vernooij
More renames; commands in output, environment variables.
110
        self.overrideEnv('BRZ_COLUMNS', '0')
5582.7.1 by Neil Martinsen-Burrell
allow BZR_COLUMNS to be 0
111
        self.run_bzr('help commands')
112
1551.9.13 by Aaron Bentley
add "hidden" topic
113
    def test_hidden(self):
4960.1.1 by Vincent Ladeuil
Fix brittle test.
114
        help_commands = self.run_bzr('help commands')[0]
115
        help_hidden = self.run_bzr('help hidden-commands')[0]
116
117
        def extract_cmd_names(help_output):
118
            # keep only the command names to avoid matching on help text (there
119
            # is a high risk to fail a test when a plugin get installed
120
            # otherwise)
121
            cmds = []
122
            for line in help_output.split('\n'):
123
                if line.startswith(' '):
7143.15.2 by Jelmer Vernooij
Run autopep8.
124
                    continue  # help on more than one line
4960.1.1 by Vincent Ladeuil
Fix brittle test.
125
                cmd = line.split(' ')[0]
126
                if line:
127
                    cmds.append(cmd)
128
            return cmds
129
        commands = extract_cmd_names(help_commands)
130
        hidden = extract_cmd_names(help_hidden)
1551.9.13 by Aaron Bentley
add "hidden" topic
131
        self.assertTrue('commit' in commands)
132
        self.assertTrue('commit' not in hidden)
133
        self.assertTrue('rocks' in hidden)
134
        self.assertTrue('rocks' not in commands)
135
3984.4.6 by Ian Clatworthy
Show usage on --usage, not -h
136
    def test_help_detail(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
137
        dash_h = self.run_bzr('diff -h')[0]
138
        help_x = self.run_bzr('help diff')[0]
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
139
        self.assertEqual(dash_h, help_x)
3984.4.5 by Ian Clatworthy
help xxx is full help; xxx -h is concise help
140
        self.assertContainsRe(help_x, "Purpose:")
141
        self.assertContainsRe(help_x, "Usage:")
142
        self.assertContainsRe(help_x, "Options:")
143
        self.assertContainsRe(help_x, "Description:")
144
        self.assertContainsRe(help_x, "Examples:")
145
        self.assertContainsRe(help_x, "See also:")
146
        self.assertContainsRe(help_x, "Aliases:")
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
147
3984.4.6 by Ian Clatworthy
Show usage on --usage, not -h
148
    def test_help_usage(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
149
        usage = self.run_bzr('diff --usage')[0]
3984.4.6 by Ian Clatworthy
Show usage on --usage, not -h
150
        self.assertContainsRe(usage, "Purpose:")
151
        self.assertContainsRe(usage, "Usage:")
152
        self.assertContainsRe(usage, "Options:")
153
        self.assertNotContainsRe(usage, "Description:")
154
        self.assertNotContainsRe(usage, "Examples:")
155
        self.assertContainsRe(usage, "See also:")
156
        self.assertContainsRe(usage, "Aliases:")
157
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
158
    def test_help_help(self):
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
159
        help = self.run_bzr('help help')[0]
160
        qmark = self.run_bzr('? ?')[0]
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
161
        self.assertEqual(help, qmark)
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
162
        for line in help.split('\n'):
163
            if '--long' in line:
2598.1.4 by Martin Pool
Fix up tests for option help cleanups
164
                self.assertContainsRe(line,
7143.15.2 by Jelmer Vernooij
Run autopep8.
165
                                      r'Show help on all commands\.')
2743.2.4 by Daniel Watkins
Added blackbox tests to ensure aliases are displayed in help correctly.
166
167
    def test_help_with_aliases(self):
168
        original = self.run_bzr('help cat')[0]
169
5345.1.26 by Vincent Ladeuil
Merge lockable-config-files into remove-gratuitous-ensure-config-dir-exist-calls resolving conflicts
170
        conf = config.GlobalConfig.from_string('''[ALIASES]
5345.1.14 by Vincent Ladeuil
Cleanup bb.test_help.
171
c=cat
172
cat=cat
5345.1.25 by Vincent Ladeuil
Move the '_save' parameter from '__init__' to 'from_bytes', fix fallouts.
173
''', save=True)
2743.2.4 by Daniel Watkins
Added blackbox tests to ensure aliases are displayed in help correctly.
174
6622.1.29 by Jelmer Vernooij
Fix some more tests.
175
        expected = original + "'brz cat' is an alias for 'brz cat'.\n"
2743.2.4 by Daniel Watkins
Added blackbox tests to ensure aliases are displayed in help correctly.
176
        self.assertEqual(expected, self.run_bzr('help cat')[0])
177
6622.1.29 by Jelmer Vernooij
Fix some more tests.
178
        self.assertEqual("'brz c' is an alias for 'brz cat'.\n",
2743.2.6 by Daniel Watkins
Cleaned up indentation in test.
179
                         self.run_bzr('help c')[0])
6437.49.1 by Martin Packman
Add blackbox tests for display of translated help
180
181
182
class TestTranslatedHelp(tests.TestCaseWithTransport):
183
    """Tests for display of translated help topics"""
184
185
    def setUp(self):
186
        super(TestTranslatedHelp, self).setUp()
187
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
188
189
    def test_help_command_utf8(self):
7065.3.6 by Jelmer Vernooij
Fix some more tests.
190
        out, err = self.run_bzr_raw(["help", "push"], encoding="utf-8")
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
191
        self.assertContainsRe(out, b"zz\xc3\xa5{{:See also:")
6437.49.1 by Martin Packman
Add blackbox tests for display of translated help
192
193
    def test_help_switch_utf8(self):
7065.3.6 by Jelmer Vernooij
Fix some more tests.
194
        out, err = self.run_bzr_raw(["push", "--help"], encoding="utf-8")
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
195
        self.assertContainsRe(out, b"zz\xc3\xa5{{:See also:")
6437.49.1 by Martin Packman
Add blackbox tests for display of translated help
196
197
    def test_help_command_ascii(self):
7065.3.6 by Jelmer Vernooij
Fix some more tests.
198
        out, err = self.run_bzr_raw(["help", "push"], encoding="ascii")
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
199
        self.assertContainsRe(out, b"zz\\?{{:See also:")
6437.49.1 by Martin Packman
Add blackbox tests for display of translated help
200
201
    def test_help_switch_ascii(self):
7065.3.6 by Jelmer Vernooij
Fix some more tests.
202
        out, err = self.run_bzr_raw(["push", "--help"], encoding="ascii")
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
203
        self.assertContainsRe(out, b"zz\\?{{:See also:")