bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
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. |
1 |
# Copyright (C) 2005 by Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License version 2 as published by
|
|
5 |
# the Free Software Foundation.
|
|
6 |
#
|
|
7 |
# This program is distributed in the hope that it will be useful,
|
|
8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
# GNU General Public License for more details.
|
|
11 |
#
|
|
12 |
# You should have received a copy of the GNU General Public License
|
|
13 |
# along with this program; if not, write to the Free Software
|
|
14 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
15 |
||
16 |
"""UI tests for the test framework."""
|
|
17 |
||
|
1692.3.3
by Robert Collins
Get run_bzr in tests to always assign a new, clean ui factory. |
18 |
import sys |
19 |
||
|
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. |
20 |
import bzrlib |
|
1551.2.47
by abentley
Fixed test_selftest's use of sftp |
21 |
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. |
22 |
from bzrlib.tests import ( |
23 |
TestCase, |
|
24 |
TestCaseInTempDir, |
|
25 |
TestSkipped, |
|
26 |
)
|
|
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
27 |
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. |
28 |
|
29 |
||
30 |
class TestOptions(TestCase): |
|
31 |
||
32 |
current_test = None |
|
33 |
||
34 |
def test_transport_set_to_sftp(self): |
|
35 |
# test the --transport option has taken effect from within the
|
|
36 |
# test_transport test
|
|
|
1551.2.47
by abentley
Fixed test_selftest's use of sftp |
37 |
try: |
38 |
import bzrlib.transport.sftp |
|
39 |
except ParamikoNotPresent: |
|
40 |
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. |
41 |
if TestOptions.current_test != "test_transport_set_to_sftp": |
42 |
return
|
|
43 |
self.assertEqual(bzrlib.transport.sftp.SFTPAbsoluteServer, |
|
44 |
bzrlib.tests.default_transport) |
|
45 |
||
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
46 |
def test_transport_set_to_memory(self): |
47 |
# test the --transport option has taken effect from within the
|
|
48 |
# test_transport test
|
|
49 |
import bzrlib.transport.memory |
|
50 |
if TestOptions.current_test != "test_transport_set_to_memory": |
|
51 |
return
|
|
52 |
self.assertEqual(bzrlib.transport.memory.MemoryServer, |
|
53 |
bzrlib.tests.default_transport) |
|
54 |
||
|
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. |
55 |
def test_transport(self): |
56 |
# test that --transport=sftp works
|
|
|
1551.2.47
by abentley
Fixed test_selftest's use of sftp |
57 |
try: |
58 |
import bzrlib.transport.sftp |
|
59 |
except ParamikoNotPresent: |
|
60 |
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. |
61 |
old_transport = bzrlib.tests.default_transport |
62 |
old_root = TestCaseInTempDir.TEST_ROOT |
|
63 |
TestCaseInTempDir.TEST_ROOT = None |
|
64 |
try: |
|
65 |
TestOptions.current_test = "test_transport_set_to_sftp" |
|
66 |
stdout = self.capture('selftest --transport=sftp test_transport_set_to_sftp') |
|
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
67 |
|
68 |
self.assertContainsRe(stdout, 'Ran 1 test') |
|
69 |
self.assertEqual(old_transport, bzrlib.tests.default_transport) |
|
70 |
||
71 |
TestOptions.current_test = "test_transport_set_to_memory" |
|
72 |
stdout = self.capture('selftest --transport=memory test_transport_set_to_memory') |
|
|
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. |
73 |
self.assertContainsRe(stdout, 'Ran 1 test') |
74 |
self.assertEqual(old_transport, bzrlib.tests.default_transport) |
|
75 |
finally: |
|
76 |
bzrlib.tests.default_transport = old_transport |
|
77 |
TestOptions.current_test = None |
|
78 |
TestCaseInTempDir.TEST_ROOT = old_root |
|
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
79 |
|
|
1707.2.1
by Robert Collins
'bzr selftest --benchmark' will run a new benchmarking selftest. |
80 |
def test_benchmark_runs_no_tests(self): |
81 |
"""bzr selftest --benchmark should not run the default test suite.""" |
|
82 |
# We test this via checking that no tests are run because the
|
|
83 |
# benchmark suite is currently empty.
|
|
84 |
out, err = self.run_bzr('selftest', '--benchmark') |
|
85 |
self.assertContainsRe(out, 'Ran 0 tests.*\n\nOK') |
|
86 |
self.assertEqual( |
|
87 |
'running tests...\nRunning tests: .\nCleaning up: .\ntests passed\n', |
|
88 |
err) |
|
89 |
||
|
1707.2.2
by Robert Collins
Start on bench_add, an add benchtest. |
90 |
def test_benchmark_runs_no_tests(self): |
91 |
"""bzr selftest --benchmark should display useful statistics.""" |
|
92 |
# We test this via checking that no tests are run because the
|
|
93 |
# benchmark suite is currently empty.
|
|
94 |
out, err = self.run_bzr('selftest', '--benchmark') |
|
95 |
self.assertContainsRe(out, 'Ran 0 tests.*\n\nOK') |
|
96 |
self.assertEqual( |
|
97 |
'running tests...\nRunning tests: .\nCleaning up: .\ntests passed\n', |
|
98 |
err) |
|
99 |
||
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
100 |
|
101 |
class TestRunBzr(ExternalBase): |
|
102 |
||
103 |
def run_bzr_captured(self, argv, retcode=0, stdin=None): |
|
104 |
self.stdin = stdin |
|
105 |
||
106 |
def test_stdin(self): |
|
107 |
# test that the stdin keyword to run_bzr is passed through to
|
|
|
1687.1.15
by Robert Collins
Review comments. |
108 |
# run_bzr_captured as-is. We do this by overriding
|
109 |
# run_bzr_captured in this class, and then calling run_bzr,
|
|
110 |
# which is a convenience function for run_bzr_captured, so
|
|
111 |
# should invoke it.
|
|
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
112 |
self.run_bzr('foo', 'bar', stdin='gam') |
113 |
self.assertEqual('gam', self.stdin) |
|
114 |
self.run_bzr('foo', 'bar', stdin='zippy') |
|
115 |
self.assertEqual('zippy', self.stdin) |
|
116 |
||
117 |
||
118 |
class TestRunBzrCaptured(ExternalBase): |
|
119 |
||
120 |
def apply_redirected(self, stdin=None, stdout=None, stderr=None, |
|
121 |
a_callable=None, *args, **kwargs): |
|
122 |
self.stdin = stdin |
|
|
1687.1.11
by Robert Collins
Teach TestCase.run_bzr_captured about the ui factories. |
123 |
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. |
124 |
self.factory = bzrlib.ui.ui_factory |
125 |
stdout.write('foo\n') |
|
126 |
stderr.write('bar\n') |
|
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
127 |
return 0 |
128 |
||
129 |
def test_stdin(self): |
|
130 |
# test that the stdin keyword to run_bzr_captured is passed through to
|
|
|
1687.1.15
by Robert Collins
Review comments. |
131 |
# apply_redirected as a StringIO. We do this by overriding
|
132 |
# apply_redirected in this class, and then calling run_bzr_captured,
|
|
133 |
# which calls apply_redirected.
|
|
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
134 |
self.run_bzr_captured(['foo', 'bar'], stdin='gam') |
135 |
self.assertEqual('gam', self.stdin.read()) |
|
|
1687.1.11
by Robert Collins
Teach TestCase.run_bzr_captured about the ui factories. |
136 |
self.assertTrue(self.stdin is self.factory_stdin) |
|
1687.1.2
by Robert Collins
Add stdin parameter to run_bzr and run_bzr_captured. |
137 |
self.run_bzr_captured(['foo', 'bar'], stdin='zippy') |
138 |
self.assertEqual('zippy', self.stdin.read()) |
|
|
1687.1.11
by Robert Collins
Teach TestCase.run_bzr_captured about the ui factories. |
139 |
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. |
140 |
|
141 |
def test_ui_factory(self): |
|
142 |
# each invocation of self.run_bzr_captured should get its own UI
|
|
143 |
# factory, which is an instance of TestUIFactory, with stdout and
|
|
144 |
# stderr attached to the stdout and stderr of the invoked
|
|
145 |
# run_bzr_captured
|
|
146 |
current_factory = bzrlib.ui.ui_factory |
|
147 |
self.run_bzr_captured(['foo']) |
|
148 |
self.failIf(current_factory is self.factory) |
|
149 |
self.assertNotEqual(sys.stdout, self.factory.stdout) |
|
150 |
self.assertNotEqual(sys.stderr, self.factory.stderr) |
|
151 |
self.assertEqual('foo\n', self.factory.stdout.getvalue()) |
|
152 |
self.assertEqual('bar\n', self.factory.stderr.getvalue()) |
|
153 |
self.assertIsInstance(self.factory, bzrlib.tests.blackbox.TestUIFactory) |