/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 bzrlib/tests/blackbox/test_selftest.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

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