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