bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
1  | 
# Copyright (C) 2005, 2007 Canonical Ltd
 | 
| 
1534.4.25
by Robert Collins
 Add a --transport parameter to the test suite to set the default transport to be used in the test suite.  | 
2  | 
#
 | 
3  | 
# This program is free software; you can redistribute it and/or modify
 | 
|
| 
2052.3.1
by John Arbash Meinel
 Add tests to cleanup the copyright of all source files  | 
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.
 | 
|
| 
1534.4.25
by Robert Collins
 Add a --transport parameter to the test suite to set the default transport to be used in the test suite.  | 
7  | 
#
 | 
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.
 | 
|
12  | 
#
 | 
|
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
 | 
|
15  | 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
|
16  | 
||
17  | 
"""UI tests for the test framework."""
 | 
|
18  | 
||
| 
1963.1.1
by John Arbash Meinel
 run_bzr_subprocess() can take an env_changes parameter  | 
19  | 
import os  | 
| 
2394.2.5
by Ian Clatworthy
 list-only working, include test not  | 
20  | 
import re  | 
| 
1910.17.2
by Andrew Bennetts
 Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue  | 
21  | 
import signal  | 
| 
1692.3.3
by Robert Collins
 Get run_bzr in tests to always assign a new, clean ui factory.  | 
22  | 
import sys  | 
23  | 
||
| 
1534.4.25
by Robert Collins
 Add a --transport parameter to the test suite to set the default transport to be used in the test suite.  | 
24  | 
import bzrlib  | 
| 
1963.1.2
by John Arbash Meinel
 Cleanups suggested by Martin, add test that env_changes can remove an env variable  | 
25  | 
from bzrlib import (  | 
26  | 
osutils,  | 
|
27  | 
    )
 | 
|
| 
2394.2.3
by Ian Clatworthy
 Backed out test junk  | 
28  | 
from bzrlib.errors import ParamikoNotPresent  | 
| 
1534.4.25
by Robert Collins
 Add a --transport parameter to the test suite to set the default transport to be used in the test suite.  | 
29  | 
from bzrlib.tests import (  | 
30  | 
TestCase,  | 
|
| 
2172.4.3
by Alexander Belchenko
 Change name of option to '--clean-output' and provide tests  | 
31  | 
TestCaseInTempDir,  | 
| 
1986.2.3
by Robert Collins
 New test base class TestCaseWithMemoryTransport offers memory-only  | 
32  | 
TestCaseWithMemoryTransport,  | 
| 
1819.1.3
by Carl Friedrich Bolz
 (lifeless, cfbolz): Add recording of benchmark results to the benchmark history  | 
33  | 
TestCaseWithTransport,  | 
| 
2294.4.4
by Vincent Ladeuil
 Provide a better implementation for testing passwords.  | 
34  | 
TestUIFactory,  | 
| 
1534.4.25
by Robert Collins
 Add a --transport parameter to the test suite to set the default transport to be used in the test suite.  | 
35  | 
TestSkipped,  | 
36  | 
                          )
 | 
|
| 
1687.1.2
by Robert Collins
 Add stdin parameter to run_bzr and run_bzr_captured.  | 
37  | 
from bzrlib.tests.blackbox import ExternalBase  | 
| 
1534.4.25
by Robert Collins
 Add a --transport parameter to the test suite to set the default transport to be used in the test suite.  | 
38  | 
|
39  | 
||
40  | 
class TestOptions(TestCase):  | 
|
41  | 
||
42  | 
current_test = None  | 
|
43  | 
||
44  | 
def test_transport_set_to_sftp(self):  | 
|
45  | 
        # test the --transport option has taken effect from within the
 | 
|
46  | 
        # test_transport test
 | 
|
| 
1551.2.47
by abentley
 Fixed test_selftest's use of sftp  | 
47  | 
try:  | 
48  | 
import bzrlib.transport.sftp  | 
|
49  | 
except ParamikoNotPresent:  | 
|
50  | 
raise TestSkipped("Paramiko not present")  | 
|
| 
1534.4.25
by Robert Collins
 Add a --transport parameter to the test suite to set the default transport to be used in the test suite.  | 
51  | 
if TestOptions.current_test != "test_transport_set_to_sftp":  | 
52  | 
            return
 | 
|
53  | 
self.assertEqual(bzrlib.transport.sftp.SFTPAbsoluteServer,  | 
|
54  | 
bzrlib.tests.default_transport)  | 
|
55  | 
||
| 
1534.4.26
by Robert Collins
 Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.  | 
56  | 
def test_transport_set_to_memory(self):  | 
57  | 
        # test the --transport option has taken effect from within the
 | 
|
58  | 
        # test_transport test
 | 
|
59  | 
import bzrlib.transport.memory  | 
|
60  | 
if TestOptions.current_test != "test_transport_set_to_memory":  | 
|
61  | 
            return
 | 
|
62  | 
self.assertEqual(bzrlib.transport.memory.MemoryServer,  | 
|
63  | 
bzrlib.tests.default_transport)  | 
|
64  | 
||
| 
1534.4.25
by Robert Collins
 Add a --transport parameter to the test suite to set the default transport to be used in the test suite.  | 
65  | 
def test_transport(self):  | 
66  | 
        # test that --transport=sftp works
 | 
|
| 
1551.2.47
by abentley
 Fixed test_selftest's use of sftp  | 
67  | 
try:  | 
68  | 
import bzrlib.transport.sftp  | 
|
69  | 
except ParamikoNotPresent:  | 
|
70  | 
raise TestSkipped("Paramiko not present")  | 
|
| 
1534.4.25
by Robert Collins
 Add a --transport parameter to the test suite to set the default transport to be used in the test suite.  | 
71  | 
old_transport = bzrlib.tests.default_transport  | 
| 
1986.2.3
by Robert Collins
 New test base class TestCaseWithMemoryTransport offers memory-only  | 
72  | 
old_root = TestCaseWithMemoryTransport.TEST_ROOT  | 
73  | 
TestCaseWithMemoryTransport.TEST_ROOT = None  | 
|
| 
1534.4.25
by Robert Collins
 Add a --transport parameter to the test suite to set the default transport to be used in the test suite.  | 
74  | 
try:  | 
75  | 
TestOptions.current_test = "test_transport_set_to_sftp"  | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
76  | 
stdout = self.run_bzr(  | 
| 
2530.3.1
by Martin Pool
 Cleanup old variations on run_bzr in the test suite  | 
77  | 
'selftest --transport=sftp test_transport_set_to_sftp')[0]  | 
| 
1534.4.26
by Robert Collins
 Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.  | 
78  | 
self.assertContainsRe(stdout, 'Ran 1 test')  | 
79  | 
self.assertEqual(old_transport, bzrlib.tests.default_transport)  | 
|
80  | 
||
81  | 
TestOptions.current_test = "test_transport_set_to_memory"  | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
82  | 
stdout = self.run_bzr(  | 
| 
2530.3.1
by Martin Pool
 Cleanup old variations on run_bzr in the test suite  | 
83  | 
'selftest --transport=memory test_transport_set_to_memory')[0]  | 
| 
1534.4.25
by Robert Collins
 Add a --transport parameter to the test suite to set the default transport to be used in the test suite.  | 
84  | 
self.assertContainsRe(stdout, 'Ran 1 test')  | 
85  | 
self.assertEqual(old_transport, bzrlib.tests.default_transport)  | 
|
86  | 
finally:  | 
|
87  | 
bzrlib.tests.default_transport = old_transport  | 
|
88  | 
TestOptions.current_test = None  | 
|
| 
1986.2.3
by Robert Collins
 New test base class TestCaseWithMemoryTransport offers memory-only  | 
89  | 
TestCaseWithMemoryTransport.TEST_ROOT = old_root  | 
| 
1687.1.2
by Robert Collins
 Add stdin parameter to run_bzr and run_bzr_captured.  | 
90  | 
|
91  | 
||
92  | 
class TestRunBzr(ExternalBase):  | 
|
93  | 
||
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
94  | 
def _run_bzr_core(self, argv, retcode=0, encoding=None, stdin=None,  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
95  | 
working_dir=None):  | 
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
96  | 
"""Override _run_bzr_core to test how it is invoked by run_bzr.  | 
| 
2552.2.1
by Vincent Ladeuil
 apply martin patch  | 
97  | 
|
| 
2530.3.1
by Martin Pool
 Cleanup old variations on run_bzr in the test suite  | 
98  | 
        Attempts to run bzr from inside this class don't actually run it.
 | 
99  | 
||
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
100  | 
        We test how run_bzr actually invokes bzr in another location.
 | 
| 
2027.5.3
by John Arbash Meinel
 Add docstring to why run_bzr_captured is overridden  | 
101  | 
        Here we only need to test that it is run_bzr passes the right
 | 
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
102  | 
        parameters to run_bzr.
 | 
| 
2027.5.3
by John Arbash Meinel
 Add docstring to why run_bzr_captured is overridden  | 
103  | 
        """
 | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
104  | 
self.argv = list(argv)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
105  | 
self.retcode = retcode  | 
106  | 
self.encoding = encoding  | 
|
| 
1687.1.2
by Robert Collins
 Add stdin parameter to run_bzr and run_bzr_captured.  | 
107  | 
self.stdin = stdin  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
108  | 
self.working_dir = working_dir  | 
| 
2292.1.28
by Marius Kruger
 * NEWS  | 
109  | 
return '', ''  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
110  | 
|
111  | 
def test_encoding(self):  | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
112  | 
"""Test that run_bzr passes encoding to _run_bzr_core"""  | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
113  | 
self.run_bzr('foo bar')  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
114  | 
self.assertEqual(None, self.encoding)  | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
115  | 
self.assertEqual(['foo', 'bar'], self.argv)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
116  | 
|
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
117  | 
self.run_bzr('foo bar', encoding='baz')  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
118  | 
self.assertEqual('baz', self.encoding)  | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
119  | 
self.assertEqual(['foo', 'bar'], self.argv)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
120  | 
|
121  | 
def test_retcode(self):  | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
122  | 
"""Test that run_bzr passes retcode to _run_bzr_core"""  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
123  | 
        # Default is retcode == 0
 | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
124  | 
self.run_bzr('foo bar')  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
125  | 
self.assertEqual(0, self.retcode)  | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
126  | 
self.assertEqual(['foo', 'bar'], self.argv)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
127  | 
|
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
128  | 
self.run_bzr('foo bar', retcode=1)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
129  | 
self.assertEqual(1, self.retcode)  | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
130  | 
self.assertEqual(['foo', 'bar'], self.argv)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
131  | 
|
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
132  | 
self.run_bzr('foo bar', retcode=None)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
133  | 
self.assertEqual(None, self.retcode)  | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
134  | 
self.assertEqual(['foo', 'bar'], self.argv)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
135  | 
|
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
136  | 
self.run_bzr(['foo', 'bar'], retcode=3)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
137  | 
self.assertEqual(3, self.retcode)  | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
138  | 
self.assertEqual(['foo', 'bar'], self.argv)  | 
| 
1687.1.2
by Robert Collins
 Add stdin parameter to run_bzr and run_bzr_captured.  | 
139  | 
|
140  | 
def test_stdin(self):  | 
|
141  | 
        # test that the stdin keyword to run_bzr is passed through to
 | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
142  | 
        # _run_bzr_core as-is. We do this by overriding
 | 
143  | 
        # _run_bzr_core in this class, and then calling run_bzr,
 | 
|
144  | 
        # which is a convenience function for _run_bzr_core, so 
 | 
|
| 
1687.1.15
by Robert Collins
 Review comments.  | 
145  | 
        # should invoke it.
 | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
146  | 
self.run_bzr('foo bar', stdin='gam')  | 
| 
1687.1.2
by Robert Collins
 Add stdin parameter to run_bzr and run_bzr_captured.  | 
147  | 
self.assertEqual('gam', self.stdin)  | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
148  | 
self.assertEqual(['foo', 'bar'], self.argv)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
149  | 
|
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
150  | 
self.run_bzr('foo bar', stdin='zippy')  | 
| 
1687.1.2
by Robert Collins
 Add stdin parameter to run_bzr and run_bzr_captured.  | 
151  | 
self.assertEqual('zippy', self.stdin)  | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
152  | 
self.assertEqual(['foo', 'bar'], self.argv)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
153  | 
|
154  | 
def test_working_dir(self):  | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
155  | 
"""Test that run_bzr passes working_dir to _run_bzr_core"""  | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
156  | 
self.run_bzr('foo bar')  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
157  | 
self.assertEqual(None, self.working_dir)  | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
158  | 
self.assertEqual(['foo', 'bar'], self.argv)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
159  | 
|
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
160  | 
self.run_bzr('foo bar', working_dir='baz')  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
161  | 
self.assertEqual('baz', self.working_dir)  | 
| 
2530.3.3
by Martin Pool
 Clean up some callers that use varargs syntax for run_bzr, but don't  | 
162  | 
self.assertEqual(['foo', 'bar'], self.argv)  | 
| 
1687.1.2
by Robert Collins
 Add stdin parameter to run_bzr and run_bzr_captured.  | 
163  | 
|
| 
2665.1.1
by Michael Hudson
 make run_bzr stricter about the keyword arguments it takes.  | 
164  | 
def test_reject_extra_keyword_arguments(self):  | 
165  | 
self.assertRaises(TypeError, self.run_bzr, "foo bar",  | 
|
166  | 
error_regex=['error message'])  | 
|
167  | 
||
| 
1687.1.2
by Robert Collins
 Add stdin parameter to run_bzr and run_bzr_captured.  | 
168  | 
|
| 
1819.1.3
by Carl Friedrich Bolz
 (lifeless, cfbolz): Add recording of benchmark results to the benchmark history  | 
169  | 
class TestBenchmarkTests(TestCaseWithTransport):  | 
170  | 
||
171  | 
def test_benchmark_runs_benchmark_tests(self):  | 
|
172  | 
"""bzr selftest --benchmark should not run the default test suite."""  | 
|
173  | 
        # We test this by passing a regression test name to --benchmark, which
 | 
|
| 
3111.1.23
by Vincent Ladeuil
 Make HTTP/1.1 the default implementation reveals one more bug.  | 
174  | 
        # should result in 0 tests run.
 | 
| 
1986.2.3
by Robert Collins
 New test base class TestCaseWithMemoryTransport offers memory-only  | 
175  | 
old_root = TestCaseWithMemoryTransport.TEST_ROOT  | 
| 
1819.1.3
by Carl Friedrich Bolz
 (lifeless, cfbolz): Add recording of benchmark results to the benchmark history  | 
176  | 
try:  | 
| 
1986.2.3
by Robert Collins
 New test base class TestCaseWithMemoryTransport offers memory-only  | 
177  | 
TestCaseWithMemoryTransport.TEST_ROOT = None  | 
| 
2552.2.4
by Vincent Ladeuil
 Merge bzr.dev and resolve conflits. (good use case for an enhanced merge  | 
178  | 
out, err = self.run_bzr('selftest --benchmark'  | 
179  | 
' workingtree_implementations')  | 
|
| 
1819.1.3
by Carl Friedrich Bolz
 (lifeless, cfbolz): Add recording of benchmark results to the benchmark history  | 
180  | 
finally:  | 
| 
1986.2.3
by Robert Collins
 New test base class TestCaseWithMemoryTransport offers memory-only  | 
181  | 
TestCaseWithMemoryTransport.TEST_ROOT = old_root  | 
| 
1819.1.3
by Carl Friedrich Bolz
 (lifeless, cfbolz): Add recording of benchmark results to the benchmark history  | 
182  | 
self.assertContainsRe(out, 'Ran 0 tests.*\n\nOK')  | 
183  | 
self.assertEqual(  | 
|
| 
2095.4.1
by Martin Pool
 Better progress bars during tests  | 
184  | 
'tests passed\n',  | 
| 
1819.1.3
by Carl Friedrich Bolz
 (lifeless, cfbolz): Add recording of benchmark results to the benchmark history  | 
185  | 
err)  | 
186  | 
benchfile = open(".perf_history", "rt")  | 
|
187  | 
try:  | 
|
188  | 
lines = benchfile.readlines()  | 
|
189  | 
finally:  | 
|
190  | 
benchfile.close()  | 
|
191  | 
self.assertEqual(1, len(lines))  | 
|
192  | 
self.assertContainsRe(lines[0], "--date [0-9.]+")  | 
|
193  | 
||
194  | 
||
| 
1687.1.2
by Robert Collins
 Add stdin parameter to run_bzr and run_bzr_captured.  | 
195  | 
class TestRunBzrCaptured(ExternalBase):  | 
196  | 
||
197  | 
def apply_redirected(self, stdin=None, stdout=None, stderr=None,  | 
|
198  | 
a_callable=None, *args, **kwargs):  | 
|
199  | 
self.stdin = stdin  | 
|
| 
1687.1.11
by Robert Collins
 Teach TestCase.run_bzr_captured about the ui factories.  | 
200  | 
self.factory_stdin = getattr(bzrlib.ui.ui_factory, "stdin", None)  | 
| 
1692.3.3
by Robert Collins
 Get run_bzr in tests to always assign a new, clean ui factory.  | 
201  | 
self.factory = bzrlib.ui.ui_factory  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
202  | 
self.working_dir = osutils.getcwd()  | 
| 
1692.3.3
by Robert Collins
 Get run_bzr in tests to always assign a new, clean ui factory.  | 
203  | 
stdout.write('foo\n')  | 
204  | 
stderr.write('bar\n')  | 
|
| 
1687.1.2
by Robert Collins
 Add stdin parameter to run_bzr and run_bzr_captured.  | 
205  | 
return 0  | 
206  | 
||
207  | 
def test_stdin(self):  | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
208  | 
        # test that the stdin keyword to _run_bzr_core is passed through to
 | 
| 
1687.1.15
by Robert Collins
 Review comments.  | 
209  | 
        # apply_redirected as a StringIO. We do this by overriding
 | 
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
210  | 
        # apply_redirected in this class, and then calling _run_bzr_core,
 | 
| 
1687.1.15
by Robert Collins
 Review comments.  | 
211  | 
        # which calls apply_redirected. 
 | 
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
212  | 
self.run_bzr(['foo', 'bar'], stdin='gam')  | 
| 
1687.1.2
by Robert Collins
 Add stdin parameter to run_bzr and run_bzr_captured.  | 
213  | 
self.assertEqual('gam', self.stdin.read())  | 
| 
1687.1.11
by Robert Collins
 Teach TestCase.run_bzr_captured about the ui factories.  | 
214  | 
self.assertTrue(self.stdin is self.factory_stdin)  | 
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
215  | 
self.run_bzr(['foo', 'bar'], stdin='zippy')  | 
| 
1687.1.2
by Robert Collins
 Add stdin parameter to run_bzr and run_bzr_captured.  | 
216  | 
self.assertEqual('zippy', self.stdin.read())  | 
| 
1687.1.11
by Robert Collins
 Teach TestCase.run_bzr_captured about the ui factories.  | 
217  | 
self.assertTrue(self.stdin is self.factory_stdin)  | 
| 
1692.3.3
by Robert Collins
 Get run_bzr in tests to always assign a new, clean ui factory.  | 
218  | 
|
219  | 
def test_ui_factory(self):  | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
220  | 
        # each invocation of self.run_bzr should get its
 | 
| 
2294.4.4
by Vincent Ladeuil
 Provide a better implementation for testing passwords.  | 
221  | 
        # own UI factory, which is an instance of TestUIFactory,
 | 
222  | 
        # with stdin, stdout and stderr attached to the stdin,
 | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
223  | 
        # stdout and stderr of the invoked run_bzr
 | 
| 
1692.3.3
by Robert Collins
 Get run_bzr in tests to always assign a new, clean ui factory.  | 
224  | 
current_factory = bzrlib.ui.ui_factory  | 
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
225  | 
self.run_bzr(['foo'])  | 
| 
1692.3.3
by Robert Collins
 Get run_bzr in tests to always assign a new, clean ui factory.  | 
226  | 
self.failIf(current_factory is self.factory)  | 
227  | 
self.assertNotEqual(sys.stdout, self.factory.stdout)  | 
|
228  | 
self.assertNotEqual(sys.stderr, self.factory.stderr)  | 
|
229  | 
self.assertEqual('foo\n', self.factory.stdout.getvalue())  | 
|
230  | 
self.assertEqual('bar\n', self.factory.stderr.getvalue())  | 
|
| 
2294.4.4
by Vincent Ladeuil
 Provide a better implementation for testing passwords.  | 
231  | 
self.assertIsInstance(self.factory, TestUIFactory)  | 
| 
1871.1.1
by Robert Collins
 Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py.  | 
232  | 
|
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
233  | 
def test_working_dir(self):  | 
234  | 
self.build_tree(['one/', 'two/'])  | 
|
235  | 
cwd = osutils.getcwd()  | 
|
236  | 
||
237  | 
        # Default is to work in the current directory
 | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
238  | 
self.run_bzr(['foo', 'bar'])  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
239  | 
self.assertEqual(cwd, self.working_dir)  | 
240  | 
||
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
241  | 
self.run_bzr(['foo', 'bar'], working_dir=None)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
242  | 
self.assertEqual(cwd, self.working_dir)  | 
243  | 
||
| 
2027.5.2
by John Arbash Meinel
 add tests that the working directory is preserved, cleanup run_bzr_subprocess  | 
244  | 
        # The function should be run in the alternative directory
 | 
245  | 
        # but afterwards the current working dir shouldn't be changed
 | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
246  | 
self.run_bzr(['foo', 'bar'], working_dir='one')  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
247  | 
self.assertNotEqual(cwd, self.working_dir)  | 
248  | 
self.assertEndsWith(self.working_dir, 'one')  | 
|
| 
2027.5.2
by John Arbash Meinel
 add tests that the working directory is preserved, cleanup run_bzr_subprocess  | 
249  | 
self.assertEqual(cwd, osutils.getcwd())  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
250  | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
251  | 
self.run_bzr(['foo', 'bar'], working_dir='two')  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
252  | 
self.assertNotEqual(cwd, self.working_dir)  | 
253  | 
self.assertEndsWith(self.working_dir, 'two')  | 
|
| 
2027.5.2
by John Arbash Meinel
 add tests that the working directory is preserved, cleanup run_bzr_subprocess  | 
254  | 
self.assertEqual(cwd, osutils.getcwd())  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
255  | 
|
256  | 
||
257  | 
class TestRunBzrSubprocess(TestCaseWithTransport):  | 
|
258  | 
||
| 
1871.1.1
by Robert Collins
 Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py.  | 
259  | 
def test_run_bzr_subprocess(self):  | 
| 
3565.2.1
by Christophe Troestler
 (trivial) Corrected typos.  | 
260  | 
"""The run_bzr_helper_external command behaves nicely."""  | 
| 
1871.1.1
by Robert Collins
 Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py.  | 
261  | 
result = self.run_bzr_subprocess('--version')  | 
| 
2665.4.1
by Aaron Bentley
 teach run_bzr_subprocess to accept either a list of strings or a string  | 
262  | 
result = self.run_bzr_subprocess(['--version'])  | 
| 
1871.1.1
by Robert Collins
 Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py.  | 
263  | 
result = self.run_bzr_subprocess('--version', retcode=None)  | 
264  | 
self.assertContainsRe(result[0], 'is free software')  | 
|
265  | 
self.assertRaises(AssertionError, self.run_bzr_subprocess,  | 
|
266  | 
'--versionn')  | 
|
267  | 
result = self.run_bzr_subprocess('--versionn', retcode=3)  | 
|
268  | 
result = self.run_bzr_subprocess('--versionn', retcode=None)  | 
|
269  | 
self.assertContainsRe(result[1], 'unknown command')  | 
|
| 
2665.4.2
by Aaron Bentley
 Update from review  | 
270  | 
err = self.run_bzr_subprocess(['merge', '--merge-type',  | 
271  | 
'magic merge'], retcode=3)[1]  | 
|
| 
2221.4.15
by Aaron Bentley
 Use RegistryOption for merge type  | 
272  | 
self.assertContainsRe(err, 'Bad value "magic merge" for option'  | 
273  | 
' "merge-type"')  | 
|
| 
1871.1.1
by Robert Collins
 Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py.  | 
274  | 
|
| 
1963.1.1
by John Arbash Meinel
 run_bzr_subprocess() can take an env_changes parameter  | 
275  | 
def test_run_bzr_subprocess_env(self):  | 
276  | 
"""run_bzr_subprocess can set environment variables in the child only.  | 
|
277  | 
||
278  | 
        These changes should not change the running process, only the child.
 | 
|
279  | 
        """
 | 
|
280  | 
        # The test suite should unset this variable
 | 
|
281  | 
self.assertEqual(None, os.environ.get('BZR_EMAIL'))  | 
|
282  | 
out, err = self.run_bzr_subprocess('whoami', env_changes={  | 
|
283  | 
'BZR_EMAIL':'Joe Foo <joe@foo.com>'  | 
|
| 
1963.1.11
by John Arbash Meinel
 Add a universal_newlines flag to run_bzr_subprocess, so we can be line-ending independent for tests  | 
284  | 
}, universal_newlines=True)  | 
| 
1963.1.1
by John Arbash Meinel
 run_bzr_subprocess() can take an env_changes parameter  | 
285  | 
self.assertEqual('', err)  | 
286  | 
self.assertEqual('Joe Foo <joe@foo.com>\n', out)  | 
|
287  | 
        # And it should not be modified
 | 
|
288  | 
self.assertEqual(None, os.environ.get('BZR_EMAIL'))  | 
|
289  | 
||
290  | 
        # Do it again with a different address, just to make sure
 | 
|
291  | 
        # it is actually changing
 | 
|
292  | 
out, err = self.run_bzr_subprocess('whoami', env_changes={  | 
|
293  | 
'BZR_EMAIL':'Barry <bar@foo.com>'  | 
|
| 
1963.1.11
by John Arbash Meinel
 Add a universal_newlines flag to run_bzr_subprocess, so we can be line-ending independent for tests  | 
294  | 
}, universal_newlines=True)  | 
| 
1963.1.1
by John Arbash Meinel
 run_bzr_subprocess() can take an env_changes parameter  | 
295  | 
self.assertEqual('', err)  | 
296  | 
self.assertEqual('Barry <bar@foo.com>\n', out)  | 
|
297  | 
self.assertEqual(None, os.environ.get('BZR_EMAIL'))  | 
|
298  | 
||
| 
1963.1.2
by John Arbash Meinel
 Cleanups suggested by Martin, add test that env_changes can remove an env variable  | 
299  | 
def test_run_bzr_subprocess_env_del(self):  | 
300  | 
"""run_bzr_subprocess can remove environment variables too."""  | 
|
301  | 
        # Create a random email, so we are sure this won't collide
 | 
|
302  | 
rand_bzr_email = 'John Doe <jdoe@%s.com>' % (osutils.rand_chars(20),)  | 
|
303  | 
rand_email = 'Jane Doe <jdoe@%s.com>' % (osutils.rand_chars(20),)  | 
|
304  | 
os.environ['BZR_EMAIL'] = rand_bzr_email  | 
|
305  | 
os.environ['EMAIL'] = rand_email  | 
|
306  | 
try:  | 
|
307  | 
            # By default, the child will inherit the current env setting
 | 
|
| 
1963.1.11
by John Arbash Meinel
 Add a universal_newlines flag to run_bzr_subprocess, so we can be line-ending independent for tests  | 
308  | 
out, err = self.run_bzr_subprocess('whoami', universal_newlines=True)  | 
| 
1963.1.2
by John Arbash Meinel
 Cleanups suggested by Martin, add test that env_changes can remove an env variable  | 
309  | 
self.assertEqual('', err)  | 
310  | 
self.assertEqual(rand_bzr_email + '\n', out)  | 
|
311  | 
||
312  | 
            # Now that BZR_EMAIL is not set, it should fall back to EMAIL
 | 
|
313  | 
out, err = self.run_bzr_subprocess('whoami',  | 
|
| 
1963.1.11
by John Arbash Meinel
 Add a universal_newlines flag to run_bzr_subprocess, so we can be line-ending independent for tests  | 
314  | 
env_changes={'BZR_EMAIL':None},  | 
315  | 
universal_newlines=True)  | 
|
| 
1963.1.2
by John Arbash Meinel
 Cleanups suggested by Martin, add test that env_changes can remove an env variable  | 
316  | 
self.assertEqual('', err)  | 
317  | 
self.assertEqual(rand_email + '\n', out)  | 
|
318  | 
||
319  | 
            # This switches back to the default email guessing logic
 | 
|
320  | 
            # Which shouldn't match either of the above addresses
 | 
|
321  | 
out, err = self.run_bzr_subprocess('whoami',  | 
|
| 
1963.1.11
by John Arbash Meinel
 Add a universal_newlines flag to run_bzr_subprocess, so we can be line-ending independent for tests  | 
322  | 
env_changes={'BZR_EMAIL':None, 'EMAIL':None},  | 
323  | 
universal_newlines=True)  | 
|
| 
1963.1.2
by John Arbash Meinel
 Cleanups suggested by Martin, add test that env_changes can remove an env variable  | 
324  | 
|
325  | 
self.assertEqual('', err)  | 
|
326  | 
self.assertNotEqual(rand_bzr_email + '\n', out)  | 
|
327  | 
self.assertNotEqual(rand_email + '\n', out)  | 
|
328  | 
finally:  | 
|
329  | 
            # TestCase cleans up BZR_EMAIL, and EMAIL at startup
 | 
|
330  | 
del os.environ['BZR_EMAIL']  | 
|
331  | 
del os.environ['EMAIL']  | 
|
| 
1871.1.1
by Robert Collins
 Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py.  | 
332  | 
|
| 
1963.1.4
by John Arbash Meinel
 env_changes={} should be safe to remove variables that aren't there  | 
333  | 
def test_run_bzr_subprocess_env_del_missing(self):  | 
334  | 
"""run_bzr_subprocess won't fail if deleting a nonexistant env var"""  | 
|
335  | 
self.failIf('NON_EXISTANT_ENV_VAR' in os.environ)  | 
|
336  | 
out, err = self.run_bzr_subprocess('rocks',  | 
|
| 
1963.1.11
by John Arbash Meinel
 Add a universal_newlines flag to run_bzr_subprocess, so we can be line-ending independent for tests  | 
337  | 
env_changes={'NON_EXISTANT_ENV_VAR':None},  | 
338  | 
universal_newlines=True)  | 
|
| 
2227.4.1
by v.ladeuil+lp at free
 Fix #78026.  | 
339  | 
self.assertEqual('It sure does!\n', out)  | 
| 
1963.1.11
by John Arbash Meinel
 Add a universal_newlines flag to run_bzr_subprocess, so we can be line-ending independent for tests  | 
340  | 
self.assertEqual('', err)  | 
| 
1963.1.4
by John Arbash Meinel
 env_changes={} should be safe to remove variables that aren't there  | 
341  | 
|
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
342  | 
def test_run_bzr_subprocess_working_dir(self):  | 
| 
2027.5.2
by John Arbash Meinel
 add tests that the working directory is preserved, cleanup run_bzr_subprocess  | 
343  | 
"""Test that we can specify the working dir for the child"""  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
344  | 
cwd = osutils.getcwd()  | 
345  | 
||
346  | 
self.make_branch_and_tree('.')  | 
|
347  | 
self.make_branch_and_tree('one')  | 
|
348  | 
self.make_branch_and_tree('two')  | 
|
349  | 
||
| 
2027.5.2
by John Arbash Meinel
 add tests that the working directory is preserved, cleanup run_bzr_subprocess  | 
350  | 
def get_root(**kwargs):  | 
351  | 
"""Spawn a process to get the 'root' of the tree.  | 
|
352  | 
||
353  | 
            You can pass in arbitrary new arguments. This just makes
 | 
|
354  | 
            sure that the returned path doesn't have trailing whitespace.
 | 
|
355  | 
            """
 | 
|
356  | 
return self.run_bzr_subprocess('root', **kwargs)[0].rstrip()  | 
|
357  | 
||
358  | 
self.assertEqual(cwd, get_root())  | 
|
359  | 
self.assertEqual(cwd, get_root(working_dir=None))  | 
|
360  | 
        # Has our path changed?
 | 
|
361  | 
self.assertEqual(cwd, osutils.getcwd())  | 
|
362  | 
||
363  | 
dir1 = get_root(working_dir='one')  | 
|
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
364  | 
self.assertEndsWith(dir1, 'one')  | 
| 
2027.5.2
by John Arbash Meinel
 add tests that the working directory is preserved, cleanup run_bzr_subprocess  | 
365  | 
self.assertEqual(cwd, osutils.getcwd())  | 
366  | 
||
367  | 
dir2 = get_root(working_dir='two')  | 
|
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
368  | 
self.assertEndsWith(dir2, 'two')  | 
| 
2027.5.2
by John Arbash Meinel
 add tests that the working directory is preserved, cleanup run_bzr_subprocess  | 
369  | 
self.assertEqual(cwd, osutils.getcwd())  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
370  | 
|
371  | 
||
| 
2067.2.2
by John Arbash Meinel
 Review comments from Robert  | 
372  | 
class _DontSpawnProcess(Exception):  | 
373  | 
"""A simple exception which just allows us to skip unnecessary steps"""  | 
|
374  | 
||
375  | 
||
376  | 
class TestRunBzrSubprocessCommands(TestCaseWithTransport):  | 
|
377  | 
||
378  | 
def _popen(self, *args, **kwargs):  | 
|
379  | 
"""Record the command that is run, so that we can ensure it is correct"""  | 
|
380  | 
self._popen_args = args  | 
|
381  | 
self._popen_kwargs = kwargs  | 
|
382  | 
raise _DontSpawnProcess()  | 
|
383  | 
||
384  | 
def test_run_bzr_subprocess_no_plugins(self):  | 
|
| 
2665.4.1
by Aaron Bentley
 teach run_bzr_subprocess to accept either a list of strings or a string  | 
385  | 
self.assertRaises(_DontSpawnProcess, self.run_bzr_subprocess, '')  | 
| 
2067.2.2
by John Arbash Meinel
 Review comments from Robert  | 
386  | 
command = self._popen_args[0]  | 
387  | 
self.assertEqual(sys.executable, command[0])  | 
|
388  | 
self.assertEqual(self.get_bzr_path(), command[1])  | 
|
389  | 
self.assertEqual(['--no-plugins'], command[2:])  | 
|
390  | 
||
391  | 
def test_allow_plugins(self):  | 
|
| 
2067.2.4
by John Arbash Meinel
 fixup one test  | 
392  | 
self.assertRaises(_DontSpawnProcess,  | 
| 
2665.4.1
by Aaron Bentley
 teach run_bzr_subprocess to accept either a list of strings or a string  | 
393  | 
self.run_bzr_subprocess, '', allow_plugins=True)  | 
| 
2067.2.2
by John Arbash Meinel
 Review comments from Robert  | 
394  | 
command = self._popen_args[0]  | 
395  | 
self.assertEqual([], command[2:])  | 
|
396  | 
||
397  | 
||
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
398  | 
class TestBzrSubprocess(TestCaseWithTransport):  | 
399  | 
||
| 
1910.17.2
by Andrew Bennetts
 Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue  | 
400  | 
def test_start_and_stop_bzr_subprocess(self):  | 
401  | 
"""We can start and perform other test actions while that process is  | 
|
402  | 
        still alive.
 | 
|
403  | 
        """
 | 
|
| 
1910.17.8
by Andrew Bennetts
 Refactor run_bzr_subprocess to use start_bzr_subprocess and finish_bzr_subprocess.  | 
404  | 
process = self.start_bzr_subprocess(['--version'])  | 
| 
1910.17.2
by Andrew Bennetts
 Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue  | 
405  | 
result = self.finish_bzr_subprocess(process)  | 
406  | 
self.assertContainsRe(result[0], 'is free software')  | 
|
407  | 
self.assertEqual('', result[1])  | 
|
408  | 
||
409  | 
def test_start_and_stop_bzr_subprocess_with_error(self):  | 
|
410  | 
"""finish_bzr_subprocess allows specification of the desired exit code.  | 
|
411  | 
        """
 | 
|
| 
1910.17.8
by Andrew Bennetts
 Refactor run_bzr_subprocess to use start_bzr_subprocess and finish_bzr_subprocess.  | 
412  | 
process = self.start_bzr_subprocess(['--versionn'])  | 
| 
1910.17.2
by Andrew Bennetts
 Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue  | 
413  | 
result = self.finish_bzr_subprocess(process, retcode=3)  | 
414  | 
self.assertEqual('', result[0])  | 
|
415  | 
self.assertContainsRe(result[1], 'unknown command')  | 
|
416  | 
||
417  | 
def test_start_and_stop_bzr_subprocess_ignoring_retcode(self):  | 
|
418  | 
"""finish_bzr_subprocess allows the exit code to be ignored."""  | 
|
| 
1910.17.8
by Andrew Bennetts
 Refactor run_bzr_subprocess to use start_bzr_subprocess and finish_bzr_subprocess.  | 
419  | 
process = self.start_bzr_subprocess(['--versionn'])  | 
| 
1910.17.2
by Andrew Bennetts
 Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue  | 
420  | 
result = self.finish_bzr_subprocess(process, retcode=None)  | 
421  | 
self.assertEqual('', result[0])  | 
|
422  | 
self.assertContainsRe(result[1], 'unknown command')  | 
|
423  | 
||
424  | 
def test_start_and_stop_bzr_subprocess_with_unexpected_retcode(self):  | 
|
425  | 
"""finish_bzr_subprocess raises self.failureException if the retcode is  | 
|
426  | 
        not the expected one.
 | 
|
427  | 
        """
 | 
|
| 
1910.17.8
by Andrew Bennetts
 Refactor run_bzr_subprocess to use start_bzr_subprocess and finish_bzr_subprocess.  | 
428  | 
process = self.start_bzr_subprocess(['--versionn'])  | 
| 
1910.17.2
by Andrew Bennetts
 Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue  | 
429  | 
self.assertRaises(self.failureException, self.finish_bzr_subprocess,  | 
| 
2581.1.2
by Martin Pool
 Remove unnecessary retcode=0 to run_bzr calls  | 
430  | 
process)  | 
| 
1910.17.2
by Andrew Bennetts
 Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue  | 
431  | 
|
432  | 
def test_start_and_stop_bzr_subprocess_send_signal(self):  | 
|
433  | 
"""finish_bzr_subprocess raises self.failureException if the retcode is  | 
|
434  | 
        not the expected one.
 | 
|
435  | 
        """
 | 
|
| 
1910.17.9
by Andrew Bennetts
 Add skip_if_plan_to_signal flag to start_bzr_subprocess.  | 
436  | 
process = self.start_bzr_subprocess(['wait-until-signalled'],  | 
437  | 
skip_if_plan_to_signal=True)  | 
|
| 
1910.17.2
by Andrew Bennetts
 Add start_bzr_subprocess and stop_bzr_subprocess to allow test code to continue  | 
438  | 
self.assertEqual('running\n', process.stdout.readline())  | 
439  | 
result = self.finish_bzr_subprocess(process, send_signal=signal.SIGINT,  | 
|
440  | 
retcode=3)  | 
|
441  | 
self.assertEqual('', result[0])  | 
|
442  | 
self.assertEqual('bzr: interrupted\n', result[1])  | 
|
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
443  | 
|
444  | 
def test_start_and_stop_working_dir(self):  | 
|
445  | 
cwd = osutils.getcwd()  | 
|
446  | 
||
447  | 
self.make_branch_and_tree('one')  | 
|
448  | 
||
449  | 
process = self.start_bzr_subprocess(['root'], working_dir='one')  | 
|
| 
2156.1.1
by v.ladeuil+lp at free
 Make the test compatible with windows.  | 
450  | 
result = self.finish_bzr_subprocess(process, universal_newlines=True)  | 
| 
2027.5.1
by John Arbash Meinel
 Add working_dir=XX to run_bzr_* functions, and clean up tests  | 
451  | 
self.assertEndsWith(result[0], 'one\n')  | 
452  | 
self.assertEqual('', result[1])  | 
|
| 
2156.1.1
by v.ladeuil+lp at free
 Make the test compatible with windows.  | 
453  | 
|
| 
1963.1.4
by John Arbash Meinel
 env_changes={} should be safe to remove variables that aren't there  | 
454  | 
|
| 
1871.1.1
by Robert Collins
 Relocate bzrlib selftest external output tests to bzrlib/tests/blackbox/test_selftest.py.  | 
455  | 
class TestRunBzrError(ExternalBase):  | 
456  | 
||
457  | 
def test_run_bzr_error(self):  | 
|
| 
2581.1.3
by Martin Pool
 Revert over-eager cleanup of test_run_bzr_error  | 
458  | 
        # retcode=0 is specially needed here because run_bzr_error expects
 | 
459  | 
        # an error (oddly enough) but we want to test the case of not
 | 
|
460  | 
        # actually getting one
 | 
|
461  | 
out, err = self.run_bzr_error(['^$'], ['rocks'], retcode=0)  | 
|
| 
2227.4.1
by v.ladeuil+lp at free
 Fix #78026.  | 
462  | 
self.assertEqual(out, 'It sure does!\n')  | 
| 
2581.1.3
by Martin Pool
 Revert over-eager cleanup of test_run_bzr_error  | 
463  | 
        # now test actually getting an error
 | 
464  | 
out, err = self.run_bzr_error(  | 
|
465  | 
["bzr: ERROR: foobarbaz is not versioned"],  | 
|
466  | 
['file-id', 'foobarbaz'])  | 
|
| 
2172.4.3
by Alexander Belchenko
 Change name of option to '--clean-output' and provide tests  | 
467  | 
|
468  | 
||
| 
2394.2.6
by Ian Clatworthy
 completed blackbox tests  | 
469  | 
class TestSelftestListOnly(TestCase):  | 
| 
2394.2.5
by Ian Clatworthy
 list-only working, include test not  | 
470  | 
|
471  | 
    @staticmethod
 | 
|
| 
2394.2.6
by Ian Clatworthy
 completed blackbox tests  | 
472  | 
def _parse_test_list(lines, newlines_in_header=1):  | 
| 
2394.2.5
by Ian Clatworthy
 list-only working, include test not  | 
473  | 
        "Parse a list of lines into a tuple of 3 lists (header,body,footer)."
 | 
474  | 
in_header = True  | 
|
475  | 
in_footer = False  | 
|
476  | 
header = []  | 
|
477  | 
body = []  | 
|
| 
2394.2.6
by Ian Clatworthy
 completed blackbox tests  | 
478  | 
footer = []  | 
| 
2687.3.1
by Martin Pool
 Revert selftest header to just two lines, but still show the bzrlib and python versions  | 
479  | 
header_newlines_found = 0  | 
| 
2394.2.5
by Ian Clatworthy
 list-only working, include test not  | 
480  | 
for line in lines:  | 
481  | 
if in_header:  | 
|
482  | 
if line == '':  | 
|
| 
2394.2.6
by Ian Clatworthy
 completed blackbox tests  | 
483  | 
header_newlines_found += 1  | 
484  | 
if header_newlines_found >= newlines_in_header:  | 
|
485  | 
in_header = False  | 
|
486  | 
                        continue
 | 
|
487  | 
header.append(line)  | 
|
| 
2394.2.5
by Ian Clatworthy
 list-only working, include test not  | 
488  | 
elif not in_footer:  | 
489  | 
if line.startswith('-------'):  | 
|
490  | 
in_footer = True  | 
|
491  | 
else:  | 
|
492  | 
body.append(line)  | 
|
493  | 
else:  | 
|
494  | 
footer.append(line)  | 
|
495  | 
        # If the last body line is blank, drop it off the list
 | 
|
496  | 
if len(body) > 0 and body[-1] == '':  | 
|
| 
2687.3.1
by Martin Pool
 Revert selftest header to just two lines, but still show the bzrlib and python versions  | 
497  | 
body.pop()  | 
| 
2394.2.5
by Ian Clatworthy
 list-only working, include test not  | 
498  | 
return (header,body,footer)  | 
499  | 
||
500  | 
def test_list_only(self):  | 
|
501  | 
        # check that bzr selftest --list-only works correctly
 | 
|
| 
2552.2.2
by Vincent Ladeuil
 Enforce run_bzr(string) where possible.  | 
502  | 
out,err = self.run_bzr('selftest selftest --list-only')  | 
| 
2394.2.6
by Ian Clatworthy
 completed blackbox tests  | 
503  | 
self.assertEndsWith(err, 'tests passed\n')  | 
| 
2394.2.5
by Ian Clatworthy
 list-only working, include test not  | 
504  | 
(header,body,footer) = self._parse_test_list(out.splitlines())  | 
| 
2394.2.8
by Ian Clatworthy
 incorporate feedback from jam  | 
505  | 
num_tests = len(body)  | 
506  | 
self.assertContainsRe(footer[0], 'Listed %s tests in' % num_tests)  | 
|
| 
2394.2.5
by Ian Clatworthy
 list-only working, include test not  | 
507  | 
|
| 
2394.2.6
by Ian Clatworthy
 completed blackbox tests  | 
508  | 
def test_list_only_filtered(self):  | 
509  | 
        # check that a filtered --list-only works, both include and exclude
 | 
|
| 
2552.2.2
by Vincent Ladeuil
 Enforce run_bzr(string) where possible.  | 
510  | 
out_all,err_all = self.run_bzr('selftest --list-only')  | 
| 
2394.2.5
by Ian Clatworthy
 list-only working, include test not  | 
511  | 
tests_all = self._parse_test_list(out_all.splitlines())[1]  | 
| 
2552.2.2
by Vincent Ladeuil
 Enforce run_bzr(string) where possible.  | 
512  | 
out_incl,err_incl = self.run_bzr('selftest --list-only selftest')  | 
| 
2394.2.6
by Ian Clatworthy
 completed blackbox tests  | 
513  | 
tests_incl = self._parse_test_list(out_incl.splitlines())[1]  | 
514  | 
self.assertSubset(tests_incl, tests_all)  | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
515  | 
out_excl,err_excl = self.run_bzr(['selftest', '--list-only',  | 
| 
2552.2.2
by Vincent Ladeuil
 Enforce run_bzr(string) where possible.  | 
516  | 
'--exclude', 'selftest'])  | 
| 
2394.2.6
by Ian Clatworthy
 completed blackbox tests  | 
517  | 
tests_excl = self._parse_test_list(out_excl.splitlines())[1]  | 
518  | 
self.assertSubset(tests_excl, tests_all)  | 
|
519  | 
set_incl = set(tests_incl)  | 
|
520  | 
set_excl = set(tests_excl)  | 
|
521  | 
intersection = set_incl.intersection(set_excl)  | 
|
522  | 
self.assertEquals(0, len(intersection))  | 
|
523  | 
self.assertEquals(len(tests_all), len(tests_incl) + len(tests_excl))  | 
|
524  | 
||
525  | 
def test_list_only_random(self):  | 
|
526  | 
        # check that --randomize works correctly
 | 
|
| 
2552.2.2
by Vincent Ladeuil
 Enforce run_bzr(string) where possible.  | 
527  | 
out_all,err_all = self.run_bzr('selftest --list-only selftest')  | 
| 
2394.2.6
by Ian Clatworthy
 completed blackbox tests  | 
528  | 
tests_all = self._parse_test_list(out_all.splitlines())[1]  | 
| 
2477.1.6
by Martin Pool
 doc  | 
529  | 
        # XXX: It looks like there are some orders for generating tests that
 | 
530  | 
        # fail as of 20070504 - maybe because of import order dependencies.
 | 
|
531  | 
        # So unfortunately this will rarely intermittently fail at the moment.
 | 
|
532  | 
        # -- mbp 20070504
 | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
533  | 
out_rand,err_rand = self.run_bzr(['selftest', '--list-only',  | 
| 
2552.2.2
by Vincent Ladeuil
 Enforce run_bzr(string) where possible.  | 
534  | 
'selftest', '--randomize', 'now'])  | 
| 
2394.2.6
by Ian Clatworthy
 completed blackbox tests  | 
535  | 
(header_rand,tests_rand,dummy) = self._parse_test_list(  | 
536  | 
out_rand.splitlines(), 2)  | 
|
| 
2687.3.1
by Martin Pool
 Revert selftest header to just two lines, but still show the bzrlib and python versions  | 
537  | 
        # XXX: The following line asserts that the randomized order is not the
 | 
538  | 
        # same as the default order.  It is just possible that they'll get
 | 
|
539  | 
        # randomized into the same order and this will falsely fail, but
 | 
|
540  | 
        # that's very unlikely in practice because there are thousands of
 | 
|
541  | 
        # tests.
 | 
|
| 
2394.2.6
by Ian Clatworthy
 completed blackbox tests  | 
542  | 
self.assertNotEqual(tests_all, tests_rand)  | 
543  | 
self.assertEqual(sorted(tests_all), sorted(tests_rand))  | 
|
544  | 
        # Check that the seed can be reused to get the exact same order
 | 
|
545  | 
seed_re = re.compile('Randomizing test order using seed (\w+)')  | 
|
546  | 
match_obj = seed_re.search(header_rand[-1])  | 
|
547  | 
seed = match_obj.group(1)  | 
|
| 
2530.3.4
by Martin Pool
 Deprecate run_bzr_captured in favour of just run_bzr  | 
548  | 
out_rand2,err_rand2 = self.run_bzr(['selftest', '--list-only',  | 
| 
2552.2.2
by Vincent Ladeuil
 Enforce run_bzr(string) where possible.  | 
549  | 
'selftest', '--randomize', seed])  | 
| 
2394.2.6
by Ian Clatworthy
 completed blackbox tests  | 
550  | 
(header_rand2,tests_rand2,dummy) = self._parse_test_list(  | 
551  | 
out_rand2.splitlines(), 2)  | 
|
552  | 
self.assertEqual(tests_rand, tests_rand2)  | 
|
| 
2394.2.5
by Ian Clatworthy
 list-only working, include test not  | 
553  | 
|
| 
3193.1.8
by Vincent Ladeuil
 Add '--load-list' option to selftest.  | 
554  | 
|
555  | 
class TestSelftestWithIdList(TestCaseInTempDir):  | 
|
556  | 
||
557  | 
def test_load_list(self):  | 
|
558  | 
        # We don't want to call selftest for the whole suite, so we start with
 | 
|
559  | 
        # a reduced list.
 | 
|
560  | 
test_list_fname = 'test.list'  | 
|
561  | 
fl = open(test_list_fname, 'wt')  | 
|
562  | 
fl.write('%s\n' % self.id())  | 
|
563  | 
fl.close()  | 
|
564  | 
out, err = self.run_bzr(  | 
|
565  | 
['selftest', '--load-list', test_list_fname, '--list'])  | 
|
566  | 
self.assertContainsRe(out, "Listed 1 test in")  | 
|
567  | 
||
568  | 
def test_load_unknown(self):  | 
|
569  | 
out, err = self.run_bzr('selftest --load-list I_do_not_exist ',  | 
|
570  | 
retcode=3)  | 
|
| 
3302.11.2
by Vincent Ladeuil
 selftest now accepts --starting-ith <id> to load and execute only a module|class|test* reduced suite.  | 
571  | 
|
572  | 
||
573  | 
class TestSelftestStartingWith(TestCase):  | 
|
574  | 
||
| 
3649.6.4
by Vincent Ladeuil
 selftest --starting-with now accepts multiple values.  | 
575  | 
def test_starting_with_single_argument(self):  | 
| 
3302.11.2
by Vincent Ladeuil
 selftest now accepts --starting-ith <id> to load and execute only a module|class|test* reduced suite.  | 
576  | 
out, err = self.run_bzr(  | 
577  | 
['selftest', '--starting-with', self.id(), '--list'])  | 
|
578  | 
self.assertContainsRe(out, "Listed 1 test in")  | 
|
| 
3302.11.5
by Vincent Ladeuil
 Fixed as per John's review. Also added a NEWS entry.  | 
579  | 
self.assertContainsRe(out, self.id())  | 
| 
3302.11.2
by Vincent Ladeuil
 selftest now accepts --starting-ith <id> to load and execute only a module|class|test* reduced suite.  | 
580  | 
|
| 
3649.6.4
by Vincent Ladeuil
 selftest --starting-with now accepts multiple values.  | 
581  | 
def test_starting_with_multiple_argument(self):  | 
582  | 
out, err = self.run_bzr(  | 
|
583  | 
['selftest',  | 
|
584  | 
'--starting-with', self.id(),  | 
|
585  | 
'--starting-with', 'bzrlib.tests.test_sampler',  | 
|
586  | 
'--list'])  | 
|
587  | 
self.assertContainsRe(out, "Listed 2 tests in")  | 
|
588  | 
self.assertContainsRe(out, self.id())  | 
|
589  | 
self.assertContainsRe(out, 'bzrlib.tests.test_sampler')  |