27
27
from breezy.transport import memory
30
29
class SelfTestPatch:
32
31
def get_params_passed_to_core(self, cmdline):
35
33
def selftest(*args, **kwargs):
36
34
"""Capture the arguments selftest was run with."""
37
35
params.append((args, kwargs))
39
37
# Yes this prevents using threads to run the test suite in parallel,
40
# however we don't have a clean dependency injector for commands,
38
# however we don't have a clean dependency injector for commands,
41
39
# and even if we did - we'd still be testing that the glue is wired
42
40
# up correctly. XXX: TODO: Solve this testing problem.
43
41
original_selftest = tests.selftest
62
60
from breezy.tests import stub_sftp
63
61
params = self.get_params_passed_to_core('selftest --transport=sftp')
64
62
self.assertEqual(stub_sftp.SFTPAbsoluteServer,
65
params[1]["transport"])
63
params[1]["transport"])
67
65
def test_transport_set_to_memory(self):
68
66
# Test that we can pass a transport to the selftest core - memory
73
71
def test_parameters_passed_to_core(self):
74
72
params = self.get_params_passed_to_core('selftest --list-only')
75
73
self.assertTrue("list_only" in params[1])
76
params = self.get_params_passed_to_core(
77
'selftest --list-only selftest')
78
self.assertTrue("list_only" in params[1])
79
params = self.get_params_passed_to_core(['selftest', '--list-only',
80
'--exclude', 'selftest'])
81
self.assertTrue("list_only" in params[1])
82
params = self.get_params_passed_to_core(['selftest', '--list-only',
83
'selftest', '--randomize', 'now'])
74
params = self.get_params_passed_to_core('selftest --list-only selftest')
75
self.assertTrue("list_only" in params[1])
76
params = self.get_params_passed_to_core(['selftest', '--list-only',
77
'--exclude', 'selftest'])
78
self.assertTrue("list_only" in params[1])
79
params = self.get_params_passed_to_core(['selftest', '--list-only',
80
'selftest', '--randomize', 'now'])
84
81
self.assertSubset(["list_only", "random_seed"], params[1])
86
83
def test_starting_with(self):
92
89
'selftest --starting-with foo --starting-with bar')
93
90
self.assertEqual(['foo', 'bar'], params[1]['starting_with'])
95
def test_subunitv1(self):
96
self.requireFeature(features.subunit)
97
params = self.get_params_passed_to_core('selftest --subunit1')
98
self.assertEqual(tests.SubUnitBzrRunnerv1, params[1]['runner_class'])
100
def test_subunitv2(self):
101
self.requireFeature(features.subunit)
102
params = self.get_params_passed_to_core('selftest --subunit2')
103
self.assertEqual(tests.SubUnitBzrRunnerv2, params[1]['runner_class'])
92
def test_subunit(self):
93
self.requireFeature(features.subunit)
94
params = self.get_params_passed_to_core('selftest --subunit')
95
self.assertEqual(tests.SubUnitBzrRunner, params[1]['runner_class'])
105
97
def _parse_test_list(self, lines, newlines_in_header=0):
106
98
"Parse a list of lines into a tuple of 3 lists (header,body,footer)."
128
120
# If the last body line is blank, drop it off the list
129
121
if len(body) > 0 and body[-1] == '':
131
return (header, body, footer)
123
return (header,body,footer)
133
125
def test_list_only(self):
134
126
# check that brz selftest --list-only outputs no ui noise
135
127
def selftest(*args, **kwargs):
136
128
"""Capture the arguments selftest was run with."""
139
130
def outputs_nothing(cmdline):
140
out, err = self.run_bzr(cmdline)
141
(header, body, footer) = self._parse_test_list(out.splitlines())
131
out,err = self.run_bzr(cmdline)
132
(header,body,footer) = self._parse_test_list(out.splitlines())
142
133
num_tests = len(body)
143
134
self.assertLength(0, header)
144
135
self.assertLength(0, footer)
145
136
self.assertEqual('', err)
146
137
# Yes this prevents using threads to run the test suite in parallel,
147
# however we don't have a clean dependency injector for commands,
138
# however we don't have a clean dependency injector for commands,
148
139
# and even if we did - we'd still be testing that the glue is wired
149
140
# up correctly. XXX: TODO: Solve this testing problem.
150
141
original_selftest = tests.selftest
153
144
outputs_nothing('selftest --list-only')
154
145
outputs_nothing('selftest --list-only selftest')
156
['selftest', '--list-only', '--exclude', 'selftest'])
146
outputs_nothing(['selftest', '--list-only', '--exclude', 'selftest'])
158
148
tests.selftest = original_selftest
166
156
self.addCleanup(setattr, os, "fork", os.fork)
168
158
out, err = self.run_bzr(["selftest", "--parallel=fork", "-s", "bt.x"],
170
160
self.assertIn("platform does not support fork", err)
171
161
self.assertFalse(out)