/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/blackbox/test_selftest.py

  • Committer: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""UI tests for the test framework."""
18
18
 
19
 
from bzrlib import (
20
 
    benchmarks,
 
19
import os
 
20
 
 
21
from breezy import (
21
22
    tests,
22
23
    )
23
 
from bzrlib.tests import (
 
24
from breezy.tests import (
24
25
    features,
25
26
    )
26
 
from bzrlib.transport import memory
 
27
from breezy.transport import memory
 
28
 
27
29
 
28
30
class SelfTestPatch:
29
31
 
30
32
    def get_params_passed_to_core(self, cmdline):
31
33
        params = []
 
34
 
32
35
        def selftest(*args, **kwargs):
33
36
            """Capture the arguments selftest was run with."""
34
37
            params.append((args, kwargs))
35
38
            return True
36
39
        # Yes this prevents using threads to run the test suite in parallel,
37
 
        # however we don't have a clean dependency injector for commands, 
 
40
        # however we don't have a clean dependency injector for commands,
38
41
        # and even if we did - we'd still be testing that the glue is wired
39
42
        # up correctly. XXX: TODO: Solve this testing problem.
40
43
        original_selftest = tests.selftest
46
49
            tests.selftest = original_selftest
47
50
 
48
51
 
49
 
class TestOptionsWritingToDisk(tests.TestCaseInTempDir, SelfTestPatch):
50
 
 
51
 
    def test_benchmark_runs_benchmark_tests(self):
52
 
        """selftest --benchmark should change the suite factory."""
53
 
        params = self.get_params_passed_to_core('selftest --benchmark')
54
 
        self.assertEqual(benchmarks.test_suite,
55
 
            params[1]['test_suite_factory'])
56
 
        self.assertNotEqual(None, params[1]['bench_history'])
57
 
        benchfile = open(".perf_history", "rt")
58
 
        try:
59
 
            lines = benchfile.readlines()
60
 
        finally:
61
 
            benchfile.close()
62
 
        # Because we don't run the actual test code no output is made to the
63
 
        # file.
64
 
        self.assertEqual(0, len(lines))
65
 
 
66
 
 
67
52
class TestOptions(tests.TestCase, SelfTestPatch):
68
53
 
69
54
    def test_load_list(self):
74
59
        # Test that we can pass a transport to the selftest core - sftp
75
60
        # version.
76
61
        self.requireFeature(features.paramiko)
77
 
        from bzrlib.tests import stub_sftp
 
62
        from breezy.tests import stub_sftp
78
63
        params = self.get_params_passed_to_core('selftest --transport=sftp')
79
64
        self.assertEqual(stub_sftp.SFTPAbsoluteServer,
80
 
            params[1]["transport"])
 
65
                         params[1]["transport"])
81
66
 
82
67
    def test_transport_set_to_memory(self):
83
68
        # Test that we can pass a transport to the selftest core - memory
88
73
    def test_parameters_passed_to_core(self):
89
74
        params = self.get_params_passed_to_core('selftest --list-only')
90
75
        self.assertTrue("list_only" in params[1])
91
 
        params = self.get_params_passed_to_core('selftest --list-only selftest')
92
 
        self.assertTrue("list_only" in params[1])
93
 
        params = self.get_params_passed_to_core(['selftest', '--list-only',
94
 
            '--exclude', 'selftest'])
95
 
        self.assertTrue("list_only" in params[1])
96
 
        params = self.get_params_passed_to_core(['selftest', '--list-only',
97
 
            'selftest', '--randomize', 'now'])
 
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'])
98
84
        self.assertSubset(["list_only", "random_seed"], params[1])
99
85
 
100
86
    def test_starting_with(self):
106
92
            'selftest --starting-with foo --starting-with bar')
107
93
        self.assertEqual(['foo', 'bar'], params[1]['starting_with'])
108
94
 
109
 
    def test_subunit(self):
110
 
        self.requireFeature(features.subunit)
111
 
        params = self.get_params_passed_to_core('selftest --subunit')
112
 
        self.assertEqual(tests.SubUnitBzrRunner, params[1]['runner_class'])
 
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'])
 
99
 
 
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'])
113
104
 
114
105
    def _parse_test_list(self, lines, newlines_in_header=0):
115
106
        "Parse a list of lines into a tuple of 3 lists (header,body,footer)."
137
128
        # If the last body line is blank, drop it off the list
138
129
        if len(body) > 0 and body[-1] == '':
139
130
            body.pop()
140
 
        return (header,body,footer)
 
131
        return (header, body, footer)
141
132
 
142
133
    def test_list_only(self):
143
 
        # check that bzr selftest --list-only outputs no ui noise
 
134
        # check that brz selftest --list-only outputs no ui noise
144
135
        def selftest(*args, **kwargs):
145
136
            """Capture the arguments selftest was run with."""
146
137
            return True
 
138
 
147
139
        def outputs_nothing(cmdline):
148
 
            out,err = self.run_bzr(cmdline)
149
 
            (header,body,footer) = self._parse_test_list(out.splitlines())
 
140
            out, err = self.run_bzr(cmdline)
 
141
            (header, body, footer) = self._parse_test_list(out.splitlines())
150
142
            num_tests = len(body)
151
143
            self.assertLength(0, header)
152
144
            self.assertLength(0, footer)
153
145
            self.assertEqual('', err)
154
146
        # Yes this prevents using threads to run the test suite in parallel,
155
 
        # however we don't have a clean dependency injector for commands, 
 
147
        # however we don't have a clean dependency injector for commands,
156
148
        # and even if we did - we'd still be testing that the glue is wired
157
149
        # up correctly. XXX: TODO: Solve this testing problem.
158
150
        original_selftest = tests.selftest
160
152
        try:
161
153
            outputs_nothing('selftest --list-only')
162
154
            outputs_nothing('selftest --list-only selftest')
163
 
            outputs_nothing(['selftest', '--list-only', '--exclude', 'selftest'])
 
155
            outputs_nothing(
 
156
                ['selftest', '--list-only', '--exclude', 'selftest'])
164
157
        finally:
165
158
            tests.selftest = original_selftest
166
159
 
167
160
    def test_lsprof_tests(self):
168
161
        params = self.get_params_passed_to_core('selftest --lsprof-tests')
169
162
        self.assertEqual(True, params[1]["lsprof_tests"])
 
163
 
 
164
    def test_parallel_fork_unsupported(self):
 
165
        if getattr(os, "fork", None) is not None:
 
166
            self.addCleanup(setattr, os, "fork", os.fork)
 
167
            del os.fork
 
168
        out, err = self.run_bzr(["selftest", "--parallel=fork", "-s", "bt.x"],
 
169
                                retcode=3)
 
170
        self.assertIn("platform does not support fork", err)
 
171
        self.assertFalse(out)