/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: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    )
27
27
from breezy.transport import memory
28
28
 
29
 
 
30
29
class SelfTestPatch:
31
30
 
32
31
    def get_params_passed_to_core(self, cmdline):
33
32
        params = []
34
 
 
35
33
        def selftest(*args, **kwargs):
36
34
            """Capture the arguments selftest was run with."""
37
35
            params.append((args, kwargs))
38
36
            return True
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"])
66
64
 
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])
85
82
 
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'])
94
91
 
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'])
 
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'])
104
96
 
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] == '':
130
122
            body.pop()
131
 
        return (header, body, footer)
 
123
        return (header,body,footer)
132
124
 
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."""
137
129
            return True
138
 
 
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
152
143
        try:
153
144
            outputs_nothing('selftest --list-only')
154
145
            outputs_nothing('selftest --list-only selftest')
155
 
            outputs_nothing(
156
 
                ['selftest', '--list-only', '--exclude', 'selftest'])
 
146
            outputs_nothing(['selftest', '--list-only', '--exclude', 'selftest'])
157
147
        finally:
158
148
            tests.selftest = original_selftest
159
149
 
166
156
            self.addCleanup(setattr, os, "fork", os.fork)
167
157
            del os.fork
168
158
        out, err = self.run_bzr(["selftest", "--parallel=fork", "-s", "bt.x"],
169
 
                                retcode=3)
 
159
            retcode=3)
170
160
        self.assertIn("platform does not support fork", err)
171
161
        self.assertFalse(out)