bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
1 |
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
|
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
|
2052.3.1
by John Arbash Meinel
Add tests to cleanup the copyright of all source files |
4 |
# it under the terms of the GNU General Public License as published by
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
7 |
#
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
|
1534.11.7
by Robert Collins
Test and correct the problem with nested test logs breaking further in-test logs. |
17 |
"""Tests for the test framework."""
|
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
18 |
|
|
2036.1.1
by John Arbash Meinel
test that logs are kept or deleted when appropriate |
19 |
import cStringIO |
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
20 |
import os |
|
1707.2.1
by Robert Collins
'bzr selftest --benchmark' will run a new benchmarking selftest. |
21 |
from StringIO import StringIO |
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
22 |
import sys |
|
1707.2.3
by Robert Collins
Add a setBenchmarkTime method to the bzrlib test result allowing introduction of granular benchmarking. (Robert Collins, Martin Pool). |
23 |
import time |
|
1185.33.95
by Martin Pool
New TestSkipped facility, and tests for it. |
24 |
import unittest |
|
1185.62.24
by John Arbash Meinel
Changing the exception that sftp.py throws when it can't find paramiko, so that the test suite can handle it. |
25 |
import warnings |
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
26 |
|
|
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. |
27 |
import bzrlib |
|
1986.4.9
by Robert Collins
``TestCase.make_branch_and_memory_tree`` now takes a format |
28 |
from bzrlib import ( |
29 |
bzrdir, |
|
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
30 |
errors, |
|
1986.4.9
by Robert Collins
``TestCase.make_branch_and_memory_tree`` now takes a format |
31 |
memorytree, |
32 |
osutils, |
|
33 |
repository, |
|
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
34 |
symbol_versioning, |
|
3193.1.1
by Vincent Ladeuil
Helper to filter test suite building by module when loading a list. |
35 |
tests, |
|
1986.4.9
by Robert Collins
``TestCase.make_branch_and_memory_tree`` now takes a format |
36 |
)
|
|
1534.11.1
by Robert Collins
Teach bzr selftest to use a progress bar in non verbose mode. |
37 |
from bzrlib.progress import _BaseProgressBar |
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
38 |
from bzrlib.repofmt import weaverepo |
|
2696.1.1
by Martin Pool
Remove things deprecated in 0.11 and earlier |
39 |
from bzrlib.symbol_versioning import ( |
|
3128.1.2
by Vincent Ladeuil
Tweak as per review feedback: s/randomise.*/randomize&/, 0.92 -> 1.0. |
40 |
one_zero, |
41 |
zero_eleven, |
|
42 |
zero_ten, |
|
43 |
)
|
|
|
1526.1.3
by Robert Collins
Merge from upstream. |
44 |
from bzrlib.tests import ( |
|
1534.4.31
by Robert Collins
cleanedup test_outside_wt |
45 |
ChrootedTestCase, |
|
2367.1.2
by Robert Collins
Some minor cleanups of test code, and implement KnownFailure support as |
46 |
ExtendedTestResult, |
|
2367.1.4
by Robert Collins
Add operating system Feature model to bzrlib.tests to allow writing tests |
47 |
Feature, |
|
2367.1.2
by Robert Collins
Some minor cleanups of test code, and implement KnownFailure support as |
48 |
KnownFailure, |
|
1526.1.3
by Robert Collins
Merge from upstream. |
49 |
TestCase, |
50 |
TestCaseInTempDir, |
|
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
51 |
TestCaseWithMemoryTransport, |
|
1534.4.10
by Robert Collins
Add TestCaseWithTransport class that provides tests with read and write transport pairs. |
52 |
TestCaseWithTransport, |
|
2729.1.1
by Martin Pool
Add TestNotApplicable exception and handling of it; document test parameterization |
53 |
TestNotApplicable, |
|
1526.1.3
by Robert Collins
Merge from upstream. |
54 |
TestSkipped, |
|
1707.2.1
by Robert Collins
'bzr selftest --benchmark' will run a new benchmarking selftest. |
55 |
TestSuite, |
|
2394.2.7
by Ian Clatworthy
Added whitebox tests - filter_suite_by_re and sort_suite_by_re |
56 |
TestUtil, |
|
1526.1.3
by Robert Collins
Merge from upstream. |
57 |
TextTestRunner, |
|
2367.1.6
by Robert Collins
Allow per-test-fixture feature requirements via 'requireFeature'.(Robert Collins) |
58 |
UnavailableFeature, |
|
2921.6.9
by Robert Collins
* New helper function ``bzrlib.tests.condition_id_re`` which helps |
59 |
condition_id_re, |
|
2921.6.8
by Robert Collins
* New helper function ``bzrlib.tests.condition_isinstance`` which helps |
60 |
condition_isinstance, |
|
2921.6.9
by Robert Collins
* New helper function ``bzrlib.tests.condition_id_re`` which helps |
61 |
exclude_tests_by_condition, |
|
2921.6.2
by Robert Collins
* New helper method ``bzrlib.tests.exclude_tests_by_re`` which gives a new |
62 |
exclude_tests_by_re, |
|
2921.6.7
by Robert Collins
* New helper function ``bzrlib.tests.filter_suite_by_condition`` which |
63 |
filter_suite_by_condition, |
|
2921.6.2
by Robert Collins
* New helper method ``bzrlib.tests.exclude_tests_by_re`` which gives a new |
64 |
filter_suite_by_re, |
|
2394.2.7
by Ian Clatworthy
Added whitebox tests - filter_suite_by_re and sort_suite_by_re |
65 |
iter_suite_tests, |
|
2921.6.6
by Robert Collins
* The ``exclude_pattern`` and ``random_order`` parameters to the function |
66 |
preserve_input, |
|
3128.1.2
by Vincent Ladeuil
Tweak as per review feedback: s/randomise.*/randomize&/, 0.92 -> 1.0. |
67 |
randomize_suite, |
|
2394.2.7
by Ian Clatworthy
Added whitebox tests - filter_suite_by_re and sort_suite_by_re |
68 |
sort_suite_by_re, |
|
2921.6.1
by Robert Collins
* New helper method ``bzrlib.tests.split_suite_by_re`` which splits a test |
69 |
split_suite_by_re, |
|
2493.2.8
by Aaron Bentley
Convert old lsprof tests to require new LSProf Feature instead of skipping |
70 |
test_lsprof, |
71 |
test_suite, |
|
|
1526.1.3
by Robert Collins
Merge from upstream. |
72 |
)
|
|
1910.14.1
by Andrew Bennetts
Fix to make_branch_and_tree's behavior when used with an sftp transport. |
73 |
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer |
|
1707.2.2
by Robert Collins
Start on bench_add, an add benchtest. |
74 |
from bzrlib.tests.TestUtil import _load_module_by_name |
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
75 |
from bzrlib.trace import note |
|
1910.13.1
by Andrew Bennetts
Make make_bzrdir preserve the transport. |
76 |
from bzrlib.transport.memory import MemoryServer, MemoryTransport |
|
1951.1.1
by Andrew Bennetts
Make test_bench_history and _get_bzr_source_tree tolerant of UnknownFormatError for the bzr workingtree. |
77 |
from bzrlib.version import _get_bzr_source_tree |
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
78 |
|
79 |
||
80 |
class SelftestTests(TestCase): |
|
81 |
||
82 |
def test_import_tests(self): |
|
83 |
mod = _load_module_by_name('bzrlib.tests.test_selftest') |
|
84 |
self.assertEqual(mod.SelftestTests, SelftestTests) |
|
85 |
||
86 |
def test_import_test_failure(self): |
|
87 |
self.assertRaises(ImportError, |
|
88 |
_load_module_by_name, |
|
89 |
'bzrlib.no-name-yet') |
|
90 |
||
91 |
class MetaTestLog(TestCase): |
|
|
1526.1.1
by Robert Collins
Run the test suite with no locale as well as the default locale. Also add a test for build_tree_shape to selftest. |
92 |
|
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
93 |
def test_logging(self): |
94 |
"""Test logs are captured when a test fails.""" |
|
95 |
self.log('a test message') |
|
96 |
self._log_file.flush() |
|
|
1927.3.1
by Carl Friedrich Bolz
Throw away on-disk logfile when possible. |
97 |
self.assertContainsRe(self._get_log(keep_log_file=True), |
98 |
'a test message\n') |
|
|
1185.33.95
by Martin Pool
New TestSkipped facility, and tests for it. |
99 |
|
100 |
||
|
1526.1.1
by Robert Collins
Run the test suite with no locale as well as the default locale. Also add a test for build_tree_shape to selftest. |
101 |
class TestTreeShape(TestCaseInTempDir): |
102 |
||
103 |
def test_unicode_paths(self): |
|
104 |
filename = u'hell\u00d8' |
|
|
1526.1.4
by Robert Collins
forgot my self. |
105 |
try: |
106 |
self.build_tree_contents([(filename, 'contents of hello')]) |
|
107 |
except UnicodeEncodeError: |
|
108 |
raise TestSkipped("can't build unicode working tree in " |
|
109 |
"filesystem encoding %s" % sys.getfilesystemencoding()) |
|
|
1526.1.1
by Robert Collins
Run the test suite with no locale as well as the default locale. Also add a test for build_tree_shape to selftest. |
110 |
self.failUnlessExists(filename) |
|
1526.1.3
by Robert Collins
Merge from upstream. |
111 |
|
112 |
||
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
113 |
class TestTransportProviderAdapter(TestCase): |
|
1530.1.21
by Robert Collins
Review feedback fixes. |
114 |
"""A group of tests that test the transport implementation adaption core. |
115 |
||
|
1551.1.1
by Martin Pool
[merge] branch-formats branch, and reconcile changes |
116 |
This is a meta test that the tests are applied to all available
|
117 |
transports.
|
|
118 |
||
|
1530.1.21
by Robert Collins
Review feedback fixes. |
119 |
This will be generalised in the future which is why it is in this
|
120 |
test file even though it is specific to transport tests at the moment.
|
|
121 |
"""
|
|
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
122 |
|
|
1530.1.11
by Robert Collins
Push the transport permutations list into each transport module allowing for automatic testing of new modules that are registered as transports. |
123 |
def test_get_transport_permutations(self): |
|
1530.1.21
by Robert Collins
Review feedback fixes. |
124 |
# this checks that we the module get_test_permutations call
|
125 |
# is made by the adapter get_transport_test_permitations method.
|
|
|
1530.1.11
by Robert Collins
Push the transport permutations list into each transport module allowing for automatic testing of new modules that are registered as transports. |
126 |
class MockModule(object): |
127 |
def get_test_permutations(self): |
|
128 |
return sample_permutation |
|
129 |
sample_permutation = [(1,2), (3,4)] |
|
|
2553.2.5
by Robert Collins
And overhaul TransportTestProviderAdapter too. |
130 |
from bzrlib.tests.test_transport_implementations \ |
131 |
import TransportTestProviderAdapter |
|
|
1530.1.11
by Robert Collins
Push the transport permutations list into each transport module allowing for automatic testing of new modules that are registered as transports. |
132 |
adapter = TransportTestProviderAdapter() |
133 |
self.assertEqual(sample_permutation, |
|
134 |
adapter.get_transport_test_permutations(MockModule())) |
|
135 |
||
136 |
def test_adapter_checks_all_modules(self): |
|
|
1530.1.21
by Robert Collins
Review feedback fixes. |
137 |
# this checks that the adapter returns as many permurtations as
|
138 |
# there are in all the registered# transport modules for there
|
|
139 |
# - we assume if this matches its probably doing the right thing
|
|
140 |
# especially in combination with the tests for setting the right
|
|
141 |
# classes below.
|
|
|
2553.2.5
by Robert Collins
And overhaul TransportTestProviderAdapter too. |
142 |
from bzrlib.tests.test_transport_implementations \ |
143 |
import TransportTestProviderAdapter |
|
144 |
from bzrlib.transport import _get_transport_modules |
|
|
1530.1.11
by Robert Collins
Push the transport permutations list into each transport module allowing for automatic testing of new modules that are registered as transports. |
145 |
modules = _get_transport_modules() |
146 |
permutation_count = 0 |
|
147 |
for module in modules: |
|
|
1185.62.24
by John Arbash Meinel
Changing the exception that sftp.py throws when it can't find paramiko, so that the test suite can handle it. |
148 |
try: |
149 |
permutation_count += len(reduce(getattr, |
|
150 |
(module + ".get_test_permutations").split('.')[1:], |
|
151 |
__import__(module))()) |
|
152 |
except errors.DependencyNotPresent: |
|
153 |
pass
|
|
|
1530.1.11
by Robert Collins
Push the transport permutations list into each transport module allowing for automatic testing of new modules that are registered as transports. |
154 |
input_test = TestTransportProviderAdapter( |
155 |
"test_adapter_sets_transport_class") |
|
156 |
adapter = TransportTestProviderAdapter() |
|
157 |
self.assertEqual(permutation_count, |
|
158 |
len(list(iter(adapter.adapt(input_test))))) |
|
159 |
||
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
160 |
def test_adapter_sets_transport_class(self): |
|
1540.3.21
by Martin Pool
Trim test for TestTransportProviderAdapter to be less dependent on |
161 |
# Check that the test adapter inserts a transport and server into the
|
162 |
# generated test.
|
|
163 |
#
|
|
164 |
# This test used to know about all the possible transports and the
|
|
165 |
# order they were returned but that seems overly brittle (mbp
|
|
166 |
# 20060307)
|
|
|
2553.2.5
by Robert Collins
And overhaul TransportTestProviderAdapter too. |
167 |
from bzrlib.tests.test_transport_implementations \ |
168 |
import TransportTestProviderAdapter |
|
169 |
scenarios = TransportTestProviderAdapter().scenarios |
|
|
1540.3.21
by Martin Pool
Trim test for TestTransportProviderAdapter to be less dependent on |
170 |
# there are at least that many builtin transports
|
|
2553.2.5
by Robert Collins
And overhaul TransportTestProviderAdapter too. |
171 |
self.assertTrue(len(scenarios) > 6) |
172 |
one_scenario = scenarios[0] |
|
173 |
self.assertIsInstance(one_scenario[0], str) |
|
174 |
self.assertTrue(issubclass(one_scenario[1]["transport_class"], |
|
|
1540.3.21
by Martin Pool
Trim test for TestTransportProviderAdapter to be less dependent on |
175 |
bzrlib.transport.Transport)) |
|
2553.2.5
by Robert Collins
And overhaul TransportTestProviderAdapter too. |
176 |
self.assertTrue(issubclass(one_scenario[1]["transport_server"], |
|
1540.3.21
by Martin Pool
Trim test for TestTransportProviderAdapter to be less dependent on |
177 |
bzrlib.transport.Server)) |
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
178 |
|
179 |
||
180 |
class TestBranchProviderAdapter(TestCase): |
|
181 |
"""A group of tests that test the branch implementation test adapter.""" |
|
182 |
||
|
2553.2.6
by Robert Collins
And overhaul BranchTestProviderAdapter too. |
183 |
def test_constructor(self): |
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
184 |
# check that constructor parameters are passed through to the adapted
|
185 |
# test.
|
|
|
2553.2.6
by Robert Collins
And overhaul BranchTestProviderAdapter too. |
186 |
from bzrlib.tests.branch_implementations import BranchTestProviderAdapter |
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
187 |
server1 = "a" |
188 |
server2 = "b" |
|
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
189 |
formats = [("c", "C"), ("d", "D")] |
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
190 |
adapter = BranchTestProviderAdapter(server1, server2, formats) |
|
2553.2.6
by Robert Collins
And overhaul BranchTestProviderAdapter too. |
191 |
self.assertEqual(2, len(adapter.scenarios)) |
192 |
self.assertEqual([ |
|
193 |
('str', |
|
194 |
{'branch_format': 'c', |
|
195 |
'bzrdir_format': 'C', |
|
196 |
'transport_readonly_server': 'b', |
|
197 |
'transport_server': 'a'}), |
|
198 |
('str', |
|
199 |
{'branch_format': 'd', |
|
200 |
'bzrdir_format': 'D', |
|
201 |
'transport_readonly_server': 'b', |
|
202 |
'transport_server': 'a'})], |
|
203 |
adapter.scenarios) |
|
|
1534.4.10
by Robert Collins
Add TestCaseWithTransport class that provides tests with read and write transport pairs. |
204 |
|
205 |
||
|
1534.4.39
by Robert Collins
Basic BzrDir support. |
206 |
class TestBzrDirProviderAdapter(TestCase): |
207 |
"""A group of tests that test the bzr dir implementation test adapter.""" |
|
208 |
||
209 |
def test_adapted_tests(self): |
|
210 |
# check that constructor parameters are passed through to the adapted
|
|
211 |
# test.
|
|
|
2553.2.7
by Robert Collins
And overhaul BzrDirTestProviderAdapter too. |
212 |
from bzrlib.tests.bzrdir_implementations import BzrDirTestProviderAdapter |
|
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
213 |
vfs_factory = "v" |
|
1534.4.39
by Robert Collins
Basic BzrDir support. |
214 |
server1 = "a" |
215 |
server2 = "b" |
|
216 |
formats = ["c", "d"] |
|
|
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
217 |
adapter = BzrDirTestProviderAdapter(vfs_factory, |
218 |
server1, server2, formats) |
|
|
2553.2.7
by Robert Collins
And overhaul BzrDirTestProviderAdapter too. |
219 |
self.assertEqual([ |
220 |
('str', |
|
221 |
{'bzrdir_format': 'c', |
|
222 |
'transport_readonly_server': 'b', |
|
223 |
'transport_server': 'a', |
|
224 |
'vfs_transport_factory': 'v'}), |
|
225 |
('str', |
|
226 |
{'bzrdir_format': 'd', |
|
227 |
'transport_readonly_server': 'b', |
|
228 |
'transport_server': 'a', |
|
229 |
'vfs_transport_factory': 'v'})], |
|
230 |
adapter.scenarios) |
|
|
1534.4.39
by Robert Collins
Basic BzrDir support. |
231 |
|
232 |
||
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
233 |
class TestRepositoryProviderAdapter(TestCase): |
234 |
"""A group of tests that test the repository implementation test adapter.""" |
|
235 |
||
|
2553.2.1
by Robert Collins
Overhaul RepositoryTestAdapter to be cleaner and more modular. |
236 |
def test_constructor(self): |
237 |
# check that constructor parameters are passed through to the
|
|
238 |
# scenarios.
|
|
|
2553.2.2
by Robert Collins
Move RepositoryTestProviderAdapter into the tests part of the code base. |
239 |
from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter |
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
240 |
server1 = "a" |
241 |
server2 = "b" |
|
242 |
formats = [("c", "C"), ("d", "D")] |
|
243 |
adapter = RepositoryTestProviderAdapter(server1, server2, formats) |
|
|
2553.2.1
by Robert Collins
Overhaul RepositoryTestAdapter to be cleaner and more modular. |
244 |
self.assertEqual([ |
245 |
('str', |
|
246 |
{'bzrdir_format': 'C', |
|
247 |
'repository_format': 'c', |
|
248 |
'transport_readonly_server': 'b', |
|
249 |
'transport_server': 'a'}), |
|
250 |
('str', |
|
251 |
{'bzrdir_format': 'D', |
|
252 |
'repository_format': 'd', |
|
253 |
'transport_readonly_server': 'b', |
|
254 |
'transport_server': 'a'})], |
|
255 |
adapter.scenarios) |
|
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
256 |
|
|
2018.5.64
by Robert Collins
Allow Repository tests to be backed onto a specific VFS as needed. |
257 |
def test_setting_vfs_transport(self): |
258 |
"""The vfs_transport_factory can be set optionally.""" |
|
|
2553.2.2
by Robert Collins
Move RepositoryTestProviderAdapter into the tests part of the code base. |
259 |
from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter |
|
2553.2.1
by Robert Collins
Overhaul RepositoryTestAdapter to be cleaner and more modular. |
260 |
formats = [("a", "b"), ("c", "d")] |
|
2018.5.64
by Robert Collins
Allow Repository tests to be backed onto a specific VFS as needed. |
261 |
adapter = RepositoryTestProviderAdapter(None, None, formats, |
262 |
vfs_transport_factory="vfs") |
|
|
2553.2.1
by Robert Collins
Overhaul RepositoryTestAdapter to be cleaner and more modular. |
263 |
self.assertEqual([ |
264 |
('str', |
|
265 |
{'bzrdir_format': 'b', |
|
266 |
'repository_format': 'a', |
|
267 |
'transport_readonly_server': None, |
|
268 |
'transport_server': None, |
|
269 |
'vfs_transport_factory': 'vfs'}), |
|
270 |
('str', |
|
271 |
{'bzrdir_format': 'd', |
|
272 |
'repository_format': 'c', |
|
273 |
'transport_readonly_server': None, |
|
274 |
'transport_server': None, |
|
275 |
'vfs_transport_factory': 'vfs'})], |
|
276 |
adapter.scenarios) |
|
277 |
||
278 |
def test_formats_to_scenarios(self): |
|
279 |
"""The adapter can generate all the scenarios needed.""" |
|
|
2553.2.2
by Robert Collins
Move RepositoryTestProviderAdapter into the tests part of the code base. |
280 |
from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter |
|
2553.2.1
by Robert Collins
Overhaul RepositoryTestAdapter to be cleaner and more modular. |
281 |
no_vfs_adapter = RepositoryTestProviderAdapter("server", "readonly", |
282 |
[], None) |
|
283 |
vfs_adapter = RepositoryTestProviderAdapter("server", "readonly", |
|
284 |
[], vfs_transport_factory="vfs") |
|
285 |
# no_vfs generate scenarios without vfs_transport_factor
|
|
286 |
formats = [("c", "C"), (1, "D")] |
|
287 |
self.assertEqual([ |
|
288 |
('str', |
|
289 |
{'bzrdir_format': 'C', |
|
290 |
'repository_format': 'c', |
|
291 |
'transport_readonly_server': 'readonly', |
|
292 |
'transport_server': 'server'}), |
|
293 |
('int', |
|
294 |
{'bzrdir_format': 'D', |
|
295 |
'repository_format': 1, |
|
296 |
'transport_readonly_server': 'readonly', |
|
297 |
'transport_server': 'server'})], |
|
298 |
no_vfs_adapter.formats_to_scenarios(formats)) |
|
299 |
self.assertEqual([ |
|
300 |
('str', |
|
301 |
{'bzrdir_format': 'C', |
|
302 |
'repository_format': 'c', |
|
303 |
'transport_readonly_server': 'readonly', |
|
304 |
'transport_server': 'server', |
|
305 |
'vfs_transport_factory': 'vfs'}), |
|
306 |
('int', |
|
307 |
{'bzrdir_format': 'D', |
|
308 |
'repository_format': 1, |
|
309 |
'transport_readonly_server': 'readonly', |
|
310 |
'transport_server': 'server', |
|
311 |
'vfs_transport_factory': 'vfs'})], |
|
312 |
vfs_adapter.formats_to_scenarios(formats)) |
|
313 |
||
|
2553.2.3
by Robert Collins
Split out the common test scenario support from the repository implementation specific code. |
314 |
|
315 |
class TestTestScenarioApplier(TestCase): |
|
316 |
"""Tests for the test adaption facilities.""" |
|
317 |
||
318 |
def test_adapt_applies_scenarios(self): |
|
319 |
from bzrlib.tests.repository_implementations import TestScenarioApplier |
|
320 |
input_test = TestTestScenarioApplier("test_adapt_test_to_scenario") |
|
321 |
adapter = TestScenarioApplier() |
|
322 |
adapter.scenarios = [("1", "dict"), ("2", "settings")] |
|
323 |
calls = [] |
|
324 |
def capture_call(test, scenario): |
|
325 |
calls.append((test, scenario)) |
|
326 |
return test |
|
327 |
adapter.adapt_test_to_scenario = capture_call |
|
328 |
adapter.adapt(input_test) |
|
329 |
self.assertEqual([(input_test, ("1", "dict")), |
|
330 |
(input_test, ("2", "settings"))], calls) |
|
331 |
||
|
2553.2.1
by Robert Collins
Overhaul RepositoryTestAdapter to be cleaner and more modular. |
332 |
def test_adapt_test_to_scenario(self): |
|
2553.2.3
by Robert Collins
Split out the common test scenario support from the repository implementation specific code. |
333 |
from bzrlib.tests.repository_implementations import TestScenarioApplier |
334 |
input_test = TestTestScenarioApplier("test_adapt_test_to_scenario") |
|
335 |
adapter = TestScenarioApplier() |
|
|
2553.2.1
by Robert Collins
Overhaul RepositoryTestAdapter to be cleaner and more modular. |
336 |
# setup two adapted tests
|
337 |
adapted_test1 = adapter.adapt_test_to_scenario(input_test, |
|
338 |
("new id", |
|
339 |
{"bzrdir_format":"bzr_format", |
|
340 |
"repository_format":"repo_fmt", |
|
341 |
"transport_server":"transport_server", |
|
342 |
"transport_readonly_server":"readonly-server"})) |
|
343 |
adapted_test2 = adapter.adapt_test_to_scenario(input_test, |
|
344 |
("new id 2", {"bzrdir_format":None})) |
|
345 |
# input_test should have been altered.
|
|
346 |
self.assertRaises(AttributeError, getattr, input_test, "bzrdir_format") |
|
347 |
# the new tests are mutually incompatible, ensuring it has
|
|
348 |
# made new ones, and unspecified elements in the scenario
|
|
349 |
# should not have been altered.
|
|
350 |
self.assertEqual("bzr_format", adapted_test1.bzrdir_format) |
|
351 |
self.assertEqual("repo_fmt", adapted_test1.repository_format) |
|
352 |
self.assertEqual("transport_server", adapted_test1.transport_server) |
|
353 |
self.assertEqual("readonly-server", |
|
354 |
adapted_test1.transport_readonly_server) |
|
355 |
self.assertEqual( |
|
|
2553.2.3
by Robert Collins
Split out the common test scenario support from the repository implementation specific code. |
356 |
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
|
|
2553.2.1
by Robert Collins
Overhaul RepositoryTestAdapter to be cleaner and more modular. |
357 |
"test_adapt_test_to_scenario(new id)", |
358 |
adapted_test1.id()) |
|
359 |
self.assertEqual(None, adapted_test2.bzrdir_format) |
|
360 |
self.assertEqual( |
|
|
2553.2.3
by Robert Collins
Split out the common test scenario support from the repository implementation specific code. |
361 |
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
|
|
2553.2.1
by Robert Collins
Overhaul RepositoryTestAdapter to be cleaner and more modular. |
362 |
"test_adapt_test_to_scenario(new id 2)", |
363 |
adapted_test2.id()) |
|
|
2018.5.64
by Robert Collins
Allow Repository tests to be backed onto a specific VFS as needed. |
364 |
|
|
1534.4.40
by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used. |
365 |
|
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
366 |
class TestInterRepositoryProviderAdapter(TestCase): |
367 |
"""A group of tests that test the InterRepository test adapter.""" |
|
368 |
||
369 |
def test_adapted_tests(self): |
|
370 |
# check that constructor parameters are passed through to the adapted
|
|
371 |
# test.
|
|
|
2553.2.4
by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter |
372 |
from bzrlib.tests.interrepository_implementations import \ |
373 |
InterRepositoryTestProviderAdapter
|
|
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
374 |
server1 = "a" |
375 |
server2 = "b" |
|
|
1563.2.20
by Robert Collins
Add a revision store test adapter. |
376 |
formats = [(str, "C1", "C2"), (int, "D1", "D2")] |
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
377 |
adapter = InterRepositoryTestProviderAdapter(server1, server2, formats) |
|
2553.2.4
by Robert Collins
Treat InterRepositoryTestProviderAdapter like RepositoryTestProviderAdapter |
378 |
self.assertEqual([ |
379 |
('str', |
|
380 |
{'interrepo_class': str, |
|
381 |
'repository_format': 'C1', |
|
382 |
'repository_format_to': 'C2', |
|
383 |
'transport_readonly_server': 'b', |
|
384 |
'transport_server': 'a'}), |
|
385 |
('int', |
|
386 |
{'interrepo_class': int, |
|
387 |
'repository_format': 'D1', |
|
388 |
'repository_format_to': 'D2', |
|
389 |
'transport_readonly_server': 'b', |
|
390 |
'transport_server': 'a'})], |
|
391 |
adapter.formats_to_scenarios(formats)) |
|
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
392 |
|
393 |
||
|
1563.2.12
by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile. |
394 |
class TestInterVersionedFileProviderAdapter(TestCase): |
395 |
"""A group of tests that test the InterVersionedFile test adapter.""" |
|
396 |
||
|
2553.2.9
by Robert Collins
And overhaul RevisionStoreTestProviderAdapter too. |
397 |
def test_scenarios(self): |
|
1563.2.12
by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile. |
398 |
# check that constructor parameters are passed through to the adapted
|
399 |
# test.
|
|
|
2553.2.8
by Robert Collins
And overhaul InterVersionedFileTestProviderAdapter too. |
400 |
from bzrlib.tests.interversionedfile_implementations \ |
401 |
import InterVersionedFileTestProviderAdapter |
|
|
1563.2.12
by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile. |
402 |
server1 = "a" |
403 |
server2 = "b" |
|
|
1563.2.20
by Robert Collins
Add a revision store test adapter. |
404 |
formats = [(str, "C1", "C2"), (int, "D1", "D2")] |
|
1563.2.12
by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile. |
405 |
adapter = InterVersionedFileTestProviderAdapter(server1, server2, formats) |
|
2553.2.8
by Robert Collins
And overhaul InterVersionedFileTestProviderAdapter too. |
406 |
self.assertEqual([ |
407 |
('str', |
|
408 |
{'interversionedfile_class':str, |
|
409 |
'transport_readonly_server': 'b', |
|
410 |
'transport_server': 'a', |
|
411 |
'versionedfile_factory': 'C1', |
|
412 |
'versionedfile_factory_to': 'C2'}), |
|
413 |
('int', |
|
414 |
{'interversionedfile_class': int, |
|
415 |
'transport_readonly_server': 'b', |
|
416 |
'transport_server': 'a', |
|
417 |
'versionedfile_factory': 'D1', |
|
418 |
'versionedfile_factory_to': 'D2'})], |
|
419 |
adapter.scenarios) |
|
|
1563.2.12
by Robert Collins
Checkpointing: created InterObject to factor out common inter object worker code, added InterVersionedFile and tests to allow making join work between any versionedfile. |
420 |
|
421 |
||
|
1563.2.20
by Robert Collins
Add a revision store test adapter. |
422 |
class TestRevisionStoreProviderAdapter(TestCase): |
423 |
"""A group of tests that test the RevisionStore test adapter.""" |
|
424 |
||
|
2553.2.9
by Robert Collins
And overhaul RevisionStoreTestProviderAdapter too. |
425 |
def test_scenarios(self): |
|
1563.2.20
by Robert Collins
Add a revision store test adapter. |
426 |
# check that constructor parameters are passed through to the adapted
|
427 |
# test.
|
|
|
2553.2.9
by Robert Collins
And overhaul RevisionStoreTestProviderAdapter too. |
428 |
from bzrlib.tests.revisionstore_implementations \ |
429 |
import RevisionStoreTestProviderAdapter |
|
|
1563.2.20
by Robert Collins
Add a revision store test adapter. |
430 |
# revision stores need a store factory - i.e. RevisionKnit
|
431 |
#, a readonly and rw transport
|
|
432 |
# transport servers:
|
|
433 |
server1 = "a" |
|
434 |
server2 = "b" |
|
435 |
store_factories = ["c", "d"] |
|
436 |
adapter = RevisionStoreTestProviderAdapter(server1, server2, store_factories) |
|
|
2553.2.9
by Robert Collins
And overhaul RevisionStoreTestProviderAdapter too. |
437 |
self.assertEqual([ |
438 |
('c', |
|
439 |
{'store_factory': 'c', |
|
440 |
'transport_readonly_server': 'b', |
|
441 |
'transport_server': 'a'}), |
|
442 |
('d', |
|
443 |
{'store_factory': 'd', |
|
444 |
'transport_readonly_server': 'b', |
|
445 |
'transport_server': 'a'})], |
|
446 |
adapter.scenarios) |
|
|
1563.2.20
by Robert Collins
Add a revision store test adapter. |
447 |
|
448 |
||
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
449 |
class TestWorkingTreeProviderAdapter(TestCase): |
450 |
"""A group of tests that test the workingtree implementation test adapter.""" |
|
451 |
||
|
2553.2.10
by Robert Collins
And overhaul WorkingTreeTestProviderAdapter too. |
452 |
def test_scenarios(self): |
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
453 |
# check that constructor parameters are passed through to the adapted
|
454 |
# test.
|
|
|
2553.2.10
by Robert Collins
And overhaul WorkingTreeTestProviderAdapter too. |
455 |
from bzrlib.tests.workingtree_implementations \ |
456 |
import WorkingTreeTestProviderAdapter |
|
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
457 |
server1 = "a" |
458 |
server2 = "b" |
|
459 |
formats = [("c", "C"), ("d", "D")] |
|
460 |
adapter = WorkingTreeTestProviderAdapter(server1, server2, formats) |
|
|
2553.2.10
by Robert Collins
And overhaul WorkingTreeTestProviderAdapter too. |
461 |
self.assertEqual([ |
462 |
('str', |
|
463 |
{'bzrdir_format': 'C', |
|
464 |
'transport_readonly_server': 'b', |
|
465 |
'transport_server': 'a', |
|
466 |
'workingtree_format': 'c'}), |
|
467 |
('str', |
|
468 |
{'bzrdir_format': 'D', |
|
469 |
'transport_readonly_server': 'b', |
|
470 |
'transport_server': 'a', |
|
471 |
'workingtree_format': 'd'})], |
|
472 |
adapter.scenarios) |
|
|
1534.4.46
by Robert Collins
Nearly complete .bzr/checkout splitout. |
473 |
|
474 |
||
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
475 |
class TestTreeProviderAdapter(TestCase): |
476 |
"""Test the setup of tree_implementation tests.""" |
|
477 |
||
478 |
def test_adapted_tests(self): |
|
479 |
# the tree implementation adapter is meant to setup one instance for
|
|
480 |
# each working tree format, and one additional instance that will
|
|
481 |
# use the default wt format, but create a revision tree for the tests.
|
|
482 |
# this means that the wt ones should have the workingtree_to_test_tree
|
|
483 |
# attribute set to 'return_parameter' and the revision one set to
|
|
484 |
# revision_tree_from_workingtree.
|
|
485 |
||
486 |
from bzrlib.tests.tree_implementations import ( |
|
487 |
TreeTestProviderAdapter, |
|
488 |
return_parameter, |
|
489 |
revision_tree_from_workingtree
|
|
490 |
)
|
|
|
2255.2.164
by Martin Pool
Change the default format for some tests from AB1 back to WorkingTreeFormat3 |
491 |
from bzrlib.workingtree import WorkingTreeFormat, WorkingTreeFormat3 |
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
492 |
input_test = TestTreeProviderAdapter( |
493 |
"test_adapted_tests") |
|
494 |
server1 = "a" |
|
495 |
server2 = "b" |
|
496 |
formats = [("c", "C"), ("d", "D")] |
|
497 |
adapter = TreeTestProviderAdapter(server1, server2, formats) |
|
498 |
suite = adapter.adapt(input_test) |
|
499 |
tests = list(iter(suite)) |
|
|
2255.6.3
by Aaron Bentley
tweak tests |
500 |
self.assertEqual(4, len(tests)) |
|
2255.2.164
by Martin Pool
Change the default format for some tests from AB1 back to WorkingTreeFormat3 |
501 |
# this must match the default format setp up in
|
502 |
# TreeTestProviderAdapter.adapt
|
|
503 |
default_format = WorkingTreeFormat3 |
|
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
504 |
self.assertEqual(tests[0].workingtree_format, formats[0][0]) |
505 |
self.assertEqual(tests[0].bzrdir_format, formats[0][1]) |
|
506 |
self.assertEqual(tests[0].transport_server, server1) |
|
507 |
self.assertEqual(tests[0].transport_readonly_server, server2) |
|
508 |
self.assertEqual(tests[0].workingtree_to_test_tree, return_parameter) |
|
509 |
self.assertEqual(tests[1].workingtree_format, formats[1][0]) |
|
510 |
self.assertEqual(tests[1].bzrdir_format, formats[1][1]) |
|
511 |
self.assertEqual(tests[1].transport_server, server1) |
|
512 |
self.assertEqual(tests[1].transport_readonly_server, server2) |
|
513 |
self.assertEqual(tests[1].workingtree_to_test_tree, return_parameter) |
|
|
2100.3.20
by Aaron Bentley
Implement tree comparison for tree references |
514 |
self.assertIsInstance(tests[2].workingtree_format, default_format) |
515 |
#self.assertEqual(tests[2].bzrdir_format,
|
|
516 |
# default_format._matchingbzrdir)
|
|
|
1852.6.1
by Robert Collins
Start tree implementation tests. |
517 |
self.assertEqual(tests[2].transport_server, server1) |
518 |
self.assertEqual(tests[2].transport_readonly_server, server2) |
|
519 |
self.assertEqual(tests[2].workingtree_to_test_tree, |
|
520 |
revision_tree_from_workingtree) |
|
521 |
||
522 |
||
|
1852.8.3
by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case. |
523 |
class TestInterTreeProviderAdapter(TestCase): |
524 |
"""A group of tests that test the InterTreeTestAdapter.""" |
|
525 |
||
526 |
def test_adapted_tests(self): |
|
527 |
# check that constructor parameters are passed through to the adapted
|
|
528 |
# test.
|
|
529 |
# for InterTree tests we want the machinery to bring up two trees in
|
|
530 |
# each instance: the base one, and the one we are interacting with.
|
|
531 |
# because each optimiser can be direction specific, we need to test
|
|
532 |
# each optimiser in its chosen direction.
|
|
533 |
# unlike the TestProviderAdapter we dont want to automatically add a
|
|
|
3128.1.3
by Vincent Ladeuil
Since we are there s/parameteris.*/parameteriz&/. |
534 |
# parameterized one for WorkingTree - the optimisers will tell us what
|
|
1852.8.3
by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case. |
535 |
# ones to add.
|
536 |
from bzrlib.tests.tree_implementations import ( |
|
537 |
return_parameter, |
|
538 |
revision_tree_from_workingtree
|
|
539 |
)
|
|
540 |
from bzrlib.tests.intertree_implementations import ( |
|
541 |
InterTreeTestProviderAdapter, |
|
542 |
)
|
|
543 |
from bzrlib.workingtree import WorkingTreeFormat2, WorkingTreeFormat3 |
|
544 |
input_test = TestInterTreeProviderAdapter( |
|
545 |
"test_adapted_tests") |
|
546 |
server1 = "a" |
|
547 |
server2 = "b" |
|
548 |
format1 = WorkingTreeFormat2() |
|
549 |
format2 = WorkingTreeFormat3() |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
550 |
formats = [(str, format1, format2, "converter1"), |
551 |
(int, format2, format1, "converter2")] |
|
|
1852.8.3
by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case. |
552 |
adapter = InterTreeTestProviderAdapter(server1, server2, formats) |
553 |
suite = adapter.adapt(input_test) |
|
554 |
tests = list(iter(suite)) |
|
555 |
self.assertEqual(2, len(tests)) |
|
556 |
self.assertEqual(tests[0].intertree_class, formats[0][0]) |
|
557 |
self.assertEqual(tests[0].workingtree_format, formats[0][1]) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
558 |
self.assertEqual(tests[0].workingtree_format_to, formats[0][2]) |
559 |
self.assertEqual(tests[0].mutable_trees_to_test_trees, formats[0][3]) |
|
560 |
self.assertEqual(tests[0].workingtree_to_test_tree, return_parameter) |
|
|
1852.8.3
by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case. |
561 |
self.assertEqual(tests[0].transport_server, server1) |
562 |
self.assertEqual(tests[0].transport_readonly_server, server2) |
|
563 |
self.assertEqual(tests[1].intertree_class, formats[1][0]) |
|
564 |
self.assertEqual(tests[1].workingtree_format, formats[1][1]) |
|
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
565 |
self.assertEqual(tests[1].workingtree_format_to, formats[1][2]) |
566 |
self.assertEqual(tests[1].mutable_trees_to_test_trees, formats[1][3]) |
|
567 |
self.assertEqual(tests[1].workingtree_to_test_tree, return_parameter) |
|
|
1852.8.3
by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case. |
568 |
self.assertEqual(tests[1].transport_server, server1) |
569 |
self.assertEqual(tests[1].transport_readonly_server, server2) |
|
570 |
||
|
1987.1.1
by John Arbash Meinel
Update the test suite to put HOME in a different directory |
571 |
|
572 |
class TestTestCaseInTempDir(TestCaseInTempDir): |
|
573 |
||
574 |
def test_home_is_not_working(self): |
|
575 |
self.assertNotEqual(self.test_dir, self.test_home_dir) |
|
576 |
cwd = osutils.getcwd() |
|
|
2823.1.4
by Vincent Ladeuil
Use assertIsSameRealPath to avoid OSX aliasing (specifically /tmp |
577 |
self.assertIsSameRealPath(self.test_dir, cwd) |
578 |
self.assertIsSameRealPath(self.test_home_dir, os.environ['HOME']) |
|
|
1987.1.1
by John Arbash Meinel
Update the test suite to put HOME in a different directory |
579 |
|
580 |
||
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
581 |
class TestTestCaseWithMemoryTransport(TestCaseWithMemoryTransport): |
582 |
||
583 |
def test_home_is_non_existant_dir_under_root(self): |
|
584 |
"""The test_home_dir for TestCaseWithMemoryTransport is missing. |
|
585 |
||
586 |
This is because TestCaseWithMemoryTransport is for tests that do not
|
|
587 |
need any disk resources: they should be hooked into bzrlib in such a
|
|
588 |
way that no global settings are being changed by the test (only a
|
|
589 |
few tests should need to do that), and having a missing dir as home is
|
|
590 |
an effective way to ensure that this is the case.
|
|
591 |
"""
|
|
|
2823.1.4
by Vincent Ladeuil
Use assertIsSameRealPath to avoid OSX aliasing (specifically /tmp |
592 |
self.assertIsSameRealPath( |
593 |
self.TEST_ROOT + "/MemoryTransportMissingHomeDir", |
|
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
594 |
self.test_home_dir) |
|
2823.1.4
by Vincent Ladeuil
Use assertIsSameRealPath to avoid OSX aliasing (specifically /tmp |
595 |
self.assertIsSameRealPath(self.test_home_dir, os.environ['HOME']) |
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
596 |
|
597 |
def test_cwd_is_TEST_ROOT(self): |
|
|
2823.1.4
by Vincent Ladeuil
Use assertIsSameRealPath to avoid OSX aliasing (specifically /tmp |
598 |
self.assertIsSameRealPath(self.test_dir, self.TEST_ROOT) |
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
599 |
cwd = osutils.getcwd() |
|
2823.1.4
by Vincent Ladeuil
Use assertIsSameRealPath to avoid OSX aliasing (specifically /tmp |
600 |
self.assertIsSameRealPath(self.test_dir, cwd) |
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
601 |
|
602 |
def test_make_branch_and_memory_tree(self): |
|
603 |
"""In TestCaseWithMemoryTransport we should not make the branch on disk. |
|
604 |
||
605 |
This is hard to comprehensively robustly test, so we settle for making
|
|
606 |
a branch and checking no directory was created at its relpath.
|
|
607 |
"""
|
|
608 |
tree = self.make_branch_and_memory_tree('dir') |
|
|
2227.2.2
by v.ladeuil+lp at free
Cleanup. |
609 |
# Guard against regression into MemoryTransport leaking
|
610 |
# files to disk instead of keeping them in memory.
|
|
611 |
self.failIf(osutils.lexists('dir')) |
|
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
612 |
self.assertIsInstance(tree, memorytree.MemoryTree) |
613 |
||
|
1986.4.9
by Robert Collins
``TestCase.make_branch_and_memory_tree`` now takes a format |
614 |
def test_make_branch_and_memory_tree_with_format(self): |
615 |
"""make_branch_and_memory_tree should accept a format option.""" |
|
616 |
format = bzrdir.BzrDirMetaFormat1() |
|
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
617 |
format.repository_format = weaverepo.RepositoryFormat7() |
|
1986.4.9
by Robert Collins
``TestCase.make_branch_and_memory_tree`` now takes a format |
618 |
tree = self.make_branch_and_memory_tree('dir', format=format) |
|
2227.2.2
by v.ladeuil+lp at free
Cleanup. |
619 |
# Guard against regression into MemoryTransport leaking
|
620 |
# files to disk instead of keeping them in memory.
|
|
621 |
self.failIf(osutils.lexists('dir')) |
|
|
1986.4.9
by Robert Collins
``TestCase.make_branch_and_memory_tree`` now takes a format |
622 |
self.assertIsInstance(tree, memorytree.MemoryTree) |
623 |
self.assertEqual(format.repository_format.__class__, |
|
624 |
tree.branch.repository._format.__class__) |
|
625 |
||
|
2875.1.1
by Vincent Ladeuil
Fix #147986 by monitoring a safety .bzr directory. |
626 |
def test_safety_net(self): |
627 |
"""No test should modify the safety .bzr directory. |
|
628 |
||
629 |
We just test that the _check_safety_net private method raises
|
|
|
2875.1.2
by Vincent Ladeuil
Update NEWS, fix typo. |
630 |
AssertionError, it's easier than building a test suite with the same
|
|
2875.1.1
by Vincent Ladeuil
Fix #147986 by monitoring a safety .bzr directory. |
631 |
test.
|
632 |
"""
|
|
633 |
# Oops, a commit in the current directory (i.e. without local .bzr
|
|
634 |
# directory) will crawl up the hierarchy to find a .bzr directory.
|
|
635 |
self.run_bzr(['commit', '-mfoo', '--unchanged']) |
|
636 |
# But we have a safety net in place.
|
|
637 |
self.assertRaises(AssertionError, self._check_safety_net) |
|
638 |
||
|
1986.2.3
by Robert Collins
New test base class TestCaseWithMemoryTransport offers memory-only |
639 |
|
|
1534.4.10
by Robert Collins
Add TestCaseWithTransport class that provides tests with read and write transport pairs. |
640 |
class TestTestCaseWithTransport(TestCaseWithTransport): |
641 |
"""Tests for the convenience functions TestCaseWithTransport introduces.""" |
|
642 |
||
643 |
def test_get_readonly_url_none(self): |
|
644 |
from bzrlib.transport import get_transport |
|
645 |
from bzrlib.transport.memory import MemoryServer |
|
646 |
from bzrlib.transport.readonly import ReadonlyTransportDecorator |
|
|
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
647 |
self.vfs_transport_factory = MemoryServer |
|
1534.4.10
by Robert Collins
Add TestCaseWithTransport class that provides tests with read and write transport pairs. |
648 |
self.transport_readonly_server = None |
649 |
# calling get_readonly_transport() constructs a decorator on the url
|
|
650 |
# for the server
|
|
651 |
url = self.get_readonly_url() |
|
|
1534.4.11
by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test. |
652 |
url2 = self.get_readonly_url('foo/bar') |
|
1534.4.10
by Robert Collins
Add TestCaseWithTransport class that provides tests with read and write transport pairs. |
653 |
t = get_transport(url) |
|
1534.4.11
by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test. |
654 |
t2 = get_transport(url2) |
|
1534.4.10
by Robert Collins
Add TestCaseWithTransport class that provides tests with read and write transport pairs. |
655 |
self.failUnless(isinstance(t, ReadonlyTransportDecorator)) |
|
1534.4.11
by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test. |
656 |
self.failUnless(isinstance(t2, ReadonlyTransportDecorator)) |
657 |
self.assertEqual(t2.base[:-1], t.abspath('foo/bar')) |
|
|
1534.4.10
by Robert Collins
Add TestCaseWithTransport class that provides tests with read and write transport pairs. |
658 |
|
659 |
def test_get_readonly_url_http(self): |
|
|
3102.1.1
by Vincent Ladeuil
Rename bzrlib/test/HTTPTestUtils.py to bzrlib/tests/http_utils.py and fix |
660 |
from bzrlib.tests.http_server import HttpServer |
|
1534.4.10
by Robert Collins
Add TestCaseWithTransport class that provides tests with read and write transport pairs. |
661 |
from bzrlib.transport import get_transport |
|
1951.2.1
by Martin Pool
Change to using LocalURLServer for testing. |
662 |
from bzrlib.transport.local import LocalURLServer |
|
2004.1.25
by v.ladeuil+lp at free
Shuffle http related test code. Hopefully it ends up at the right place :) |
663 |
from bzrlib.transport.http import HttpTransportBase |
|
1951.2.1
by Martin Pool
Change to using LocalURLServer for testing. |
664 |
self.transport_server = LocalURLServer |
|
1534.4.10
by Robert Collins
Add TestCaseWithTransport class that provides tests with read and write transport pairs. |
665 |
self.transport_readonly_server = HttpServer |
666 |
# calling get_readonly_transport() gives us a HTTP server instance.
|
|
667 |
url = self.get_readonly_url() |
|
|
1534.4.11
by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test. |
668 |
url2 = self.get_readonly_url('foo/bar') |
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
669 |
# the transport returned may be any HttpTransportBase subclass
|
|
1534.4.10
by Robert Collins
Add TestCaseWithTransport class that provides tests with read and write transport pairs. |
670 |
t = get_transport(url) |
|
1534.4.11
by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test. |
671 |
t2 = get_transport(url2) |
|
1540.3.6
by Martin Pool
[merge] update from bzr.dev |
672 |
self.failUnless(isinstance(t, HttpTransportBase)) |
673 |
self.failUnless(isinstance(t2, HttpTransportBase)) |
|
|
1534.4.11
by Robert Collins
Convert test_open_containing from being a Remote test to being the more accurate Chrooted test. |
674 |
self.assertEqual(t2.base[:-1], t.abspath('foo/bar')) |
|
1534.4.31
by Robert Collins
cleanedup test_outside_wt |
675 |
|
|
1553.5.68
by Martin Pool
Add new TestCaseWithTransport.assertIsDirectory() and tests |
676 |
def test_is_directory(self): |
677 |
"""Test assertIsDirectory assertion""" |
|
678 |
t = self.get_transport() |
|
679 |
self.build_tree(['a_dir/', 'a_file'], transport=t) |
|
680 |
self.assertIsDirectory('a_dir', t) |
|
681 |
self.assertRaises(AssertionError, self.assertIsDirectory, 'a_file', t) |
|
682 |
self.assertRaises(AssertionError, self.assertIsDirectory, 'not_here', t) |
|
|
1534.4.31
by Robert Collins
cleanedup test_outside_wt |
683 |
|
|
1666.1.4
by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in |
684 |
|
|
1910.13.1
by Andrew Bennetts
Make make_bzrdir preserve the transport. |
685 |
class TestTestCaseTransports(TestCaseWithTransport): |
686 |
||
687 |
def setUp(self): |
|
688 |
super(TestTestCaseTransports, self).setUp() |
|
|
2018.5.42
by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :). |
689 |
self.vfs_transport_factory = MemoryServer |
|
1910.13.1
by Andrew Bennetts
Make make_bzrdir preserve the transport. |
690 |
|
691 |
def test_make_bzrdir_preserves_transport(self): |
|
692 |
t = self.get_transport() |
|
693 |
result_bzrdir = self.make_bzrdir('subdir') |
|
694 |
self.assertIsInstance(result_bzrdir.transport, |
|
695 |
MemoryTransport) |
|
696 |
# should not be on disk, should only be in memory
|
|
697 |
self.failIfExists('subdir') |
|
698 |
||
699 |
||
|
1534.4.31
by Robert Collins
cleanedup test_outside_wt |
700 |
class TestChrootedTest(ChrootedTestCase): |
701 |
||
702 |
def test_root_is_root(self): |
|
703 |
from bzrlib.transport import get_transport |
|
704 |
t = get_transport(self.get_readonly_url()) |
|
705 |
url = t.base |
|
706 |
self.assertEqual(url, t.clone('..').base) |
|
|
1540.3.22
by Martin Pool
[patch] Add TestCase.assertIsInstance |
707 |
|
708 |
||
|
1534.11.1
by Robert Collins
Teach bzr selftest to use a progress bar in non verbose mode. |
709 |
class MockProgress(_BaseProgressBar): |
710 |
"""Progress-bar standin that records calls. |
|
711 |
||
712 |
Useful for testing pb using code.
|
|
713 |
"""
|
|
714 |
||
715 |
def __init__(self): |
|
716 |
_BaseProgressBar.__init__(self) |
|
717 |
self.calls = [] |
|
718 |
||
719 |
def tick(self): |
|
720 |
self.calls.append(('tick',)) |
|
721 |
||
722 |
def update(self, msg=None, current=None, total=None): |
|
723 |
self.calls.append(('update', msg, current, total)) |
|
724 |
||
725 |
def clear(self): |
|
726 |
self.calls.append(('clear',)) |
|
727 |
||
|
1864.3.1
by John Arbash Meinel
Print out when a test fails in non verbose mode, run transport tests later |
728 |
def note(self, msg, *args): |
729 |
self.calls.append(('note', msg, args)) |
|
730 |
||
|
1534.11.1
by Robert Collins
Teach bzr selftest to use a progress bar in non verbose mode. |
731 |
|
|
1725.1.1
by Robert Collins
'bzr selftest --benchmark --lsprof-timed' will use lsprofile to generate |
732 |
class TestTestResult(TestCase): |
|
1534.11.1
by Robert Collins
Teach bzr selftest to use a progress bar in non verbose mode. |
733 |
|
|
2695.1.3
by Martin Pool
Fix up selftest tests for new extractBenchmarkTime behaviour; remove many unneeded calls to it |
734 |
def check_timing(self, test_case, expected_re): |
|
2095.4.1
by Martin Pool
Better progress bars during tests |
735 |
result = bzrlib.tests.TextTestResult(self._log_file, |
|
2695.1.3
by Martin Pool
Fix up selftest tests for new extractBenchmarkTime behaviour; remove many unneeded calls to it |
736 |
descriptions=0, |
737 |
verbosity=1, |
|
738 |
)
|
|
739 |
test_case.run(result) |
|
740 |
timed_string = result._testTimeString(test_case) |
|
741 |
self.assertContainsRe(timed_string, expected_re) |
|
742 |
||
743 |
def test_test_reporting(self): |
|
744 |
class ShortDelayTestCase(TestCase): |
|
745 |
def test_short_delay(self): |
|
746 |
time.sleep(0.003) |
|
747 |
def test_short_benchmark(self): |
|
748 |
self.time(time.sleep, 0.003) |
|
749 |
self.check_timing(ShortDelayTestCase('test_short_delay'), |
|
750 |
r"^ +[0-9]+ms$") |
|
|
1707.2.3
by Robert Collins
Add a setBenchmarkTime method to the bzrlib test result allowing introduction of granular benchmarking. (Robert Collins, Martin Pool). |
751 |
# if a benchmark time is given, we want a x of y style result.
|
|
2695.1.3
by Martin Pool
Fix up selftest tests for new extractBenchmarkTime behaviour; remove many unneeded calls to it |
752 |
self.check_timing(ShortDelayTestCase('test_short_benchmark'), |
753 |
r"^ +[0-9]+ms/ +[0-9]+ms$") |
|
|
1707.2.3
by Robert Collins
Add a setBenchmarkTime method to the bzrlib test result allowing introduction of granular benchmarking. (Robert Collins, Martin Pool). |
754 |
|
|
2695.1.3
by Martin Pool
Fix up selftest tests for new extractBenchmarkTime behaviour; remove many unneeded calls to it |
755 |
def test_unittest_reporting_unittest_class(self): |
756 |
# getting the time from a non-bzrlib test works ok
|
|
757 |
class ShortDelayTestCase(unittest.TestCase): |
|
758 |
def test_short_delay(self): |
|
759 |
time.sleep(0.003) |
|
760 |
self.check_timing(ShortDelayTestCase('test_short_delay'), |
|
761 |
r"^ +[0-9]+ms$") |
|
762 |
||
|
1819.1.1
by Carl Friedrich Bolz
(lifeless, cfbolz, hpk): Give the test result object an optional benchmark |
763 |
def test_assigned_benchmark_file_stores_date(self): |
764 |
output = StringIO() |
|
|
2095.4.1
by Martin Pool
Better progress bars during tests |
765 |
result = bzrlib.tests.TextTestResult(self._log_file, |
|
1819.1.1
by Carl Friedrich Bolz
(lifeless, cfbolz, hpk): Give the test result object an optional benchmark |
766 |
descriptions=0, |
767 |
verbosity=1, |
|
768 |
bench_history=output |
|
769 |
)
|
|
770 |
output_string = output.getvalue() |
|
|
1819.1.4
by Jan Balster
save the revison id for every benchmark run in .perf-history |
771 |
# if you are wondering about the regexp please read the comment in
|
772 |
# test_bench_history (bzrlib.tests.test_selftest.TestRunner)
|
|
|
1951.1.2
by Andrew Bennetts
Relax test_assigned_benchmark_file_stores_date's regexp the same way we relaxed test_bench_history's. |
773 |
# XXX: what comment? -- Andrew Bennetts
|
774 |
self.assertContainsRe(output_string, "--date [0-9.]+") |
|
|
1819.1.3
by Carl Friedrich Bolz
(lifeless, cfbolz): Add recording of benchmark results to the benchmark history |
775 |
|
776 |
def test_benchhistory_records_test_times(self): |
|
777 |
result_stream = StringIO() |
|
|
2095.4.1
by Martin Pool
Better progress bars during tests |
778 |
result = bzrlib.tests.TextTestResult( |
|
1819.1.3
by Carl Friedrich Bolz
(lifeless, cfbolz): Add recording of benchmark results to the benchmark history |
779 |
self._log_file, |
780 |
descriptions=0, |
|
781 |
verbosity=1, |
|
782 |
bench_history=result_stream |
|
783 |
)
|
|
784 |
||
785 |
# we want profile a call and check that its test duration is recorded
|
|
786 |
# make a new test instance that when run will generate a benchmark
|
|
787 |
example_test_case = TestTestResult("_time_hello_world_encoding") |
|
788 |
# execute the test, which should succeed and record times
|
|
789 |
example_test_case.run(result) |
|
790 |
lines = result_stream.getvalue().splitlines() |
|
791 |
self.assertEqual(2, len(lines)) |
|
792 |
self.assertContainsRe(lines[1], |
|
793 |
" *[0-9]+ms bzrlib.tests.test_selftest.TestTestResult"
|
|
794 |
"._time_hello_world_encoding") |
|
795 |
||
|
1725.1.1
by Robert Collins
'bzr selftest --benchmark --lsprof-timed' will use lsprofile to generate |
796 |
def _time_hello_world_encoding(self): |
797 |
"""Profile two sleep calls |
|
798 |
|
|
799 |
This is used to exercise the test framework.
|
|
800 |
"""
|
|
801 |
self.time(unicode, 'hello', errors='replace') |
|
802 |
self.time(unicode, 'world', errors='replace') |
|
803 |
||
804 |
def test_lsprofiling(self): |
|
805 |
"""Verbose test result prints lsprof statistics from test cases.""" |
|
|
1551.15.28
by Aaron Bentley
Improve Feature usage style w/ lsprof |
806 |
self.requireFeature(test_lsprof.LSProfFeature) |
|
1725.1.1
by Robert Collins
'bzr selftest --benchmark --lsprof-timed' will use lsprofile to generate |
807 |
result_stream = StringIO() |
|
2095.4.1
by Martin Pool
Better progress bars during tests |
808 |
result = bzrlib.tests.VerboseTestResult( |
|
1725.1.1
by Robert Collins
'bzr selftest --benchmark --lsprof-timed' will use lsprofile to generate |
809 |
unittest._WritelnDecorator(result_stream), |
810 |
descriptions=0, |
|
811 |
verbosity=2, |
|
812 |
)
|
|
813 |
# we want profile a call of some sort and check it is output by
|
|
814 |
# addSuccess. We dont care about addError or addFailure as they
|
|
815 |
# are not that interesting for performance tuning.
|
|
816 |
# make a new test instance that when run will generate a profile
|
|
817 |
example_test_case = TestTestResult("_time_hello_world_encoding") |
|
818 |
example_test_case._gather_lsprof_in_benchmarks = True |
|
819 |
# execute the test, which should succeed and record profiles
|
|
820 |
example_test_case.run(result) |
|
821 |
# lsprofile_something()
|
|
822 |
# if this worked we want
|
|
823 |
# LSProf output for <built in function unicode> (['hello'], {'errors': 'replace'})
|
|
824 |
# CallCount Recursive Total(ms) Inline(ms) module:lineno(function)
|
|
825 |
# (the lsprof header)
|
|
826 |
# ... an arbitrary number of lines
|
|
827 |
# and the function call which is time.sleep.
|
|
828 |
# 1 0 ??? ??? ???(sleep)
|
|
829 |
# and then repeated but with 'world', rather than 'hello'.
|
|
830 |
# this should appear in the output stream of our test result.
|
|
|
1831.2.1
by Martin Pool
[trivial] Simplify & fix up lsprof blackbox test |
831 |
output = result_stream.getvalue() |
832 |
self.assertContainsRe(output, |
|
833 |
r"LSProf output for <type 'unicode'>\(\('hello',\), {'errors': 'replace'}\)") |
|
834 |
self.assertContainsRe(output, |
|
835 |
r" *CallCount *Recursive *Total\(ms\) *Inline\(ms\) *module:lineno\(function\)\n") |
|
836 |
self.assertContainsRe(output, |
|
837 |
r"( +1 +0 +0\.\d+ +0\.\d+ +<method 'disable' of '_lsprof\.Profiler' objects>\n)?") |
|
838 |
self.assertContainsRe(output, |
|
839 |
r"LSProf output for <type 'unicode'>\(\('world',\), {'errors': 'replace'}\)\n") |
|
|
1725.1.1
by Robert Collins
'bzr selftest --benchmark --lsprof-timed' will use lsprofile to generate |
840 |
|
|
2367.1.2
by Robert Collins
Some minor cleanups of test code, and implement KnownFailure support as |
841 |
def test_known_failure(self): |
842 |
"""A KnownFailure being raised should trigger several result actions.""" |
|
843 |
class InstrumentedTestResult(ExtendedTestResult): |
|
844 |
||
845 |
def report_test_start(self, test): pass |
|
846 |
def report_known_failure(self, test, err): |
|
847 |
self._call = test, err |
|
848 |
result = InstrumentedTestResult(None, None, None, None) |
|
849 |
def test_function(): |
|
850 |
raise KnownFailure('failed!') |
|
851 |
test = unittest.FunctionTestCase(test_function) |
|
852 |
test.run(result) |
|
853 |
# it should invoke 'report_known_failure'.
|
|
854 |
self.assertEqual(2, len(result._call)) |
|
855 |
self.assertEqual(test, result._call[0]) |
|
856 |
self.assertEqual(KnownFailure, result._call[1][0]) |
|
857 |
self.assertIsInstance(result._call[1][1], KnownFailure) |
|
858 |
# we dont introspec the traceback, if the rest is ok, it would be
|
|
859 |
# exceptional for it not to be.
|
|
860 |
# it should update the known_failure_count on the object.
|
|
861 |
self.assertEqual(1, result.known_failure_count) |
|
862 |
# the result should be successful.
|
|
863 |
self.assertTrue(result.wasSuccessful()) |
|
864 |
||
865 |
def test_verbose_report_known_failure(self): |
|
866 |
# verbose test output formatting
|
|
867 |
result_stream = StringIO() |
|
868 |
result = bzrlib.tests.VerboseTestResult( |
|
869 |
unittest._WritelnDecorator(result_stream), |
|
870 |
descriptions=0, |
|
871 |
verbosity=2, |
|
872 |
)
|
|
873 |
test = self.get_passing_test() |
|
874 |
result.startTest(test) |
|
875 |
prefix = len(result_stream.getvalue()) |
|
876 |
# the err parameter has the shape:
|
|
877 |
# (class, exception object, traceback)
|
|
878 |
# KnownFailures dont get their tracebacks shown though, so we
|
|
879 |
# can skip that.
|
|
880 |
err = (KnownFailure, KnownFailure('foo'), None) |
|
881 |
result.report_known_failure(test, err) |
|
882 |
output = result_stream.getvalue()[prefix:] |
|
883 |
lines = output.splitlines() |
|
|
2418.3.1
by John Arbash Meinel
Remove timing dependencies from the selftest tests. |
884 |
self.assertContainsRe(lines[0], r'XFAIL *\d+ms$') |
885 |
self.assertEqual(lines[1], ' foo') |
|
886 |
self.assertEqual(2, len(lines)) |
|
887 |
||
|
2367.1.2
by Robert Collins
Some minor cleanups of test code, and implement KnownFailure support as |
888 |
def test_text_report_known_failure(self): |
889 |
# text test output formatting
|
|
890 |
pb = MockProgress() |
|
891 |
result = bzrlib.tests.TextTestResult( |
|
892 |
None, |
|
893 |
descriptions=0, |
|
894 |
verbosity=1, |
|
895 |
pb=pb, |
|
896 |
)
|
|
897 |
test = self.get_passing_test() |
|
898 |
# this seeds the state to handle reporting the test.
|
|
899 |
result.startTest(test) |
|
900 |
# the err parameter has the shape:
|
|
901 |
# (class, exception object, traceback)
|
|
902 |
# KnownFailures dont get their tracebacks shown though, so we
|
|
903 |
# can skip that.
|
|
904 |
err = (KnownFailure, KnownFailure('foo'), None) |
|
905 |
result.report_known_failure(test, err) |
|
906 |
self.assertEqual( |
|
907 |
[
|
|
908 |
('update', '[1 in 0s] passing_test', None, None), |
|
909 |
('note', 'XFAIL: %s\n%s\n', ('passing_test', err[1])) |
|
910 |
],
|
|
911 |
pb.calls) |
|
912 |
# known_failures should be printed in the summary, so if we run a test
|
|
913 |
# after there are some known failures, the update prefix should match
|
|
914 |
# this.
|
|
915 |
result.known_failure_count = 3 |
|
916 |
test.run(result) |
|
917 |
self.assertEqual( |
|
918 |
[
|
|
919 |
('update', '[2 in 0s, 3 known failures] passing_test', None, None), |
|
920 |
],
|
|
921 |
pb.calls[2:]) |
|
922 |
||
923 |
def get_passing_test(self): |
|
924 |
"""Return a test object that can't be run usefully.""" |
|
925 |
def passing_test(): |
|
926 |
pass
|
|
927 |
return unittest.FunctionTestCase(passing_test) |
|
928 |
||
|
2367.1.5
by Robert Collins
Implement reporting of Unsupported tests in the bzr test result and runner |
929 |
def test_add_not_supported(self): |
930 |
"""Test the behaviour of invoking addNotSupported.""" |
|
931 |
class InstrumentedTestResult(ExtendedTestResult): |
|
932 |
def report_test_start(self, test): pass |
|
933 |
def report_unsupported(self, test, feature): |
|
934 |
self._call = test, feature |
|
935 |
result = InstrumentedTestResult(None, None, None, None) |
|
936 |
test = SampleTestCase('_test_pass') |
|
937 |
feature = Feature() |
|
938 |
result.startTest(test) |
|
939 |
result.addNotSupported(test, feature) |
|
940 |
# it should invoke 'report_unsupported'.
|
|
941 |
self.assertEqual(2, len(result._call)) |
|
942 |
self.assertEqual(test, result._call[0]) |
|
943 |
self.assertEqual(feature, result._call[1]) |
|
944 |
# the result should be successful.
|
|
945 |
self.assertTrue(result.wasSuccessful()) |
|
946 |
# it should record the test against a count of tests not run due to
|
|
947 |
# this feature.
|
|
948 |
self.assertEqual(1, result.unsupported['Feature']) |
|
949 |
# and invoking it again should increment that counter
|
|
950 |
result.addNotSupported(test, feature) |
|
951 |
self.assertEqual(2, result.unsupported['Feature']) |
|
952 |
||
953 |
def test_verbose_report_unsupported(self): |
|
954 |
# verbose test output formatting
|
|
955 |
result_stream = StringIO() |
|
956 |
result = bzrlib.tests.VerboseTestResult( |
|
957 |
unittest._WritelnDecorator(result_stream), |
|
958 |
descriptions=0, |
|
959 |
verbosity=2, |
|
960 |
)
|
|
961 |
test = self.get_passing_test() |
|
962 |
feature = Feature() |
|
963 |
result.startTest(test) |
|
964 |
prefix = len(result_stream.getvalue()) |
|
965 |
result.report_unsupported(test, feature) |
|
966 |
output = result_stream.getvalue()[prefix:] |
|
967 |
lines = output.splitlines() |
|
968 |
self.assertEqual(lines, ['NODEP 0ms', " The feature 'Feature' is not available."]) |
|
969 |
||
970 |
def test_text_report_unsupported(self): |
|
971 |
# text test output formatting
|
|
972 |
pb = MockProgress() |
|
973 |
result = bzrlib.tests.TextTestResult( |
|
974 |
None, |
|
975 |
descriptions=0, |
|
976 |
verbosity=1, |
|
977 |
pb=pb, |
|
978 |
)
|
|
979 |
test = self.get_passing_test() |
|
980 |
feature = Feature() |
|
981 |
# this seeds the state to handle reporting the test.
|
|
982 |
result.startTest(test) |
|
983 |
result.report_unsupported(test, feature) |
|
984 |
# no output on unsupported features
|
|
985 |
self.assertEqual( |
|
986 |
[('update', '[1 in 0s] passing_test', None, None) |
|
987 |
],
|
|
988 |
pb.calls) |
|
989 |
# the number of missing features should be printed in the progress
|
|
990 |
# summary, so check for that.
|
|
991 |
result.unsupported = {'foo':0, 'bar':0} |
|
992 |
test.run(result) |
|
993 |
self.assertEqual( |
|
994 |
[
|
|
995 |
('update', '[2 in 0s, 2 missing features] passing_test', None, None), |
|
996 |
],
|
|
997 |
pb.calls[1:]) |
|
998 |
||
|
2367.1.6
by Robert Collins
Allow per-test-fixture feature requirements via 'requireFeature'.(Robert Collins) |
999 |
def test_unavailable_exception(self): |
1000 |
"""An UnavailableFeature being raised should invoke addNotSupported.""" |
|
1001 |
class InstrumentedTestResult(ExtendedTestResult): |
|
1002 |
||
1003 |
def report_test_start(self, test): pass |
|
1004 |
def addNotSupported(self, test, feature): |
|
1005 |
self._call = test, feature |
|
1006 |
result = InstrumentedTestResult(None, None, None, None) |
|
1007 |
feature = Feature() |
|
1008 |
def test_function(): |
|
1009 |
raise UnavailableFeature(feature) |
|
1010 |
test = unittest.FunctionTestCase(test_function) |
|
1011 |
test.run(result) |
|
1012 |
# it should invoke 'addNotSupported'.
|
|
1013 |
self.assertEqual(2, len(result._call)) |
|
1014 |
self.assertEqual(test, result._call[0]) |
|
1015 |
self.assertEqual(feature, result._call[1]) |
|
1016 |
# and not count as an error
|
|
1017 |
self.assertEqual(0, result.error_count) |
|
1018 |
||
|
2658.3.2
by Daniel Watkins
Added tests for ExtendedTestResult.wasStrictlySuccessful. |
1019 |
def test_strict_with_unsupported_feature(self): |
1020 |
result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0, |
|
|
2695.1.3
by Martin Pool
Fix up selftest tests for new extractBenchmarkTime behaviour; remove many unneeded calls to it |
1021 |
verbosity=1) |
|
2658.3.2
by Daniel Watkins
Added tests for ExtendedTestResult.wasStrictlySuccessful. |
1022 |
test = self.get_passing_test() |
1023 |
feature = "Unsupported Feature" |
|
1024 |
result.addNotSupported(test, feature) |
|
1025 |
self.assertFalse(result.wasStrictlySuccessful()) |
|
|
2695.1.3
by Martin Pool
Fix up selftest tests for new extractBenchmarkTime behaviour; remove many unneeded calls to it |
1026 |
self.assertEqual(None, result._extractBenchmarkTime(test)) |
1027 |
||
|
2658.3.2
by Daniel Watkins
Added tests for ExtendedTestResult.wasStrictlySuccessful. |
1028 |
def test_strict_with_known_failure(self): |
1029 |
result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0, |
|
|
2695.1.3
by Martin Pool
Fix up selftest tests for new extractBenchmarkTime behaviour; remove many unneeded calls to it |
1030 |
verbosity=1) |
|
2658.3.2
by Daniel Watkins
Added tests for ExtendedTestResult.wasStrictlySuccessful. |
1031 |
test = self.get_passing_test() |
1032 |
err = (KnownFailure, KnownFailure('foo'), None) |
|
|
2695.1.1
by Martin Pool
Fix problem if the first test is missing a dependency |
1033 |
result._addKnownFailure(test, err) |
|
2658.3.2
by Daniel Watkins
Added tests for ExtendedTestResult.wasStrictlySuccessful. |
1034 |
self.assertFalse(result.wasStrictlySuccessful()) |
|
2695.1.3
by Martin Pool
Fix up selftest tests for new extractBenchmarkTime behaviour; remove many unneeded calls to it |
1035 |
self.assertEqual(None, result._extractBenchmarkTime(test)) |
|
2658.3.2
by Daniel Watkins
Added tests for ExtendedTestResult.wasStrictlySuccessful. |
1036 |
|
1037 |
def test_strict_with_success(self): |
|
1038 |
result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0, |
|
|
2695.1.3
by Martin Pool
Fix up selftest tests for new extractBenchmarkTime behaviour; remove many unneeded calls to it |
1039 |
verbosity=1) |
|
2658.3.2
by Daniel Watkins
Added tests for ExtendedTestResult.wasStrictlySuccessful. |
1040 |
test = self.get_passing_test() |
1041 |
result.addSuccess(test) |
|
1042 |
self.assertTrue(result.wasStrictlySuccessful()) |
|
|
2695.1.3
by Martin Pool
Fix up selftest tests for new extractBenchmarkTime behaviour; remove many unneeded calls to it |
1043 |
self.assertEqual(None, result._extractBenchmarkTime(test)) |
|
2658.3.2
by Daniel Watkins
Added tests for ExtendedTestResult.wasStrictlySuccessful. |
1044 |
|
|
1534.11.1
by Robert Collins
Teach bzr selftest to use a progress bar in non verbose mode. |
1045 |
|
1046 |
class TestRunner(TestCase): |
|
1047 |
||
1048 |
def dummy_test(self): |
|
1049 |
pass
|
|
1050 |
||
|
1534.11.7
by Robert Collins
Test and correct the problem with nested test logs breaking further in-test logs. |
1051 |
def run_test_runner(self, testrunner, test): |
1052 |
"""Run suite in testrunner, saving global state and restoring it. |
|
1053 |
||
1054 |
This current saves and restores:
|
|
1055 |
TestCaseInTempDir.TEST_ROOT
|
|
1056 |
|
|
1057 |
There should be no tests in this file that use bzrlib.tests.TextTestRunner
|
|
1058 |
without using this convenience method, because of our use of global state.
|
|
1059 |
"""
|
|
1060 |
old_root = TestCaseInTempDir.TEST_ROOT |
|
1061 |
try: |
|
1062 |
TestCaseInTempDir.TEST_ROOT = None |
|
1063 |
return testrunner.run(test) |
|
1064 |
finally: |
|
1065 |
TestCaseInTempDir.TEST_ROOT = old_root |
|
1066 |
||
|
2367.1.2
by Robert Collins
Some minor cleanups of test code, and implement KnownFailure support as |
1067 |
def test_known_failure_failed_run(self): |
1068 |
# run a test that generates a known failure which should be printed in
|
|
1069 |
# the final output when real failures occur.
|
|
1070 |
def known_failure_test(): |
|
1071 |
raise KnownFailure('failed') |
|
1072 |
test = unittest.TestSuite() |
|
1073 |
test.addTest(unittest.FunctionTestCase(known_failure_test)) |
|
1074 |
def failing_test(): |
|
1075 |
raise AssertionError('foo') |
|
1076 |
test.addTest(unittest.FunctionTestCase(failing_test)) |
|
1077 |
stream = StringIO() |
|
1078 |
runner = TextTestRunner(stream=stream) |
|
1079 |
result = self.run_test_runner(runner, test) |
|
1080 |
lines = stream.getvalue().splitlines() |
|
1081 |
self.assertEqual([ |
|
1082 |
'', |
|
1083 |
'======================================================================', |
|
1084 |
'FAIL: unittest.FunctionTestCase (failing_test)', |
|
1085 |
'----------------------------------------------------------------------', |
|
1086 |
'Traceback (most recent call last):', |
|
1087 |
' raise AssertionError(\'foo\')', |
|
1088 |
'AssertionError: foo', |
|
1089 |
'', |
|
1090 |
'----------------------------------------------------------------------', |
|
1091 |
'', |
|
1092 |
'FAILED (failures=1, known_failure_count=1)'], |
|
|
2367.1.5
by Robert Collins
Implement reporting of Unsupported tests in the bzr test result and runner |
1093 |
lines[0:5] + lines[6:10] + lines[11:]) |
|
2367.1.2
by Robert Collins
Some minor cleanups of test code, and implement KnownFailure support as |
1094 |
|
1095 |
def test_known_failure_ok_run(self): |
|
1096 |
# run a test that generates a known failure which should be printed in the final output.
|
|
1097 |
def known_failure_test(): |
|
1098 |
raise KnownFailure('failed') |
|
1099 |
test = unittest.FunctionTestCase(known_failure_test) |
|
1100 |
stream = StringIO() |
|
1101 |
runner = TextTestRunner(stream=stream) |
|
1102 |
result = self.run_test_runner(runner, test) |
|
|
2418.3.1
by John Arbash Meinel
Remove timing dependencies from the selftest tests. |
1103 |
self.assertContainsRe(stream.getvalue(), |
1104 |
'\n' |
|
1105 |
'-*\n' |
|
1106 |
'Ran 1 test in .*\n' |
|
1107 |
'\n' |
|
1108 |
'OK \\(known_failures=1\\)\n') |
|
|
2367.1.2
by Robert Collins
Some minor cleanups of test code, and implement KnownFailure support as |
1109 |
|
|
1534.11.7
by Robert Collins
Test and correct the problem with nested test logs breaking further in-test logs. |
1110 |
def test_skipped_test(self): |
1111 |
# run a test that is skipped, and check the suite as a whole still
|
|
1112 |
# succeeds.
|
|
1113 |
# skipping_test must be hidden in here so it's not run as a real test
|
|
1114 |
def skipping_test(): |
|
1115 |
raise TestSkipped('test intentionally skipped') |
|
|
2338.4.8
by Marien Zwart
Fix a bug in selftest causing tearDown to run twice for skipped tests. |
1116 |
|
|
2485.6.5
by Martin Pool
Remove keep_output option |
1117 |
runner = TextTestRunner(stream=self._log_file) |
|
2338.4.10
by Marien Zwart
Make a test skipped from setUp run tearDown again. Make calling _runCleanups twice safe. Clean up tests. |
1118 |
test = unittest.FunctionTestCase(skipping_test) |
1119 |
result = self.run_test_runner(runner, test) |
|
1120 |
self.assertTrue(result.wasSuccessful()) |
|
1121 |
||
1122 |
def test_skipped_from_setup(self): |
|
|
3224.4.1
by Andrew Bennetts
Prune __dict__ of TestCases after they have run to save memory. |
1123 |
calls = [] |
|
2338.4.10
by Marien Zwart
Make a test skipped from setUp run tearDown again. Make calling _runCleanups twice safe. Clean up tests. |
1124 |
class SkippedSetupTest(TestCase): |
|
2338.4.8
by Marien Zwart
Fix a bug in selftest causing tearDown to run twice for skipped tests. |
1125 |
|
1126 |
def setUp(self): |
|
|
3224.4.1
by Andrew Bennetts
Prune __dict__ of TestCases after they have run to save memory. |
1127 |
calls.append('setUp') |
|
2338.4.10
by Marien Zwart
Make a test skipped from setUp run tearDown again. Make calling _runCleanups twice safe. Clean up tests. |
1128 |
self.addCleanup(self.cleanup) |
|
2338.4.8
by Marien Zwart
Fix a bug in selftest causing tearDown to run twice for skipped tests. |
1129 |
raise TestSkipped('skipped setup') |
1130 |
||
1131 |
def test_skip(self): |
|
1132 |
self.fail('test reached') |
|
1133 |
||
|
2338.4.10
by Marien Zwart
Make a test skipped from setUp run tearDown again. Make calling _runCleanups twice safe. Clean up tests. |
1134 |
def cleanup(self): |
|
3224.4.1
by Andrew Bennetts
Prune __dict__ of TestCases after they have run to save memory. |
1135 |
calls.append('cleanup') |
|
2338.4.10
by Marien Zwart
Make a test skipped from setUp run tearDown again. Make calling _runCleanups twice safe. Clean up tests. |
1136 |
|
|
2485.6.5
by Martin Pool
Remove keep_output option |
1137 |
runner = TextTestRunner(stream=self._log_file) |
|
2338.4.10
by Marien Zwart
Make a test skipped from setUp run tearDown again. Make calling _runCleanups twice safe. Clean up tests. |
1138 |
test = SkippedSetupTest('test_skip') |
1139 |
result = self.run_test_runner(runner, test) |
|
1140 |
self.assertTrue(result.wasSuccessful()) |
|
1141 |
# Check if cleanup was called the right number of times.
|
|
|
3224.4.1
by Andrew Bennetts
Prune __dict__ of TestCases after they have run to save memory. |
1142 |
self.assertEqual(['setUp', 'cleanup'], calls) |
|
2338.4.10
by Marien Zwart
Make a test skipped from setUp run tearDown again. Make calling _runCleanups twice safe. Clean up tests. |
1143 |
|
1144 |
def test_skipped_from_test(self): |
|
|
3224.4.1
by Andrew Bennetts
Prune __dict__ of TestCases after they have run to save memory. |
1145 |
calls = [] |
|
2338.4.10
by Marien Zwart
Make a test skipped from setUp run tearDown again. Make calling _runCleanups twice safe. Clean up tests. |
1146 |
class SkippedTest(TestCase): |
|
2338.4.8
by Marien Zwart
Fix a bug in selftest causing tearDown to run twice for skipped tests. |
1147 |
|
1148 |
def setUp(self): |
|
|
3224.4.1
by Andrew Bennetts
Prune __dict__ of TestCases after they have run to save memory. |
1149 |
calls.append('setUp') |
|
2338.4.10
by Marien Zwart
Make a test skipped from setUp run tearDown again. Make calling _runCleanups twice safe. Clean up tests. |
1150 |
self.addCleanup(self.cleanup) |
|
2338.4.8
by Marien Zwart
Fix a bug in selftest causing tearDown to run twice for skipped tests. |
1151 |
|
1152 |
def test_skip(self): |
|
1153 |
raise TestSkipped('skipped test') |
|
1154 |
||
|
2338.4.10
by Marien Zwart
Make a test skipped from setUp run tearDown again. Make calling _runCleanups twice safe. Clean up tests. |
1155 |
def cleanup(self): |
|
3224.4.1
by Andrew Bennetts
Prune __dict__ of TestCases after they have run to save memory. |
1156 |
calls.append('cleanup') |
|
2338.4.8
by Marien Zwart
Fix a bug in selftest causing tearDown to run twice for skipped tests. |
1157 |
|
|
2485.6.5
by Martin Pool
Remove keep_output option |
1158 |
runner = TextTestRunner(stream=self._log_file) |
|
2338.4.8
by Marien Zwart
Fix a bug in selftest causing tearDown to run twice for skipped tests. |
1159 |
test = SkippedTest('test_skip') |
1160 |
result = self.run_test_runner(runner, test) |
|
1161 |
self.assertTrue(result.wasSuccessful()) |
|
|
2338.4.10
by Marien Zwart
Make a test skipped from setUp run tearDown again. Make calling _runCleanups twice safe. Clean up tests. |
1162 |
# Check if cleanup was called the right number of times.
|
|
3224.4.1
by Andrew Bennetts
Prune __dict__ of TestCases after they have run to save memory. |
1163 |
self.assertEqual(['setUp', 'cleanup'], calls) |
|
1534.11.7
by Robert Collins
Test and correct the problem with nested test logs breaking further in-test logs. |
1164 |
|
|
2729.1.1
by Martin Pool
Add TestNotApplicable exception and handling of it; document test parameterization |
1165 |
def test_not_applicable(self): |
1166 |
# run a test that is skipped because it's not applicable
|
|
1167 |
def not_applicable_test(): |
|
1168 |
from bzrlib.tests import TestNotApplicable |
|
1169 |
raise TestNotApplicable('this test never runs') |
|
1170 |
out = StringIO() |
|
1171 |
runner = TextTestRunner(stream=out, verbosity=2) |
|
1172 |
test = unittest.FunctionTestCase(not_applicable_test) |
|
1173 |
result = self.run_test_runner(runner, test) |
|
1174 |
self._log_file.write(out.getvalue()) |
|
1175 |
self.assertTrue(result.wasSuccessful()) |
|
1176 |
self.assertTrue(result.wasStrictlySuccessful()) |
|
1177 |
self.assertContainsRe(out.getvalue(), |
|
1178 |
r'(?m)not_applicable_test * N/A') |
|
1179 |
self.assertContainsRe(out.getvalue(), |
|
1180 |
r'(?m)^ this test never runs') |
|
1181 |
||
1182 |
def test_not_applicable_demo(self): |
|
1183 |
# just so you can see it in the test output
|
|
1184 |
raise TestNotApplicable('this test is just a demonstation') |
|
1185 |
||
|
2367.1.5
by Robert Collins
Implement reporting of Unsupported tests in the bzr test result and runner |
1186 |
def test_unsupported_features_listed(self): |
1187 |
"""When unsupported features are encountered they are detailed.""" |
|
1188 |
class Feature1(Feature): |
|
1189 |
def _probe(self): return False |
|
1190 |
class Feature2(Feature): |
|
1191 |
def _probe(self): return False |
|
1192 |
# create sample tests
|
|
1193 |
test1 = SampleTestCase('_test_pass') |
|
1194 |
test1._test_needs_features = [Feature1()] |
|
1195 |
test2 = SampleTestCase('_test_pass') |
|
1196 |
test2._test_needs_features = [Feature2()] |
|
1197 |
test = unittest.TestSuite() |
|
1198 |
test.addTest(test1) |
|
1199 |
test.addTest(test2) |
|
1200 |
stream = StringIO() |
|
1201 |
runner = TextTestRunner(stream=stream) |
|
1202 |
result = self.run_test_runner(runner, test) |
|
1203 |
lines = stream.getvalue().splitlines() |
|
1204 |
self.assertEqual([ |
|
1205 |
'OK', |
|
1206 |
"Missing feature 'Feature1' skipped 1 tests.", |
|
1207 |
"Missing feature 'Feature2' skipped 1 tests.", |
|
1208 |
],
|
|
|
2367.1.6
by Robert Collins
Allow per-test-fixture feature requirements via 'requireFeature'.(Robert Collins) |
1209 |
lines[-3:]) |
|
2367.1.5
by Robert Collins
Implement reporting of Unsupported tests in the bzr test result and runner |
1210 |
|
|
1819.1.2
by Carl Friedrich Bolz
(lifeless, cfbolz, hpk): Add a benchmark output parameter to TextTestRunner. |
1211 |
def test_bench_history(self): |
|
1951.1.1
by Andrew Bennetts
Make test_bench_history and _get_bzr_source_tree tolerant of UnknownFormatError for the bzr workingtree. |
1212 |
# tests that the running the benchmark produces a history file
|
1213 |
# containing a timestamp and the revision id of the bzrlib source which
|
|
1214 |
# was tested.
|
|
1215 |
workingtree = _get_bzr_source_tree() |
|
|
1819.1.2
by Carl Friedrich Bolz
(lifeless, cfbolz, hpk): Add a benchmark output parameter to TextTestRunner. |
1216 |
test = TestRunner('dummy_test') |
1217 |
output = StringIO() |
|
1218 |
runner = TextTestRunner(stream=self._log_file, bench_history=output) |
|
1219 |
result = self.run_test_runner(runner, test) |
|
1220 |
output_string = output.getvalue() |
|
|
1951.1.1
by Andrew Bennetts
Make test_bench_history and _get_bzr_source_tree tolerant of UnknownFormatError for the bzr workingtree. |
1221 |
self.assertContainsRe(output_string, "--date [0-9.]+") |
1222 |
if workingtree is not None: |
|
|
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
1223 |
revision_id = workingtree.get_parent_ids()[0] |
|
1951.1.1
by Andrew Bennetts
Make test_bench_history and _get_bzr_source_tree tolerant of UnknownFormatError for the bzr workingtree. |
1224 |
self.assertEndsWith(output_string.rstrip(), revision_id) |
|
1819.1.2
by Carl Friedrich Bolz
(lifeless, cfbolz, hpk): Add a benchmark output parameter to TextTestRunner. |
1225 |
|
|
3199.1.1
by Vincent Ladeuil
Get rid of ~1000 useless log files out of 10.000 tests in /tmp. |
1226 |
def assertLogDeleted(self, test): |
1227 |
log = test._get_log() |
|
1228 |
self.assertEqual("DELETED log file to reduce memory footprint", log) |
|
1229 |
self.assertEqual('', test._log_contents) |
|
1230 |
self.assertIs(None, test._log_file_name) |
|
1231 |
||
|
2036.1.1
by John Arbash Meinel
test that logs are kept or deleted when appropriate |
1232 |
def test_success_log_deleted(self): |
1233 |
"""Successful tests have their log deleted""" |
|
1234 |
||
1235 |
class LogTester(TestCase): |
|
1236 |
||
1237 |
def test_success(self): |
|
1238 |
self.log('this will be removed\n') |
|
1239 |
||
1240 |
sio = cStringIO.StringIO() |
|
1241 |
runner = TextTestRunner(stream=sio) |
|
1242 |
test = LogTester('test_success') |
|
1243 |
result = self.run_test_runner(runner, test) |
|
1244 |
||
|
3199.1.1
by Vincent Ladeuil
Get rid of ~1000 useless log files out of 10.000 tests in /tmp. |
1245 |
self.assertLogDeleted(test) |
1246 |
||
1247 |
def test_skipped_log_deleted(self): |
|
1248 |
"""Skipped tests have their log deleted""" |
|
1249 |
||
1250 |
class LogTester(TestCase): |
|
1251 |
||
1252 |
def test_skipped(self): |
|
1253 |
self.log('this will be removed\n') |
|
1254 |
raise tests.TestSkipped() |
|
1255 |
||
1256 |
sio = cStringIO.StringIO() |
|
1257 |
runner = TextTestRunner(stream=sio) |
|
1258 |
test = LogTester('test_skipped') |
|
1259 |
result = self.run_test_runner(runner, test) |
|
1260 |
||
1261 |
self.assertLogDeleted(test) |
|
1262 |
||
1263 |
def test_not_aplicable_log_deleted(self): |
|
1264 |
"""Not applicable tests have their log deleted""" |
|
1265 |
||
1266 |
class LogTester(TestCase): |
|
1267 |
||
1268 |
def test_not_applicable(self): |
|
1269 |
self.log('this will be removed\n') |
|
1270 |
raise tests.TestNotApplicable() |
|
1271 |
||
1272 |
sio = cStringIO.StringIO() |
|
1273 |
runner = TextTestRunner(stream=sio) |
|
1274 |
test = LogTester('test_not_applicable') |
|
1275 |
result = self.run_test_runner(runner, test) |
|
1276 |
||
1277 |
self.assertLogDeleted(test) |
|
1278 |
||
1279 |
def test_known_failure_log_deleted(self): |
|
1280 |
"""Know failure tests have their log deleted""" |
|
1281 |
||
1282 |
class LogTester(TestCase): |
|
1283 |
||
1284 |
def test_known_failure(self): |
|
1285 |
self.log('this will be removed\n') |
|
1286 |
raise tests.KnownFailure() |
|
1287 |
||
1288 |
sio = cStringIO.StringIO() |
|
1289 |
runner = TextTestRunner(stream=sio) |
|
1290 |
test = LogTester('test_known_failure') |
|
1291 |
result = self.run_test_runner(runner, test) |
|
1292 |
||
1293 |
self.assertLogDeleted(test) |
|
|
2036.1.1
by John Arbash Meinel
test that logs are kept or deleted when appropriate |
1294 |
|
1295 |
def test_fail_log_kept(self): |
|
1296 |
"""Failed tests have their log kept""" |
|
1297 |
||
1298 |
class LogTester(TestCase): |
|
1299 |
||
1300 |
def test_fail(self): |
|
1301 |
self.log('this will be kept\n') |
|
1302 |
self.fail('this test fails') |
|
1303 |
||
1304 |
sio = cStringIO.StringIO() |
|
1305 |
runner = TextTestRunner(stream=sio) |
|
1306 |
test = LogTester('test_fail') |
|
1307 |
result = self.run_test_runner(runner, test) |
|
1308 |
||
1309 |
text = sio.getvalue() |
|
1310 |
self.assertContainsRe(text, 'this will be kept') |
|
1311 |
self.assertContainsRe(text, 'this test fails') |
|
1312 |
||
1313 |
log = test._get_log() |
|
1314 |
self.assertContainsRe(log, 'this will be kept') |
|
1315 |
self.assertEqual(log, test._log_contents) |
|
1316 |
||
1317 |
def test_error_log_kept(self): |
|
1318 |
"""Tests with errors have their log kept""" |
|
1319 |
||
1320 |
class LogTester(TestCase): |
|
1321 |
||
1322 |
def test_error(self): |
|
1323 |
self.log('this will be kept\n') |
|
1324 |
raise ValueError('random exception raised') |
|
1325 |
||
1326 |
sio = cStringIO.StringIO() |
|
1327 |
runner = TextTestRunner(stream=sio) |
|
1328 |
test = LogTester('test_error') |
|
1329 |
result = self.run_test_runner(runner, test) |
|
1330 |
||
1331 |
text = sio.getvalue() |
|
1332 |
self.assertContainsRe(text, 'this will be kept') |
|
1333 |
self.assertContainsRe(text, 'random exception raised') |
|
1334 |
||
1335 |
log = test._get_log() |
|
1336 |
self.assertContainsRe(log, 'this will be kept') |
|
1337 |
self.assertEqual(log, test._log_contents) |
|
|
1819.1.2
by Carl Friedrich Bolz
(lifeless, cfbolz, hpk): Add a benchmark output parameter to TextTestRunner. |
1338 |
|
|
2036.1.2
by John Arbash Meinel
whitespace fix |
1339 |
|
|
2367.1.3
by Robert Collins
Add support for calling addNotSupported on TestResults to bzr TestCase's |
1340 |
class SampleTestCase(TestCase): |
1341 |
||
1342 |
def _test_pass(self): |
|
1343 |
pass
|
|
1344 |
||
1345 |
||
|
1534.11.7
by Robert Collins
Test and correct the problem with nested test logs breaking further in-test logs. |
1346 |
class TestTestCase(TestCase): |
1347 |
"""Tests that test the core bzrlib TestCase.""" |
|
1348 |
||
|
2560.1.1
by Robert Collins
Make debug.debug_flags be isolated for all tests. |
1349 |
def test_debug_flags_sanitised(self): |
1350 |
"""The bzrlib debug flags should be sanitised by setUp.""" |
|
1351 |
# we could set something and run a test that will check
|
|
1352 |
# it gets santised, but this is probably sufficient for now:
|
|
1353 |
# if someone runs the test with -Dsomething it will error.
|
|
1354 |
self.assertEqual(set(), bzrlib.debug.debug_flags) |
|
1355 |
||
|
1534.11.7
by Robert Collins
Test and correct the problem with nested test logs breaking further in-test logs. |
1356 |
def inner_test(self): |
1357 |
# the inner child test
|
|
1358 |
note("inner_test") |
|
1359 |
||
1360 |
def outer_child(self): |
|
1361 |
# the outer child test
|
|
1362 |
note("outer_start") |
|
1363 |
self.inner_test = TestTestCase("inner_child") |
|
|
2095.4.1
by Martin Pool
Better progress bars during tests |
1364 |
result = bzrlib.tests.TextTestResult(self._log_file, |
|
1534.11.7
by Robert Collins
Test and correct the problem with nested test logs breaking further in-test logs. |
1365 |
descriptions=0, |
1366 |
verbosity=1) |
|
1367 |
self.inner_test.run(result) |
|
1368 |
note("outer finish") |
|
1369 |
||
1370 |
def test_trace_nesting(self): |
|
1371 |
# this tests that each test case nests its trace facility correctly.
|
|
1372 |
# we do this by running a test case manually. That test case (A)
|
|
1373 |
# should setup a new log, log content to it, setup a child case (B),
|
|
1374 |
# which should log independently, then case (A) should log a trailer
|
|
1375 |
# and return.
|
|
1376 |
# we do two nested children so that we can verify the state of the
|
|
1377 |
# logs after the outer child finishes is correct, which a bad clean
|
|
1378 |
# up routine in tearDown might trigger a fault in our test with only
|
|
1379 |
# one child, we should instead see the bad result inside our test with
|
|
1380 |
# the two children.
|
|
1381 |
# the outer child test
|
|
1382 |
original_trace = bzrlib.trace._trace_file |
|
1383 |
outer_test = TestTestCase("outer_child") |
|
|
2095.4.1
by Martin Pool
Better progress bars during tests |
1384 |
result = bzrlib.tests.TextTestResult(self._log_file, |
|
1534.11.7
by Robert Collins
Test and correct the problem with nested test logs breaking further in-test logs. |
1385 |
descriptions=0, |
1386 |
verbosity=1) |
|
1387 |
outer_test.run(result) |
|
1388 |
self.assertEqual(original_trace, bzrlib.trace._trace_file) |
|
|
1707.2.4
by Robert Collins
Teach the bzrlib TestCase to report the time take by calls to self.time as benchmark time, allowing granular reporting of time during benchmarks. See bzrlib.benchmarks.bench_add. (Robert Collins, Martin Pool) |
1389 |
|
1390 |
def method_that_times_a_bit_twice(self): |
|
1391 |
# call self.time twice to ensure it aggregates
|
|
|
1713.1.4
by Robert Collins
Make the test test_time_creates_benchmark_in_result more robust to timing variation. |
1392 |
self.time(time.sleep, 0.007) |
1393 |
self.time(time.sleep, 0.007) |
|
|
1707.2.4
by Robert Collins
Teach the bzrlib TestCase to report the time take by calls to self.time as benchmark time, allowing granular reporting of time during benchmarks. See bzrlib.benchmarks.bench_add. (Robert Collins, Martin Pool) |
1394 |
|
1395 |
def test_time_creates_benchmark_in_result(self): |
|
1396 |
"""Test that the TestCase.time() method accumulates a benchmark time.""" |
|
1397 |
sample_test = TestTestCase("method_that_times_a_bit_twice") |
|
1398 |
output_stream = StringIO() |
|
|
2095.4.1
by Martin Pool
Better progress bars during tests |
1399 |
result = bzrlib.tests.VerboseTestResult( |
|
1707.2.4
by Robert Collins
Teach the bzrlib TestCase to report the time take by calls to self.time as benchmark time, allowing granular reporting of time during benchmarks. See bzrlib.benchmarks.bench_add. (Robert Collins, Martin Pool) |
1400 |
unittest._WritelnDecorator(output_stream), |
1401 |
descriptions=0, |
|
|
2095.4.1
by Martin Pool
Better progress bars during tests |
1402 |
verbosity=2, |
1403 |
num_tests=sample_test.countTestCases()) |
|
|
1707.2.4
by Robert Collins
Teach the bzrlib TestCase to report the time take by calls to self.time as benchmark time, allowing granular reporting of time during benchmarks. See bzrlib.benchmarks.bench_add. (Robert Collins, Martin Pool) |
1404 |
sample_test.run(result) |
1405 |
self.assertContainsRe( |
|
1406 |
output_stream.getvalue(), |
|
|
2067.3.1
by Martin Pool
Clean up BzrNewError, other exception classes and users. |
1407 |
r"\d+ms/ +\d+ms\n$") |
|
2245.1.1
by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers |
1408 |
|
1409 |
def test_hooks_sanitised(self): |
|
1410 |
"""The bzrlib hooks should be sanitised by setUp.""" |
|
|
2245.1.2
by Robert Collins
Remove the static DefaultHooks method from Branch, replacing it with a derived dict BranchHooks object, which is easier to use and provides a place to put the policy-checking add method discussed on list. |
1411 |
self.assertEqual(bzrlib.branch.BranchHooks(), |
|
2245.1.1
by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers |
1412 |
bzrlib.branch.Branch.hooks) |
|
2400.1.7
by Andrew Bennetts
Merge from bzr.dev. |
1413 |
self.assertEqual(bzrlib.smart.server.SmartServerHooks(), |
1414 |
bzrlib.smart.server.SmartTCPServer.hooks) |
|
|
2245.1.1
by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers |
1415 |
|
|
1725.1.1
by Robert Collins
'bzr selftest --benchmark --lsprof-timed' will use lsprofile to generate |
1416 |
def test__gather_lsprof_in_benchmarks(self): |
1417 |
"""When _gather_lsprof_in_benchmarks is on, accumulate profile data. |
|
1418 |
|
|
1419 |
Each self.time() call is individually and separately profiled.
|
|
1420 |
"""
|
|
|
1551.15.28
by Aaron Bentley
Improve Feature usage style w/ lsprof |
1421 |
self.requireFeature(test_lsprof.LSProfFeature) |
|
1725.1.1
by Robert Collins
'bzr selftest --benchmark --lsprof-timed' will use lsprofile to generate |
1422 |
# overrides the class member with an instance member so no cleanup
|
1423 |
# needed.
|
|
1424 |
self._gather_lsprof_in_benchmarks = True |
|
1425 |
self.time(time.sleep, 0.000) |
|
1426 |
self.time(time.sleep, 0.003) |
|
1427 |
self.assertEqual(2, len(self._benchcalls)) |
|
1428 |
self.assertEqual((time.sleep, (0.000,), {}), self._benchcalls[0][0]) |
|
1429 |
self.assertEqual((time.sleep, (0.003,), {}), self._benchcalls[1][0]) |
|
1430 |
self.assertIsInstance(self._benchcalls[0][1], bzrlib.lsprof.Stats) |
|
1431 |
self.assertIsInstance(self._benchcalls[1][1], bzrlib.lsprof.Stats) |
|
1432 |
||
|
2367.1.2
by Robert Collins
Some minor cleanups of test code, and implement KnownFailure support as |
1433 |
def test_knownFailure(self): |
1434 |
"""Self.knownFailure() should raise a KnownFailure exception.""" |
|
1435 |
self.assertRaises(KnownFailure, self.knownFailure, "A Failure") |
|
1436 |
||
|
2367.1.6
by Robert Collins
Allow per-test-fixture feature requirements via 'requireFeature'.(Robert Collins) |
1437 |
def test_requireFeature_available(self): |
1438 |
"""self.requireFeature(available) is a no-op.""" |
|
1439 |
class Available(Feature): |
|
1440 |
def _probe(self):return True |
|
1441 |
feature = Available() |
|
1442 |
self.requireFeature(feature) |
|
1443 |
||
1444 |
def test_requireFeature_unavailable(self): |
|
1445 |
"""self.requireFeature(unavailable) raises UnavailableFeature.""" |
|
1446 |
class Unavailable(Feature): |
|
1447 |
def _probe(self):return False |
|
1448 |
feature = Unavailable() |
|
1449 |
self.assertRaises(UnavailableFeature, self.requireFeature, feature) |
|
1450 |
||
|
2367.1.3
by Robert Collins
Add support for calling addNotSupported on TestResults to bzr TestCase's |
1451 |
def test_run_no_parameters(self): |
1452 |
test = SampleTestCase('_test_pass') |
|
1453 |
test.run() |
|
1454 |
||
1455 |
def test_run_enabled_unittest_result(self): |
|
1456 |
"""Test we revert to regular behaviour when the test is enabled.""" |
|
1457 |
test = SampleTestCase('_test_pass') |
|
1458 |
class EnabledFeature(object): |
|
1459 |
def available(self): |
|
1460 |
return True |
|
1461 |
test._test_needs_features = [EnabledFeature()] |
|
1462 |
result = unittest.TestResult() |
|
1463 |
test.run(result) |
|
1464 |
self.assertEqual(1, result.testsRun) |
|
1465 |
self.assertEqual([], result.errors) |
|
1466 |
self.assertEqual([], result.failures) |
|
1467 |
||
1468 |
def test_run_disabled_unittest_result(self): |
|
1469 |
"""Test our compatability for disabled tests with unittest results.""" |
|
1470 |
test = SampleTestCase('_test_pass') |
|
1471 |
class DisabledFeature(object): |
|
1472 |
def available(self): |
|
1473 |
return False |
|
1474 |
test._test_needs_features = [DisabledFeature()] |
|
1475 |
result = unittest.TestResult() |
|
1476 |
test.run(result) |
|
1477 |
self.assertEqual(1, result.testsRun) |
|
1478 |
self.assertEqual([], result.errors) |
|
1479 |
self.assertEqual([], result.failures) |
|
1480 |
||
1481 |
def test_run_disabled_supporting_result(self): |
|
1482 |
"""Test disabled tests behaviour with support aware results.""" |
|
1483 |
test = SampleTestCase('_test_pass') |
|
1484 |
class DisabledFeature(object): |
|
1485 |
def available(self): |
|
1486 |
return False |
|
1487 |
the_feature = DisabledFeature() |
|
1488 |
test._test_needs_features = [the_feature] |
|
1489 |
class InstrumentedTestResult(unittest.TestResult): |
|
1490 |
def __init__(self): |
|
1491 |
unittest.TestResult.__init__(self) |
|
1492 |
self.calls = [] |
|
1493 |
def startTest(self, test): |
|
1494 |
self.calls.append(('startTest', test)) |
|
1495 |
def stopTest(self, test): |
|
1496 |
self.calls.append(('stopTest', test)) |
|
1497 |
def addNotSupported(self, test, feature): |
|
1498 |
self.calls.append(('addNotSupported', test, feature)) |
|
1499 |
result = InstrumentedTestResult() |
|
1500 |
test.run(result) |
|
1501 |
self.assertEqual([ |
|
1502 |
('startTest', test), |
|
1503 |
('addNotSupported', test, the_feature), |
|
1504 |
('stopTest', test), |
|
1505 |
],
|
|
1506 |
result.calls) |
|
1507 |
||
|
1534.11.4
by Robert Collins
Merge from mainline. |
1508 |
|
|
1982.3.2
by Robert Collins
New TestCase helper applyDeprecated. This allows you to call a callable |
1509 |
@symbol_versioning.deprecated_function(zero_eleven) |
1510 |
def sample_deprecated_function(): |
|
1511 |
"""A deprecated function to test applyDeprecated with.""" |
|
1512 |
return 2 |
|
1513 |
||
1514 |
||
1515 |
def sample_undeprecated_function(a_param): |
|
1516 |
"""A undeprecated function to test applyDeprecated with.""" |
|
1517 |
||
1518 |
||
1519 |
class ApplyDeprecatedHelper(object): |
|
1520 |
"""A helper class for ApplyDeprecated tests.""" |
|
1521 |
||
1522 |
@symbol_versioning.deprecated_method(zero_eleven) |
|
1523 |
def sample_deprecated_method(self, param_one): |
|
1524 |
"""A deprecated method for testing with.""" |
|
1525 |
return param_one |
|
1526 |
||
1527 |
def sample_normal_method(self): |
|
1528 |
"""A undeprecated method.""" |
|
1529 |
||
1530 |
@symbol_versioning.deprecated_method(zero_ten) |
|
1531 |
def sample_nested_deprecation(self): |
|
1532 |
return sample_deprecated_function() |
|
1533 |
||
1534 |
||
|
1540.3.22
by Martin Pool
[patch] Add TestCase.assertIsInstance |
1535 |
class TestExtraAssertions(TestCase): |
1536 |
"""Tests for new test assertions in bzrlib test suite""" |
|
1537 |
||
1538 |
def test_assert_isinstance(self): |
|
1539 |
self.assertIsInstance(2, int) |
|
1540 |
self.assertIsInstance(u'', basestring) |
|
1541 |
self.assertRaises(AssertionError, self.assertIsInstance, None, int) |
|
1542 |
self.assertRaises(AssertionError, self.assertIsInstance, 23.3, int) |
|
|
1666.1.4
by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in |
1543 |
|
|
1692.3.1
by Robert Collins
Fix push to work with just a branch, no need for a working tree. |
1544 |
def test_assertEndsWith(self): |
1545 |
self.assertEndsWith('foo', 'oo') |
|
1546 |
self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo') |
|
1547 |
||
|
1982.3.2
by Robert Collins
New TestCase helper applyDeprecated. This allows you to call a callable |
1548 |
def test_applyDeprecated_not_deprecated(self): |
1549 |
sample_object = ApplyDeprecatedHelper() |
|
1550 |
# calling an undeprecated callable raises an assertion
|
|
1551 |
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven, |
|
1552 |
sample_object.sample_normal_method) |
|
1553 |
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven, |
|
1554 |
sample_undeprecated_function, "a param value") |
|
1555 |
# calling a deprecated callable (function or method) with the wrong
|
|
1556 |
# expected deprecation fails.
|
|
1557 |
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten, |
|
1558 |
sample_object.sample_deprecated_method, "a param value") |
|
1559 |
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten, |
|
1560 |
sample_deprecated_function) |
|
1561 |
# calling a deprecated callable (function or method) with the right
|
|
1562 |
# expected deprecation returns the functions result.
|
|
1563 |
self.assertEqual("a param value", self.applyDeprecated(zero_eleven, |
|
1564 |
sample_object.sample_deprecated_method, "a param value")) |
|
1565 |
self.assertEqual(2, self.applyDeprecated(zero_eleven, |
|
1566 |
sample_deprecated_function)) |
|
1567 |
# calling a nested deprecation with the wrong deprecation version
|
|
1568 |
# fails even if a deeper nested function was deprecated with the
|
|
1569 |
# supplied version.
|
|
1570 |
self.assertRaises(AssertionError, self.applyDeprecated, |
|
1571 |
zero_eleven, sample_object.sample_nested_deprecation) |
|
1572 |
# calling a nested deprecation with the right deprecation value
|
|
1573 |
# returns the calls result.
|
|
1574 |
self.assertEqual(2, self.applyDeprecated(zero_ten, |
|
1575 |
sample_object.sample_nested_deprecation)) |
|
1576 |
||
|
1551.8.9
by Aaron Bentley
Rename assertDeprecated to callDeprecated |
1577 |
def test_callDeprecated(self): |
|
1551.8.8
by Aaron Bentley
Made assertDeprecated return the callable's result |
1578 |
def testfunc(be_deprecated, result=None): |
|
1910.2.10
by Aaron Bentley
Add tests for assertDeprecated |
1579 |
if be_deprecated is True: |
1580 |
symbol_versioning.warn('i am deprecated', DeprecationWarning, |
|
1581 |
stacklevel=1) |
|
|
1551.8.8
by Aaron Bentley
Made assertDeprecated return the callable's result |
1582 |
return result |
|
1551.8.9
by Aaron Bentley
Rename assertDeprecated to callDeprecated |
1583 |
result = self.callDeprecated(['i am deprecated'], testfunc, True) |
|
1551.8.8
by Aaron Bentley
Made assertDeprecated return the callable's result |
1584 |
self.assertIs(None, result) |
|
1551.8.9
by Aaron Bentley
Rename assertDeprecated to callDeprecated |
1585 |
result = self.callDeprecated([], testfunc, False, 'result') |
|
1551.8.8
by Aaron Bentley
Made assertDeprecated return the callable's result |
1586 |
self.assertEqual('result', result) |
|
1982.3.2
by Robert Collins
New TestCase helper applyDeprecated. This allows you to call a callable |
1587 |
self.callDeprecated(['i am deprecated'], testfunc, be_deprecated=True) |
|
1551.8.9
by Aaron Bentley
Rename assertDeprecated to callDeprecated |
1588 |
self.callDeprecated([], testfunc, be_deprecated=False) |
|
1910.2.10
by Aaron Bentley
Add tests for assertDeprecated |
1589 |
|
|
1666.1.4
by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in |
1590 |
|
|
2592.3.242
by Martin Pool
New method TestCase.call_catch_warnings |
1591 |
class TestWarningTests(TestCase): |
1592 |
"""Tests for calling methods that raise warnings.""" |
|
1593 |
||
1594 |
def test_callCatchWarnings(self): |
|
1595 |
def meth(a, b): |
|
1596 |
warnings.warn("this is your last warning") |
|
1597 |
return a + b |
|
1598 |
wlist, result = self.callCatchWarnings(meth, 1, 2) |
|
1599 |
self.assertEquals(3, result) |
|
1600 |
# would like just to compare them, but UserWarning doesn't implement
|
|
1601 |
# eq well
|
|
1602 |
w0, = wlist |
|
1603 |
self.assertIsInstance(w0, UserWarning) |
|
|
2592.3.247
by Andrew Bennetts
Fix test_callCatchWarnings to pass when run with Python 2.4. |
1604 |
self.assertEquals("this is your last warning", str(w0)) |
|
2592.3.242
by Martin Pool
New method TestCase.call_catch_warnings |
1605 |
|
1606 |
||
|
1666.1.4
by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in |
1607 |
class TestConvenienceMakers(TestCaseWithTransport): |
1608 |
"""Test for the make_* convenience functions.""" |
|
1609 |
||
1610 |
def test_make_branch_and_tree_with_format(self): |
|
1611 |
# we should be able to supply a format to make_branch_and_tree
|
|
1612 |
self.make_branch_and_tree('a', format=bzrlib.bzrdir.BzrDirMetaFormat1()) |
|
1613 |
self.make_branch_and_tree('b', format=bzrlib.bzrdir.BzrDirFormat6()) |
|
1614 |
self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('a')._format, |
|
1615 |
bzrlib.bzrdir.BzrDirMetaFormat1) |
|
1616 |
self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('b')._format, |
|
1617 |
bzrlib.bzrdir.BzrDirFormat6) |
|
|
1707.2.1
by Robert Collins
'bzr selftest --benchmark' will run a new benchmarking selftest. |
1618 |
|
|
1986.2.1
by Robert Collins
Bugfix - the name of the test for make_branch_and_memory_tree was wrong. |
1619 |
def test_make_branch_and_memory_tree(self): |
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
1620 |
# we should be able to get a new branch and a mutable tree from
|
1621 |
# TestCaseWithTransport
|
|
1622 |
tree = self.make_branch_and_memory_tree('a') |
|
1623 |
self.assertIsInstance(tree, bzrlib.memorytree.MemoryTree) |
|
1624 |
||
|
1707.2.1
by Robert Collins
'bzr selftest --benchmark' will run a new benchmarking selftest. |
1625 |
|
|
1910.14.1
by Andrew Bennetts
Fix to make_branch_and_tree's behavior when used with an sftp transport. |
1626 |
class TestSFTPMakeBranchAndTree(TestCaseWithSFTPServer): |
1627 |
||
1628 |
def test_make_tree_for_sftp_branch(self): |
|
1629 |
"""Transports backed by local directories create local trees.""" |
|
1630 |
||
1631 |
tree = self.make_branch_and_tree('t1') |
|
1632 |
base = tree.bzrdir.root_transport.base |
|
1633 |
self.failIf(base.startswith('sftp'), |
|
1634 |
'base %r is on sftp but should be local' % base) |
|
1635 |
self.assertEquals(tree.bzrdir.root_transport, |
|
1636 |
tree.branch.bzrdir.root_transport) |
|
1637 |
self.assertEquals(tree.bzrdir.root_transport, |
|
1638 |
tree.branch.repository.bzrdir.root_transport) |
|
1639 |
||
1640 |
||
|
1707.2.1
by Robert Collins
'bzr selftest --benchmark' will run a new benchmarking selftest. |
1641 |
class TestSelftest(TestCase): |
1642 |
"""Tests of bzrlib.tests.selftest.""" |
|
1643 |
||
1644 |
def test_selftest_benchmark_parameter_invokes_test_suite__benchmark__(self): |
|
1645 |
factory_called = [] |
|
1646 |
def factory(): |
|
1647 |
factory_called.append(True) |
|
1648 |
return TestSuite() |
|
1649 |
out = StringIO() |
|
1650 |
err = StringIO() |
|
1651 |
self.apply_redirected(out, err, None, bzrlib.tests.selftest, |
|
1652 |
test_suite_factory=factory) |
|
1653 |
self.assertEqual([True], factory_called) |
|
|
2172.4.3
by Alexander Belchenko
Change name of option to '--clean-output' and provide tests |
1654 |
|
1655 |
||
|
2367.1.2
by Robert Collins
Some minor cleanups of test code, and implement KnownFailure support as |
1656 |
class TestKnownFailure(TestCase): |
1657 |
||
1658 |
def test_known_failure(self): |
|
1659 |
"""Check that KnownFailure is defined appropriately.""" |
|
1660 |
# a KnownFailure is an assertion error for compatability with unaware
|
|
1661 |
# runners.
|
|
1662 |
self.assertIsInstance(KnownFailure(""), AssertionError) |
|
|
2367.1.4
by Robert Collins
Add operating system Feature model to bzrlib.tests to allow writing tests |
1663 |
|
|
1551.13.9
by Aaron Bentley
Implement TestCase.expectFailure |
1664 |
def test_expect_failure(self): |
1665 |
try: |
|
1666 |
self.expectFailure("Doomed to failure", self.assertTrue, False) |
|
1667 |
except KnownFailure, e: |
|
1668 |
self.assertEqual('Doomed to failure', e.args[0]) |
|
1669 |
try: |
|
1670 |
self.expectFailure("Doomed to failure", self.assertTrue, True) |
|
1671 |
except AssertionError, e: |
|
1672 |
self.assertEqual('Unexpected success. Should have failed:' |
|
1673 |
' Doomed to failure', e.args[0]) |
|
1674 |
else: |
|
1675 |
self.fail('Assertion not raised') |
|
1676 |
||
|
2367.1.4
by Robert Collins
Add operating system Feature model to bzrlib.tests to allow writing tests |
1677 |
|
1678 |
class TestFeature(TestCase): |
|
1679 |
||
1680 |
def test_caching(self): |
|
1681 |
"""Feature._probe is called by the feature at most once.""" |
|
1682 |
class InstrumentedFeature(Feature): |
|
1683 |
def __init__(self): |
|
1684 |
Feature.__init__(self) |
|
1685 |
self.calls = [] |
|
1686 |
def _probe(self): |
|
1687 |
self.calls.append('_probe') |
|
1688 |
return False |
|
1689 |
feature = InstrumentedFeature() |
|
1690 |
feature.available() |
|
1691 |
self.assertEqual(['_probe'], feature.calls) |
|
1692 |
feature.available() |
|
1693 |
self.assertEqual(['_probe'], feature.calls) |
|
1694 |
||
1695 |
def test_named_str(self): |
|
1696 |
"""Feature.__str__ should thunk to feature_name().""" |
|
1697 |
class NamedFeature(Feature): |
|
1698 |
def feature_name(self): |
|
1699 |
return 'symlinks' |
|
1700 |
feature = NamedFeature() |
|
1701 |
self.assertEqual('symlinks', str(feature)) |
|
1702 |
||
1703 |
def test_default_str(self): |
|
1704 |
"""Feature.__str__ should default to __class__.__name__.""" |
|
1705 |
class NamedFeature(Feature): |
|
1706 |
pass
|
|
1707 |
feature = NamedFeature() |
|
1708 |
self.assertEqual('NamedFeature', str(feature)) |
|
|
2367.1.6
by Robert Collins
Allow per-test-fixture feature requirements via 'requireFeature'.(Robert Collins) |
1709 |
|
1710 |
||
1711 |
class TestUnavailableFeature(TestCase): |
|
1712 |
||
1713 |
def test_access_feature(self): |
|
1714 |
feature = Feature() |
|
1715 |
exception = UnavailableFeature(feature) |
|
1716 |
self.assertIs(feature, exception.args[0]) |
|
|
2394.2.5
by Ian Clatworthy
list-only working, include test not |
1717 |
|
1718 |
||
1719 |
class TestSelftestFiltering(TestCase): |
|
1720 |
||
|
2394.2.7
by Ian Clatworthy
Added whitebox tests - filter_suite_by_re and sort_suite_by_re |
1721 |
def setUp(self): |
1722 |
self.suite = TestUtil.TestSuite() |
|
1723 |
self.loader = TestUtil.TestLoader() |
|
1724 |
self.suite.addTest(self.loader.loadTestsFromModuleNames([ |
|
1725 |
'bzrlib.tests.test_selftest'])) |
|
|
2921.6.1
by Robert Collins
* New helper method ``bzrlib.tests.split_suite_by_re`` which splits a test |
1726 |
self.all_names = self._test_ids(self.suite) |
1727 |
||
1728 |
def _test_ids(self, test_suite): |
|
1729 |
"""Get the ids for the tests in a test suite.""" |
|
1730 |
return [t.id() for t in iter_suite_tests(test_suite)] |
|
|
2394.2.7
by Ian Clatworthy
Added whitebox tests - filter_suite_by_re and sort_suite_by_re |
1731 |
|
|
2921.6.9
by Robert Collins
* New helper function ``bzrlib.tests.condition_id_re`` which helps |
1732 |
def test_condition_id_re(self): |
1733 |
test_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.' |
|
1734 |
'test_condition_id_re') |
|
1735 |
filtered_suite = filter_suite_by_condition(self.suite, |
|
1736 |
condition_id_re('test_condition_id_re')) |
|
1737 |
self.assertEqual([test_name], self._test_ids(filtered_suite)) |
|
1738 |
||
|
3193.1.2
by Vincent Ladeuil
Add condition_id_in_list and filter_suite_by_id_list capabilities. |
1739 |
def test_condition_id_in_list(self): |
1740 |
test_names = ['bzrlib.tests.test_selftest.TestSelftestFiltering.' |
|
1741 |
'test_condition_id_in_list'] |
|
|
3193.1.11
by Vincent Ladeuil
Relax constraint on test ids, simplify implementation and update tests. |
1742 |
id_list = tests.TestIdList(test_names) |
|
3193.1.2
by Vincent Ladeuil
Add condition_id_in_list and filter_suite_by_id_list capabilities. |
1743 |
filtered_suite = filter_suite_by_condition( |
|
3193.1.11
by Vincent Ladeuil
Relax constraint on test ids, simplify implementation and update tests. |
1744 |
self.suite, tests.condition_id_in_list(id_list)) |
|
3193.1.2
by Vincent Ladeuil
Add condition_id_in_list and filter_suite_by_id_list capabilities. |
1745 |
my_pattern = 'TestSelftestFiltering.*test_condition_id_in_list' |
1746 |
re_filtered = filter_suite_by_re(self.suite, my_pattern) |
|
1747 |
self.assertEqual(self._test_ids(re_filtered), |
|
1748 |
self._test_ids(filtered_suite)) |
|
1749 |
||
|
2921.6.8
by Robert Collins
* New helper function ``bzrlib.tests.condition_isinstance`` which helps |
1750 |
def test_condition_isinstance(self): |
1751 |
filtered_suite = filter_suite_by_condition(self.suite, |
|
1752 |
condition_isinstance(self.__class__)) |
|
1753 |
class_pattern = 'bzrlib.tests.test_selftest.TestSelftestFiltering.' |
|
1754 |
re_filtered = filter_suite_by_re(self.suite, class_pattern) |
|
1755 |
self.assertEqual(self._test_ids(re_filtered), |
|
1756 |
self._test_ids(filtered_suite)) |
|
1757 |
||
|
2921.6.9
by Robert Collins
* New helper function ``bzrlib.tests.condition_id_re`` which helps |
1758 |
def test_exclude_tests_by_condition(self): |
1759 |
excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.' |
|
1760 |
'test_exclude_tests_by_condition') |
|
1761 |
filtered_suite = exclude_tests_by_condition(self.suite, |
|
1762 |
lambda x:x.id() == excluded_name) |
|
1763 |
self.assertEqual(len(self.all_names) - 1, |
|
1764 |
filtered_suite.countTestCases()) |
|
1765 |
self.assertFalse(excluded_name in self._test_ids(filtered_suite)) |
|
1766 |
remaining_names = list(self.all_names) |
|
1767 |
remaining_names.remove(excluded_name) |
|
1768 |
self.assertEqual(remaining_names, self._test_ids(filtered_suite)) |
|
1769 |
||
|
2921.6.2
by Robert Collins
* New helper method ``bzrlib.tests.exclude_tests_by_re`` which gives a new |
1770 |
def test_exclude_tests_by_re(self): |
1771 |
self.all_names = self._test_ids(self.suite) |
|
1772 |
filtered_suite = exclude_tests_by_re(self.suite, 'exclude_tests_by_re') |
|
1773 |
excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.' |
|
1774 |
'test_exclude_tests_by_re') |
|
1775 |
self.assertEqual(len(self.all_names) - 1, |
|
1776 |
filtered_suite.countTestCases()) |
|
1777 |
self.assertFalse(excluded_name in self._test_ids(filtered_suite)) |
|
1778 |
remaining_names = list(self.all_names) |
|
1779 |
remaining_names.remove(excluded_name) |
|
1780 |
self.assertEqual(remaining_names, self._test_ids(filtered_suite)) |
|
1781 |
||
|
2921.6.7
by Robert Collins
* New helper function ``bzrlib.tests.filter_suite_by_condition`` which |
1782 |
def test_filter_suite_by_condition(self): |
1783 |
test_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.' |
|
1784 |
'test_filter_suite_by_condition') |
|
1785 |
filtered_suite = filter_suite_by_condition(self.suite, |
|
1786 |
lambda x:x.id() == test_name) |
|
1787 |
self.assertEqual([test_name], self._test_ids(filtered_suite)) |
|
1788 |
||
|
2394.2.5
by Ian Clatworthy
list-only working, include test not |
1789 |
def test_filter_suite_by_re(self): |
|
2921.6.7
by Robert Collins
* New helper function ``bzrlib.tests.filter_suite_by_condition`` which |
1790 |
filtered_suite = filter_suite_by_re(self.suite, 'test_filter_suite_by_r') |
|
2921.6.1
by Robert Collins
* New helper method ``bzrlib.tests.split_suite_by_re`` which splits a test |
1791 |
filtered_names = self._test_ids(filtered_suite) |
|
2394.2.7
by Ian Clatworthy
Added whitebox tests - filter_suite_by_re and sort_suite_by_re |
1792 |
self.assertEqual(filtered_names, ['bzrlib.tests.test_selftest.' |
1793 |
'TestSelftestFiltering.test_filter_suite_by_re']) |
|
|
2921.6.1
by Robert Collins
* New helper method ``bzrlib.tests.split_suite_by_re`` which splits a test |
1794 |
|
|
3193.1.2
by Vincent Ladeuil
Add condition_id_in_list and filter_suite_by_id_list capabilities. |
1795 |
def test_filter_suite_by_id_list(self): |
|
3193.1.11
by Vincent Ladeuil
Relax constraint on test ids, simplify implementation and update tests. |
1796 |
test_list = ['bzrlib.tests.test_selftest.' |
1797 |
'TestSelftestFiltering.test_filter_suite_by_id_list'] |
|
|
3193.1.2
by Vincent Ladeuil
Add condition_id_in_list and filter_suite_by_id_list capabilities. |
1798 |
filtered_suite = tests.filter_suite_by_id_list( |
|
3193.1.11
by Vincent Ladeuil
Relax constraint on test ids, simplify implementation and update tests. |
1799 |
self.suite, tests.TestIdList(test_list)) |
|
3193.1.2
by Vincent Ladeuil
Add condition_id_in_list and filter_suite_by_id_list capabilities. |
1800 |
filtered_names = self._test_ids(filtered_suite) |
1801 |
self.assertEqual( |
|
1802 |
filtered_names, |
|
1803 |
['bzrlib.tests.test_selftest.' |
|
1804 |
'TestSelftestFiltering.test_filter_suite_by_id_list']) |
|
1805 |
||
|
2921.6.6
by Robert Collins
* The ``exclude_pattern`` and ``random_order`` parameters to the function |
1806 |
def test_preserve_input(self): |
1807 |
# NB: Surely this is something in the stdlib to do this?
|
|
1808 |
self.assertTrue(self.suite is preserve_input(self.suite)) |
|
1809 |
self.assertTrue("@#$" is preserve_input("@#$")) |
|
1810 |
||
|
3128.1.2
by Vincent Ladeuil
Tweak as per review feedback: s/randomise.*/randomize&/, 0.92 -> 1.0. |
1811 |
def test_randomize_suite(self): |
1812 |
randomized_suite = randomize_suite(self.suite) |
|
1813 |
# randomizing should not add or remove test names.
|
|
|
2921.6.3
by Robert Collins
* New helper method ``bzrlib.tests.randomise_suite`` which returns a |
1814 |
self.assertEqual(set(self._test_ids(self.suite)), |
|
3128.1.2
by Vincent Ladeuil
Tweak as per review feedback: s/randomise.*/randomize&/, 0.92 -> 1.0. |
1815 |
set(self._test_ids(randomized_suite))) |
|
2921.6.3
by Robert Collins
* New helper method ``bzrlib.tests.randomise_suite`` which returns a |
1816 |
# Technically, this *can* fail, because random.shuffle(list) can be
|
1817 |
# equal to list. Trying multiple times just pushes the frequency back.
|
|
1818 |
# As its len(self.all_names)!:1, the failure frequency should be low
|
|
1819 |
# enough to ignore. RBC 20071021.
|
|
1820 |
# It should change the order.
|
|
|
3128.1.2
by Vincent Ladeuil
Tweak as per review feedback: s/randomise.*/randomize&/, 0.92 -> 1.0. |
1821 |
self.assertNotEqual(self.all_names, self._test_ids(randomized_suite)) |
|
2921.6.3
by Robert Collins
* New helper method ``bzrlib.tests.randomise_suite`` which returns a |
1822 |
# But not the length. (Possibly redundant with the set test, but not
|
1823 |
# necessarily.)
|
|
1824 |
self.assertEqual(len(self.all_names), |
|
|
3128.1.2
by Vincent Ladeuil
Tweak as per review feedback: s/randomise.*/randomize&/, 0.92 -> 1.0. |
1825 |
len(self._test_ids(randomized_suite))) |
|
2921.6.3
by Robert Collins
* New helper method ``bzrlib.tests.randomise_suite`` which returns a |
1826 |
|
|
2394.2.7
by Ian Clatworthy
Added whitebox tests - filter_suite_by_re and sort_suite_by_re |
1827 |
def test_sort_suite_by_re(self): |
|
3128.1.2
by Vincent Ladeuil
Tweak as per review feedback: s/randomise.*/randomize&/, 0.92 -> 1.0. |
1828 |
sorted_suite = self.applyDeprecated(one_zero, |
|
2921.6.7
by Robert Collins
* New helper function ``bzrlib.tests.filter_suite_by_condition`` which |
1829 |
sort_suite_by_re, self.suite, 'test_filter_suite_by_r') |
|
2921.6.1
by Robert Collins
* New helper method ``bzrlib.tests.split_suite_by_re`` which splits a test |
1830 |
sorted_names = self._test_ids(sorted_suite) |
|
2394.2.7
by Ian Clatworthy
Added whitebox tests - filter_suite_by_re and sort_suite_by_re |
1831 |
self.assertEqual(sorted_names[0], 'bzrlib.tests.test_selftest.' |
1832 |
'TestSelftestFiltering.test_filter_suite_by_re') |
|
1833 |
self.assertEquals(sorted(self.all_names), sorted(sorted_names)) |
|
1834 |
||
|
2921.6.1
by Robert Collins
* New helper method ``bzrlib.tests.split_suite_by_re`` which splits a test |
1835 |
def test_split_suit_by_re(self): |
1836 |
self.all_names = self._test_ids(self.suite) |
|
|
2921.6.7
by Robert Collins
* New helper function ``bzrlib.tests.filter_suite_by_condition`` which |
1837 |
split_suite = split_suite_by_re(self.suite, 'test_filter_suite_by_r') |
|
2921.6.1
by Robert Collins
* New helper method ``bzrlib.tests.split_suite_by_re`` which splits a test |
1838 |
filtered_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.' |
1839 |
'test_filter_suite_by_re') |
|
1840 |
self.assertEqual([filtered_name], self._test_ids(split_suite[0])) |
|
1841 |
self.assertFalse(filtered_name in self._test_ids(split_suite[1])) |
|
1842 |
remaining_names = list(self.all_names) |
|
1843 |
remaining_names.remove(filtered_name) |
|
1844 |
self.assertEqual(remaining_names, self._test_ids(split_suite[1])) |
|
1845 |
||
|
2545.3.2
by James Westby
Add a test for check_inventory_shape. |
1846 |
|
1847 |
class TestCheckInventoryShape(TestCaseWithTransport): |
|
1848 |
||
1849 |
def test_check_inventory_shape(self): |
|
|
2561.1.2
by Aaron Bentley
Fix indenting in TestCheckInventoryShape |
1850 |
files = ['a', 'b/', 'b/c'] |
1851 |
tree = self.make_branch_and_tree('.') |
|
1852 |
self.build_tree(files) |
|
1853 |
tree.add(files) |
|
1854 |
tree.lock_read() |
|
1855 |
try: |
|
1856 |
self.check_inventory_shape(tree.inventory, files) |
|
1857 |
finally: |
|
1858 |
tree.unlock() |
|
|
2830.2.1
by Martin Pool
If TestCase.run_bzr hits an internal exception, don't catch it but rather propagate up into the test suite |
1859 |
|
1860 |
||
1861 |
class TestBlackboxSupport(TestCase): |
|
1862 |
"""Tests for testsuite blackbox features.""" |
|
1863 |
||
1864 |
def test_run_bzr_failure_not_caught(self): |
|
1865 |
# When we run bzr in blackbox mode, we want any unexpected errors to
|
|
1866 |
# propagate up to the test suite so that it can show the error in the
|
|
1867 |
# usual way, and we won't get a double traceback.
|
|
1868 |
e = self.assertRaises( |
|
1869 |
AssertionError, |
|
1870 |
self.run_bzr, ['assert-fail']) |
|
1871 |
# make sure we got the real thing, not an error from somewhere else in
|
|
1872 |
# the test framework
|
|
1873 |
self.assertEquals('always fails', str(e)) |
|
1874 |
# check that there's no traceback in the test log
|
|
1875 |
self.assertNotContainsRe(self._get_log(keep_log_file=True), |
|
1876 |
r'Traceback') |
|
1877 |
||
1878 |
def test_run_bzr_user_error_caught(self): |
|
1879 |
# Running bzr in blackbox mode, normal/expected/user errors should be
|
|
1880 |
# caught in the regular way and turned into an error message plus exit
|
|
1881 |
# code.
|
|
1882 |
out, err = self.run_bzr(["log", "/nonexistantpath"], retcode=3) |
|
1883 |
self.assertEqual(out, '') |
|
|
3146.4.7
by Aaron Bentley
Remove UNIX path assumption |
1884 |
self.assertContainsRe(err, |
1885 |
'bzr: ERROR: Not a branch: ".*nonexistantpath/".\n') |
|
|
2921.6.13
by Robert Collins
* Modules can now customise their tests by defining a ``load_tests`` |
1886 |
|
1887 |
||
1888 |
class TestTestLoader(TestCase): |
|
1889 |
"""Tests for the test loader.""" |
|
1890 |
||
1891 |
def _get_loader_and_module(self): |
|
1892 |
"""Gets a TestLoader and a module with one test in it.""" |
|
1893 |
loader = TestUtil.TestLoader() |
|
1894 |
module = {} |
|
1895 |
class Stub(TestCase): |
|
1896 |
def test_foo(self): |
|
1897 |
pass
|
|
1898 |
class MyModule(object): |
|
1899 |
pass
|
|
1900 |
MyModule.a_class = Stub |
|
1901 |
module = MyModule() |
|
1902 |
return loader, module |
|
1903 |
||
1904 |
def test_module_no_load_tests_attribute_loads_classes(self): |
|
1905 |
loader, module = self._get_loader_and_module() |
|
1906 |
self.assertEqual(1, loader.loadTestsFromModule(module).countTestCases()) |
|
1907 |
||
1908 |
def test_module_load_tests_attribute_gets_called(self): |
|
1909 |
loader, module = self._get_loader_and_module() |
|
1910 |
# 'self' is here because we're faking the module with a class. Regular
|
|
1911 |
# load_tests do not need that :)
|
|
1912 |
def load_tests(self, standard_tests, module, loader): |
|
1913 |
result = loader.suiteClass() |
|
1914 |
for test in iter_suite_tests(standard_tests): |
|
1915 |
result.addTests([test, test]) |
|
1916 |
return result |
|
1917 |
# add a load_tests() method which multiplies the tests from the module.
|
|
1918 |
module.__class__.load_tests = load_tests |
|
1919 |
self.assertEqual(2, loader.loadTestsFromModule(module).countTestCases()) |
|
1920 |
||
|
3193.1.1
by Vincent Ladeuil
Helper to filter test suite building by module when loading a list. |
1921 |
|
|
3193.1.11
by Vincent Ladeuil
Relax constraint on test ids, simplify implementation and update tests. |
1922 |
class TestTestIdList(tests.TestCase): |
1923 |
||
1924 |
def _create_id_list(self, test_list): |
|
1925 |
return tests.TestIdList(test_list) |
|
1926 |
||
1927 |
def _create_suite(self, test_id_list): |
|
|
3193.1.5
by Vincent Ladeuil
Add helper method to get only listed tests from a module test suite. |
1928 |
|
1929 |
class Stub(TestCase): |
|
1930 |
def test_foo(self): |
|
1931 |
pass
|
|
1932 |
||
1933 |
def _create_test_id(id): |
|
1934 |
return lambda: id |
|
1935 |
||
1936 |
suite = TestUtil.TestSuite() |
|
|
3193.1.11
by Vincent Ladeuil
Relax constraint on test ids, simplify implementation and update tests. |
1937 |
for id in test_id_list: |
|
3193.1.5
by Vincent Ladeuil
Add helper method to get only listed tests from a module test suite. |
1938 |
t = Stub('test_foo') |
1939 |
t.id = _create_test_id(id) |
|
1940 |
suite.addTest(t) |
|
1941 |
return suite |
|
1942 |
||
1943 |
def _test_ids(self, test_suite): |
|
1944 |
"""Get the ids for the tests in a test suite.""" |
|
1945 |
return [t.id() for t in iter_suite_tests(test_suite)] |
|
1946 |
||
|
3193.1.1
by Vincent Ladeuil
Helper to filter test suite building by module when loading a list. |
1947 |
def test_empty_list(self): |
|
3193.1.11
by Vincent Ladeuil
Relax constraint on test ids, simplify implementation and update tests. |
1948 |
id_list = self._create_id_list([]) |
1949 |
self.assertEquals({}, id_list.tests) |
|
1950 |
self.assertEquals({}, id_list.modules) |
|
|
3193.1.1
by Vincent Ladeuil
Helper to filter test suite building by module when loading a list. |
1951 |
|
1952 |
def test_valid_list(self): |
|
|
3193.1.11
by Vincent Ladeuil
Relax constraint on test ids, simplify implementation and update tests. |
1953 |
id_list = self._create_id_list( |
|
3193.1.4
by Vincent Ladeuil
Make TestTestIdListFilter aware that a test exists for a module or one of |
1954 |
['mod1.cl1.meth1', 'mod1.cl1.meth2', |
|
3193.1.11
by Vincent Ladeuil
Relax constraint on test ids, simplify implementation and update tests. |
1955 |
'mod1.func1', 'mod1.cl2.meth2', |
1956 |
'mod1.submod1', |
|
|
3193.1.4
by Vincent Ladeuil
Make TestTestIdListFilter aware that a test exists for a module or one of |
1957 |
'mod1.submod2.cl1.meth1', 'mod1.submod2.cl2.meth2', |
1958 |
])
|
|
|
3193.1.11
by Vincent Ladeuil
Relax constraint on test ids, simplify implementation and update tests. |
1959 |
self.assertTrue(id_list.is_module_name_used('mod1')) |
1960 |
self.assertTrue(id_list.is_module_name_used('mod1.submod1')) |
|
1961 |
self.assertTrue(id_list.is_module_name_used('mod1.submod2')) |
|
1962 |
self.assertTrue(id_list.test_in('mod1.cl1.meth1')) |
|
1963 |
self.assertTrue(id_list.test_in('mod1.submod1')) |
|
1964 |
self.assertTrue(id_list.test_in('mod1.func1')) |
|
|
3193.1.1
by Vincent Ladeuil
Helper to filter test suite building by module when loading a list. |
1965 |
|
1966 |
def test_bad_chars_in_params(self): |
|
|
3193.1.11
by Vincent Ladeuil
Relax constraint on test ids, simplify implementation and update tests. |
1967 |
id_list = self._create_id_list(['mod1.cl1.meth1(xx.yy)']) |
1968 |
self.assertTrue(id_list.is_module_name_used('mod1')) |
|
1969 |
self.assertTrue(id_list.test_in('mod1.cl1.meth1(xx.yy)')) |
|
|
3193.1.4
by Vincent Ladeuil
Make TestTestIdListFilter aware that a test exists for a module or one of |
1970 |
|
1971 |
def test_module_used(self): |
|
|
3193.1.11
by Vincent Ladeuil
Relax constraint on test ids, simplify implementation and update tests. |
1972 |
id_list = self._create_id_list(['mod.class.meth']) |
1973 |
self.assertTrue(id_list.is_module_name_used('mod')) |
|
1974 |
self.assertTrue(id_list.is_module_name_used('mod.class')) |
|
1975 |
self.assertTrue(id_list.is_module_name_used('mod.class.meth')) |
|
|
3193.1.6
by Vincent Ladeuil
Filter the whole test suite. |
1976 |
|
1977 |
def test_test_suite(self): |
|
1978 |
# This test is slow, so we do a single test with one test in each
|
|
1979 |
# category
|
|
1980 |
test_list = [ |
|
1981 |
# testmod_names
|
|
|
3193.1.12
by Vincent Ladeuil
Fix typo (using test id list is no replacement for running the whole test suite QED). |
1982 |
'bzrlib.tests.test_selftest.TestTestIdList.test_test_suite', |
|
3193.1.6
by Vincent Ladeuil
Filter the whole test suite. |
1983 |
# transport implementations
|
1984 |
'bzrlib.tests.test_transport_implementations.TransportTests'
|
|
1985 |
'.test_abspath(LocalURLServer)', |
|
1986 |
# packages_to_test()
|
|
1987 |
'bzrlib.tests.blackbox.test_branch.TestBranch.test_branch', |
|
1988 |
# MODULES_TO_DOCTEST
|
|
1989 |
'bzrlib.timestamp.format_highres_date', |
|
|
3193.1.8
by Vincent Ladeuil
Add '--load-list' option to selftest. |
1990 |
# plugins can't be tested that way since selftest may be run with
|
1991 |
# --no-plugins
|
|
|
3193.1.6
by Vincent Ladeuil
Filter the whole test suite. |
1992 |
]
|
1993 |
suite = tests.test_suite(test_list) |
|
1994 |
self.assertEquals(test_list, self._test_ids(suite)) |
|
|
3193.1.7
by Vincent Ladeuil
Load test id list from a text file. |
1995 |
|
1996 |
||
1997 |
class TestLoadTestIdList(tests.TestCaseInTempDir): |
|
1998 |
||
1999 |
def _create_test_list_file(self, file_name, content): |
|
2000 |
fl = open(file_name, 'wt') |
|
2001 |
fl.write(content) |
|
2002 |
fl.close() |
|
2003 |
||
2004 |
def test_load_unknown(self): |
|
2005 |
self.assertRaises(errors.NoSuchFile, |
|
2006 |
tests.load_test_id_list, 'i_do_not_exist') |
|
2007 |
||
2008 |
def test_load_test_list(self): |
|
2009 |
test_list_fname = 'test.list' |
|
2010 |
self._create_test_list_file(test_list_fname, |
|
2011 |
'mod1.cl1.meth1\nmod2.cl2.meth2\n') |
|
2012 |
tlist = tests.load_test_id_list(test_list_fname) |
|
2013 |
self.assertEquals(2, len(tlist)) |
|
2014 |
self.assertEquals('mod1.cl1.meth1', tlist[0]) |
|
2015 |
self.assertEquals('mod2.cl2.meth2', tlist[1]) |
|
2016 |
||
2017 |
def test_load_dirty_file(self): |
|
2018 |
test_list_fname = 'test.list' |
|
2019 |
self._create_test_list_file(test_list_fname, |
|
2020 |
' mod1.cl1.meth1\n\nmod2.cl2.meth2 \n' |
|
2021 |
'bar baz\n') |
|
2022 |
tlist = tests.load_test_id_list(test_list_fname) |
|
2023 |
self.assertEquals(4, len(tlist)) |
|
2024 |
self.assertEquals('mod1.cl1.meth1', tlist[0]) |
|
2025 |
self.assertEquals('', tlist[1]) |
|
2026 |
self.assertEquals('mod2.cl2.meth2', tlist[2]) |
|
2027 |
self.assertEquals('bar baz', tlist[3]) |
|
2028 |
||
2029 |