112
78
'a test message\n')
115
class TestUnicodeFilename(TestCase):
117
def test_probe_passes(self):
118
"""UnicodeFilename._probe passes."""
119
# We can't test much more than that because the behaviour depends
121
tests.UnicodeFilename._probe()
124
81
class TestTreeShape(TestCaseInTempDir):
126
83
def test_unicode_paths(self):
127
self.requireFeature(tests.UnicodeFilename)
129
84
filename = u'hell\u00d8'
130
self.build_tree_contents([(filename, 'contents of hello')])
86
self.build_tree_contents([(filename, 'contents of hello')])
87
except UnicodeEncodeError:
88
raise TestSkipped("can't build unicode working tree in "
89
"filesystem encoding %s" % sys.getfilesystemencoding())
131
90
self.failUnlessExists(filename)
134
class TestTransportScenarios(TestCase):
93
class TestTransportProviderAdapter(TestCase):
135
94
"""A group of tests that test the transport implementation adaption core.
137
This is a meta test that the tests are applied to all available
96
This is a meta test that the tests are applied to all available
140
This will be generalised in the future which is why it is in this
99
This will be generalised in the future which is why it is in this
141
100
test file even though it is specific to transport tests at the moment.
144
103
def test_get_transport_permutations(self):
145
# this checks that get_test_permutations defined by the module is
146
# called by the get_transport_test_permutations function.
104
# this checks that we the module get_test_permutations call
105
# is made by the adapter get_transport_test_permitations method.
147
106
class MockModule(object):
148
107
def get_test_permutations(self):
149
108
return sample_permutation
150
109
sample_permutation = [(1,2), (3,4)]
151
from bzrlib.tests.test_transport_implementations \
152
import get_transport_test_permutations
110
from bzrlib.transport import TransportTestProviderAdapter
111
adapter = TransportTestProviderAdapter()
153
112
self.assertEqual(sample_permutation,
154
get_transport_test_permutations(MockModule()))
113
adapter.get_transport_test_permutations(MockModule()))
156
def test_scenarios_invlude_all_modules(self):
157
# this checks that the scenario generator returns as many permutations
158
# as there are in all the registered transport modules - we assume if
159
# this matches its probably doing the right thing especially in
160
# combination with the tests for setting the right classes below.
161
from bzrlib.tests.test_transport_implementations \
162
import transport_test_permutations
163
from bzrlib.transport import _get_transport_modules
115
def test_adapter_checks_all_modules(self):
116
# this checks that the adapter returns as many permurtations as
117
# there are in all the registered# transport modules for there
118
# - we assume if this matches its probably doing the right thing
119
# especially in combination with the tests for setting the right
121
from bzrlib.transport import (TransportTestProviderAdapter,
122
_get_transport_modules
164
124
modules = _get_transport_modules()
165
125
permutation_count = 0
166
126
for module in modules:
168
permutation_count += len(reduce(getattr,
128
permutation_count += len(reduce(getattr,
169
129
(module + ".get_test_permutations").split('.')[1:],
170
130
__import__(module))())
171
131
except errors.DependencyNotPresent:
173
scenarios = transport_test_permutations()
174
self.assertEqual(permutation_count, len(scenarios))
133
input_test = TestTransportProviderAdapter(
134
"test_adapter_sets_transport_class")
135
adapter = TransportTestProviderAdapter()
136
self.assertEqual(permutation_count,
137
len(list(iter(adapter.adapt(input_test)))))
176
def test_scenarios_include_transport_class(self):
139
def test_adapter_sets_transport_class(self):
140
# Check that the test adapter inserts a transport and server into the
177
143
# This test used to know about all the possible transports and the
178
144
# order they were returned but that seems overly brittle (mbp
180
from bzrlib.tests.test_transport_implementations \
181
import transport_test_permutations
182
scenarios = transport_test_permutations()
146
input_test = TestTransportProviderAdapter(
147
"test_adapter_sets_transport_class")
148
from bzrlib.transport import TransportTestProviderAdapter
149
suite = TransportTestProviderAdapter().adapt(input_test)
150
tests = list(iter(suite))
151
self.assertTrue(len(tests) > 6)
183
152
# there are at least that many builtin transports
184
self.assertTrue(len(scenarios) > 6)
185
one_scenario = scenarios[0]
186
self.assertIsInstance(one_scenario[0], str)
187
self.assertTrue(issubclass(one_scenario[1]["transport_class"],
154
self.assertTrue(issubclass(one_test.transport_class,
188
155
bzrlib.transport.Transport))
189
self.assertTrue(issubclass(one_scenario[1]["transport_server"],
156
self.assertTrue(issubclass(one_test.transport_server,
190
157
bzrlib.transport.Server))
193
class TestBranchScenarios(TestCase):
160
class TestBranchProviderAdapter(TestCase):
161
"""A group of tests that test the branch implementation test adapter."""
195
def test_scenarios(self):
163
def test_adapted_tests(self):
196
164
# check that constructor parameters are passed through to the adapted
198
from bzrlib.tests.branch_implementations import make_scenarios
166
from bzrlib.branch import BranchTestProviderAdapter
167
input_test = TestBranchProviderAdapter(
168
"test_adapted_tests")
201
171
formats = [("c", "C"), ("d", "D")]
202
scenarios = make_scenarios(server1, server2, formats)
203
self.assertEqual(2, len(scenarios))
206
{'branch_format': 'c',
207
'bzrdir_format': 'C',
208
'transport_readonly_server': 'b',
209
'transport_server': 'a'}),
211
{'branch_format': 'd',
212
'bzrdir_format': 'D',
213
'transport_readonly_server': 'b',
214
'transport_server': 'a'})],
218
class TestBzrDirScenarios(TestCase):
220
def test_scenarios(self):
172
adapter = BranchTestProviderAdapter(server1, server2, formats)
173
suite = adapter.adapt(input_test)
174
tests = list(iter(suite))
175
self.assertEqual(2, len(tests))
176
self.assertEqual(tests[0].branch_format, formats[0][0])
177
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
178
self.assertEqual(tests[0].transport_server, server1)
179
self.assertEqual(tests[0].transport_readonly_server, server2)
180
self.assertEqual(tests[1].branch_format, formats[1][0])
181
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
182
self.assertEqual(tests[1].transport_server, server1)
183
self.assertEqual(tests[1].transport_readonly_server, server2)
186
class TestBzrDirProviderAdapter(TestCase):
187
"""A group of tests that test the bzr dir implementation test adapter."""
189
def test_adapted_tests(self):
221
190
# check that constructor parameters are passed through to the adapted
223
from bzrlib.tests.bzrdir_implementations import make_scenarios
192
from bzrlib.bzrdir import BzrDirTestProviderAdapter
193
input_test = TestBzrDirProviderAdapter(
194
"test_adapted_tests")
227
197
formats = ["c", "d"]
228
scenarios = make_scenarios(vfs_factory, server1, server2, formats)
231
{'bzrdir_format': 'c',
232
'transport_readonly_server': 'b',
233
'transport_server': 'a',
234
'vfs_transport_factory': 'v'}),
236
{'bzrdir_format': 'd',
237
'transport_readonly_server': 'b',
238
'transport_server': 'a',
239
'vfs_transport_factory': 'v'})],
243
class TestRepositoryScenarios(TestCase):
245
def test_formats_to_scenarios(self):
246
from bzrlib.tests.per_repository import formats_to_scenarios
247
formats = [("(c)", remote.RemoteRepositoryFormat()),
248
("(d)", repository.format_registry.get(
249
'Bazaar pack repository format 1 (needs bzr 0.92)\n'))]
250
no_vfs_scenarios = formats_to_scenarios(formats, "server", "readonly",
252
vfs_scenarios = formats_to_scenarios(formats, "server", "readonly",
253
vfs_transport_factory="vfs")
254
# no_vfs generate scenarios without vfs_transport_factory
256
('RemoteRepositoryFormat(c)',
257
{'bzrdir_format': remote.RemoteBzrDirFormat(),
258
'repository_format': remote.RemoteRepositoryFormat(),
259
'transport_readonly_server': 'readonly',
260
'transport_server': 'server'}),
261
('RepositoryFormatKnitPack1(d)',
262
{'bzrdir_format': bzrdir.BzrDirMetaFormat1(),
263
'repository_format': pack_repo.RepositoryFormatKnitPack1(),
264
'transport_readonly_server': 'readonly',
265
'transport_server': 'server'})],
268
('RemoteRepositoryFormat(c)',
269
{'bzrdir_format': remote.RemoteBzrDirFormat(),
270
'repository_format': remote.RemoteRepositoryFormat(),
271
'transport_readonly_server': 'readonly',
272
'transport_server': 'server',
273
'vfs_transport_factory': 'vfs'}),
274
('RepositoryFormatKnitPack1(d)',
275
{'bzrdir_format': bzrdir.BzrDirMetaFormat1(),
276
'repository_format': pack_repo.RepositoryFormatKnitPack1(),
277
'transport_readonly_server': 'readonly',
278
'transport_server': 'server',
279
'vfs_transport_factory': 'vfs'})],
283
class TestTestScenarioApplication(TestCase):
284
"""Tests for the test adaption facilities."""
286
def test_apply_scenario(self):
287
from bzrlib.tests import apply_scenario
288
input_test = TestTestScenarioApplication("test_apply_scenario")
289
# setup two adapted tests
290
adapted_test1 = apply_scenario(input_test,
292
{"bzrdir_format":"bzr_format",
293
"repository_format":"repo_fmt",
294
"transport_server":"transport_server",
295
"transport_readonly_server":"readonly-server"}))
296
adapted_test2 = apply_scenario(input_test,
297
("new id 2", {"bzrdir_format":None}))
298
# input_test should have been altered.
299
self.assertRaises(AttributeError, getattr, input_test, "bzrdir_format")
300
# the new tests are mutually incompatible, ensuring it has
301
# made new ones, and unspecified elements in the scenario
302
# should not have been altered.
303
self.assertEqual("bzr_format", adapted_test1.bzrdir_format)
304
self.assertEqual("repo_fmt", adapted_test1.repository_format)
305
self.assertEqual("transport_server", adapted_test1.transport_server)
306
self.assertEqual("readonly-server",
307
adapted_test1.transport_readonly_server)
309
"bzrlib.tests.test_selftest.TestTestScenarioApplication."
310
"test_apply_scenario(new id)",
312
self.assertEqual(None, adapted_test2.bzrdir_format)
314
"bzrlib.tests.test_selftest.TestTestScenarioApplication."
315
"test_apply_scenario(new id 2)",
319
class TestInterRepositoryScenarios(TestCase):
321
def test_scenarios(self):
322
# check that constructor parameters are passed through to the adapted
324
from bzrlib.tests.interrepository_implementations import \
328
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
329
scenarios = make_scenarios(server1, server2, formats)
332
{'interrepo_class': str,
333
'repository_format': 'C1',
334
'repository_format_to': 'C2',
335
'transport_readonly_server': 'b',
336
'transport_server': 'a'}),
338
{'interrepo_class': int,
339
'repository_format': 'D1',
340
'repository_format_to': 'D2',
341
'transport_readonly_server': 'b',
342
'transport_server': 'a'})],
346
class TestWorkingTreeScenarios(TestCase):
348
def test_scenarios(self):
349
# check that constructor parameters are passed through to the adapted
351
from bzrlib.tests.workingtree_implementations \
352
import make_scenarios
355
formats = [workingtree.WorkingTreeFormat2(),
356
workingtree.WorkingTreeFormat3(),]
357
scenarios = make_scenarios(server1, server2, formats)
359
('WorkingTreeFormat2',
360
{'bzrdir_format': formats[0]._matchingbzrdir,
361
'transport_readonly_server': 'b',
362
'transport_server': 'a',
363
'workingtree_format': formats[0]}),
364
('WorkingTreeFormat3',
365
{'bzrdir_format': formats[1]._matchingbzrdir,
366
'transport_readonly_server': 'b',
367
'transport_server': 'a',
368
'workingtree_format': formats[1]})],
372
class TestTreeScenarios(TestCase):
374
def test_scenarios(self):
375
# the tree implementation scenario generator is meant to setup one
376
# instance for each working tree format, and one additional instance
377
# that will use the default wt format, but create a revision tree for
378
# the tests. this means that the wt ones should have the
379
# workingtree_to_test_tree attribute set to 'return_parameter' and the
380
# revision one set to revision_tree_from_workingtree.
198
adapter = BzrDirTestProviderAdapter(server1, server2, formats)
199
suite = adapter.adapt(input_test)
200
tests = list(iter(suite))
201
self.assertEqual(2, len(tests))
202
self.assertEqual(tests[0].bzrdir_format, formats[0])
203
self.assertEqual(tests[0].transport_server, server1)
204
self.assertEqual(tests[0].transport_readonly_server, server2)
205
self.assertEqual(tests[1].bzrdir_format, formats[1])
206
self.assertEqual(tests[1].transport_server, server1)
207
self.assertEqual(tests[1].transport_readonly_server, server2)
210
class TestRepositoryProviderAdapter(TestCase):
211
"""A group of tests that test the repository implementation test adapter."""
213
def test_adapted_tests(self):
214
# check that constructor parameters are passed through to the adapted
216
from bzrlib.repository import RepositoryTestProviderAdapter
217
input_test = TestRepositoryProviderAdapter(
218
"test_adapted_tests")
221
formats = [("c", "C"), ("d", "D")]
222
adapter = RepositoryTestProviderAdapter(server1, server2, formats)
223
suite = adapter.adapt(input_test)
224
tests = list(iter(suite))
225
self.assertEqual(2, len(tests))
226
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
227
self.assertEqual(tests[0].repository_format, formats[0][0])
228
self.assertEqual(tests[0].transport_server, server1)
229
self.assertEqual(tests[0].transport_readonly_server, server2)
230
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
231
self.assertEqual(tests[1].repository_format, formats[1][0])
232
self.assertEqual(tests[1].transport_server, server1)
233
self.assertEqual(tests[1].transport_readonly_server, server2)
236
class TestInterRepositoryProviderAdapter(TestCase):
237
"""A group of tests that test the InterRepository test adapter."""
239
def test_adapted_tests(self):
240
# check that constructor parameters are passed through to the adapted
242
from bzrlib.repository import InterRepositoryTestProviderAdapter
243
input_test = TestInterRepositoryProviderAdapter(
244
"test_adapted_tests")
247
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
248
adapter = InterRepositoryTestProviderAdapter(server1, server2, formats)
249
suite = adapter.adapt(input_test)
250
tests = list(iter(suite))
251
self.assertEqual(2, len(tests))
252
self.assertEqual(tests[0].interrepo_class, formats[0][0])
253
self.assertEqual(tests[0].repository_format, formats[0][1])
254
self.assertEqual(tests[0].repository_format_to, formats[0][2])
255
self.assertEqual(tests[0].transport_server, server1)
256
self.assertEqual(tests[0].transport_readonly_server, server2)
257
self.assertEqual(tests[1].interrepo_class, formats[1][0])
258
self.assertEqual(tests[1].repository_format, formats[1][1])
259
self.assertEqual(tests[1].repository_format_to, formats[1][2])
260
self.assertEqual(tests[1].transport_server, server1)
261
self.assertEqual(tests[1].transport_readonly_server, server2)
264
class TestInterVersionedFileProviderAdapter(TestCase):
265
"""A group of tests that test the InterVersionedFile test adapter."""
267
def test_adapted_tests(self):
268
# check that constructor parameters are passed through to the adapted
270
from bzrlib.versionedfile import InterVersionedFileTestProviderAdapter
271
input_test = TestInterRepositoryProviderAdapter(
272
"test_adapted_tests")
275
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
276
adapter = InterVersionedFileTestProviderAdapter(server1, server2, formats)
277
suite = adapter.adapt(input_test)
278
tests = list(iter(suite))
279
self.assertEqual(2, len(tests))
280
self.assertEqual(tests[0].interversionedfile_class, formats[0][0])
281
self.assertEqual(tests[0].versionedfile_factory, formats[0][1])
282
self.assertEqual(tests[0].versionedfile_factory_to, formats[0][2])
283
self.assertEqual(tests[0].transport_server, server1)
284
self.assertEqual(tests[0].transport_readonly_server, server2)
285
self.assertEqual(tests[1].interversionedfile_class, formats[1][0])
286
self.assertEqual(tests[1].versionedfile_factory, formats[1][1])
287
self.assertEqual(tests[1].versionedfile_factory_to, formats[1][2])
288
self.assertEqual(tests[1].transport_server, server1)
289
self.assertEqual(tests[1].transport_readonly_server, server2)
292
class TestRevisionStoreProviderAdapter(TestCase):
293
"""A group of tests that test the RevisionStore test adapter."""
295
def test_adapted_tests(self):
296
# check that constructor parameters are passed through to the adapted
298
from bzrlib.store.revision import RevisionStoreTestProviderAdapter
299
input_test = TestRevisionStoreProviderAdapter(
300
"test_adapted_tests")
301
# revision stores need a store factory - i.e. RevisionKnit
302
#, a readonly and rw transport
306
store_factories = ["c", "d"]
307
adapter = RevisionStoreTestProviderAdapter(server1, server2, store_factories)
308
suite = adapter.adapt(input_test)
309
tests = list(iter(suite))
310
self.assertEqual(2, len(tests))
311
self.assertEqual(tests[0].store_factory, store_factories[0][0])
312
self.assertEqual(tests[0].transport_server, server1)
313
self.assertEqual(tests[0].transport_readonly_server, server2)
314
self.assertEqual(tests[1].store_factory, store_factories[1][0])
315
self.assertEqual(tests[1].transport_server, server1)
316
self.assertEqual(tests[1].transport_readonly_server, server2)
319
class TestWorkingTreeProviderAdapter(TestCase):
320
"""A group of tests that test the workingtree implementation test adapter."""
322
def test_adapted_tests(self):
323
# check that constructor parameters are passed through to the adapted
325
from bzrlib.workingtree import WorkingTreeTestProviderAdapter
326
input_test = TestWorkingTreeProviderAdapter(
327
"test_adapted_tests")
330
formats = [("c", "C"), ("d", "D")]
331
adapter = WorkingTreeTestProviderAdapter(server1, server2, formats)
332
suite = adapter.adapt(input_test)
333
tests = list(iter(suite))
334
self.assertEqual(2, len(tests))
335
self.assertEqual(tests[0].workingtree_format, formats[0][0])
336
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
337
self.assertEqual(tests[0].transport_server, server1)
338
self.assertEqual(tests[0].transport_readonly_server, server2)
339
self.assertEqual(tests[1].workingtree_format, formats[1][0])
340
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
341
self.assertEqual(tests[1].transport_server, server1)
342
self.assertEqual(tests[1].transport_readonly_server, server2)
345
class TestTreeProviderAdapter(TestCase):
346
"""Test the setup of tree_implementation tests."""
348
def test_adapted_tests(self):
349
# the tree implementation adapter is meant to setup one instance for
350
# each working tree format, and one additional instance that will
351
# use the default wt format, but create a revision tree for the tests.
352
# this means that the wt ones should have the workingtree_to_test_tree
353
# attribute set to 'return_parameter' and the revision one set to
354
# revision_tree_from_workingtree.
382
356
from bzrlib.tests.tree_implementations import (
383
_dirstate_tree_from_workingtree,
357
TreeTestProviderAdapter,
387
358
return_parameter,
388
359
revision_tree_from_workingtree
361
from bzrlib.workingtree import WorkingTreeFormat, WorkingTreeFormat3
362
input_test = TestTreeProviderAdapter(
363
"test_adapted_tests")
392
formats = [workingtree.WorkingTreeFormat2(),
393
workingtree.WorkingTreeFormat3(),]
394
scenarios = make_scenarios(server1, server2, formats)
395
self.assertEqual(7, len(scenarios))
396
default_wt_format = workingtree.WorkingTreeFormat4._default_format
397
wt4_format = workingtree.WorkingTreeFormat4()
398
wt5_format = workingtree.WorkingTreeFormat5()
399
expected_scenarios = [
400
('WorkingTreeFormat2',
401
{'bzrdir_format': formats[0]._matchingbzrdir,
402
'transport_readonly_server': 'b',
403
'transport_server': 'a',
404
'workingtree_format': formats[0],
405
'_workingtree_to_test_tree': return_parameter,
407
('WorkingTreeFormat3',
408
{'bzrdir_format': formats[1]._matchingbzrdir,
409
'transport_readonly_server': 'b',
410
'transport_server': 'a',
411
'workingtree_format': formats[1],
412
'_workingtree_to_test_tree': return_parameter,
415
{'_workingtree_to_test_tree': revision_tree_from_workingtree,
416
'bzrdir_format': default_wt_format._matchingbzrdir,
417
'transport_readonly_server': 'b',
418
'transport_server': 'a',
419
'workingtree_format': default_wt_format,
421
('DirStateRevisionTree,WT4',
422
{'_workingtree_to_test_tree': _dirstate_tree_from_workingtree,
423
'bzrdir_format': wt4_format._matchingbzrdir,
424
'transport_readonly_server': 'b',
425
'transport_server': 'a',
426
'workingtree_format': wt4_format,
428
('DirStateRevisionTree,WT5',
429
{'_workingtree_to_test_tree': _dirstate_tree_from_workingtree,
430
'bzrdir_format': wt5_format._matchingbzrdir,
431
'transport_readonly_server': 'b',
432
'transport_server': 'a',
433
'workingtree_format': wt5_format,
436
{'_workingtree_to_test_tree': preview_tree_pre,
437
'bzrdir_format': default_wt_format._matchingbzrdir,
438
'transport_readonly_server': 'b',
439
'transport_server': 'a',
440
'workingtree_format': default_wt_format}),
442
{'_workingtree_to_test_tree': preview_tree_post,
443
'bzrdir_format': default_wt_format._matchingbzrdir,
444
'transport_readonly_server': 'b',
445
'transport_server': 'a',
446
'workingtree_format': default_wt_format}),
448
self.assertEqual(expected_scenarios, scenarios)
451
class TestInterTreeScenarios(TestCase):
366
formats = [("c", "C"), ("d", "D")]
367
adapter = TreeTestProviderAdapter(server1, server2, formats)
368
suite = adapter.adapt(input_test)
369
tests = list(iter(suite))
370
self.assertEqual(4, len(tests))
371
# this must match the default format setp up in
372
# TreeTestProviderAdapter.adapt
373
default_format = WorkingTreeFormat3
374
self.assertEqual(tests[0].workingtree_format, formats[0][0])
375
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
376
self.assertEqual(tests[0].transport_server, server1)
377
self.assertEqual(tests[0].transport_readonly_server, server2)
378
self.assertEqual(tests[0].workingtree_to_test_tree, return_parameter)
379
self.assertEqual(tests[1].workingtree_format, formats[1][0])
380
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
381
self.assertEqual(tests[1].transport_server, server1)
382
self.assertEqual(tests[1].transport_readonly_server, server2)
383
self.assertEqual(tests[1].workingtree_to_test_tree, return_parameter)
384
self.assertIsInstance(tests[2].workingtree_format, default_format)
385
#self.assertEqual(tests[2].bzrdir_format,
386
# default_format._matchingbzrdir)
387
self.assertEqual(tests[2].transport_server, server1)
388
self.assertEqual(tests[2].transport_readonly_server, server2)
389
self.assertEqual(tests[2].workingtree_to_test_tree,
390
revision_tree_from_workingtree)
393
class TestInterTreeProviderAdapter(TestCase):
452
394
"""A group of tests that test the InterTreeTestAdapter."""
454
def test_scenarios(self):
396
def test_adapted_tests(self):
455
397
# check that constructor parameters are passed through to the adapted
457
399
# for InterTree tests we want the machinery to bring up two trees in
1901
1469
feature = Feature()
1902
1470
exception = UnavailableFeature(feature)
1903
1471
self.assertIs(feature, exception.args[0])
1906
class TestSelftestFiltering(TestCase):
1909
TestCase.setUp(self)
1910
self.suite = TestUtil.TestSuite()
1911
self.loader = TestUtil.TestLoader()
1912
self.suite.addTest(self.loader.loadTestsFromModuleNames([
1913
'bzrlib.tests.test_selftest']))
1914
self.all_names = _test_ids(self.suite)
1916
def test_condition_id_re(self):
1917
test_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1918
'test_condition_id_re')
1919
filtered_suite = filter_suite_by_condition(self.suite,
1920
condition_id_re('test_condition_id_re'))
1921
self.assertEqual([test_name], _test_ids(filtered_suite))
1923
def test_condition_id_in_list(self):
1924
test_names = ['bzrlib.tests.test_selftest.TestSelftestFiltering.'
1925
'test_condition_id_in_list']
1926
id_list = tests.TestIdList(test_names)
1927
filtered_suite = filter_suite_by_condition(
1928
self.suite, tests.condition_id_in_list(id_list))
1929
my_pattern = 'TestSelftestFiltering.*test_condition_id_in_list'
1930
re_filtered = filter_suite_by_re(self.suite, my_pattern)
1931
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1933
def test_condition_id_startswith(self):
1934
klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1935
start1 = klass + 'test_condition_id_starts'
1936
start2 = klass + 'test_condition_id_in'
1937
test_names = [ klass + 'test_condition_id_in_list',
1938
klass + 'test_condition_id_startswith',
1940
filtered_suite = filter_suite_by_condition(
1941
self.suite, tests.condition_id_startswith([start1, start2]))
1942
self.assertEqual(test_names, _test_ids(filtered_suite))
1944
def test_condition_isinstance(self):
1945
filtered_suite = filter_suite_by_condition(self.suite,
1946
condition_isinstance(self.__class__))
1947
class_pattern = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1948
re_filtered = filter_suite_by_re(self.suite, class_pattern)
1949
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1951
def test_exclude_tests_by_condition(self):
1952
excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1953
'test_exclude_tests_by_condition')
1954
filtered_suite = exclude_tests_by_condition(self.suite,
1955
lambda x:x.id() == excluded_name)
1956
self.assertEqual(len(self.all_names) - 1,
1957
filtered_suite.countTestCases())
1958
self.assertFalse(excluded_name in _test_ids(filtered_suite))
1959
remaining_names = list(self.all_names)
1960
remaining_names.remove(excluded_name)
1961
self.assertEqual(remaining_names, _test_ids(filtered_suite))
1963
def test_exclude_tests_by_re(self):
1964
self.all_names = _test_ids(self.suite)
1965
filtered_suite = exclude_tests_by_re(self.suite, 'exclude_tests_by_re')
1966
excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1967
'test_exclude_tests_by_re')
1968
self.assertEqual(len(self.all_names) - 1,
1969
filtered_suite.countTestCases())
1970
self.assertFalse(excluded_name in _test_ids(filtered_suite))
1971
remaining_names = list(self.all_names)
1972
remaining_names.remove(excluded_name)
1973
self.assertEqual(remaining_names, _test_ids(filtered_suite))
1975
def test_filter_suite_by_condition(self):
1976
test_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1977
'test_filter_suite_by_condition')
1978
filtered_suite = filter_suite_by_condition(self.suite,
1979
lambda x:x.id() == test_name)
1980
self.assertEqual([test_name], _test_ids(filtered_suite))
1982
def test_filter_suite_by_re(self):
1983
filtered_suite = filter_suite_by_re(self.suite, 'test_filter_suite_by_r')
1984
filtered_names = _test_ids(filtered_suite)
1985
self.assertEqual(filtered_names, ['bzrlib.tests.test_selftest.'
1986
'TestSelftestFiltering.test_filter_suite_by_re'])
1988
def test_filter_suite_by_id_list(self):
1989
test_list = ['bzrlib.tests.test_selftest.'
1990
'TestSelftestFiltering.test_filter_suite_by_id_list']
1991
filtered_suite = tests.filter_suite_by_id_list(
1992
self.suite, tests.TestIdList(test_list))
1993
filtered_names = _test_ids(filtered_suite)
1996
['bzrlib.tests.test_selftest.'
1997
'TestSelftestFiltering.test_filter_suite_by_id_list'])
1999
def test_filter_suite_by_id_startswith(self):
2000
# By design this test may fail if another test is added whose name also
2001
# begins with one of the start value used.
2002
klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
2003
start1 = klass + 'test_filter_suite_by_id_starts'
2004
start2 = klass + 'test_filter_suite_by_id_li'
2005
test_list = [klass + 'test_filter_suite_by_id_list',
2006
klass + 'test_filter_suite_by_id_startswith',
2008
filtered_suite = tests.filter_suite_by_id_startswith(
2009
self.suite, [start1, start2])
2012
_test_ids(filtered_suite),
2015
def test_preserve_input(self):
2016
# NB: Surely this is something in the stdlib to do this?
2017
self.assertTrue(self.suite is preserve_input(self.suite))
2018
self.assertTrue("@#$" is preserve_input("@#$"))
2020
def test_randomize_suite(self):
2021
randomized_suite = randomize_suite(self.suite)
2022
# randomizing should not add or remove test names.
2023
self.assertEqual(set(_test_ids(self.suite)),
2024
set(_test_ids(randomized_suite)))
2025
# Technically, this *can* fail, because random.shuffle(list) can be
2026
# equal to list. Trying multiple times just pushes the frequency back.
2027
# As its len(self.all_names)!:1, the failure frequency should be low
2028
# enough to ignore. RBC 20071021.
2029
# It should change the order.
2030
self.assertNotEqual(self.all_names, _test_ids(randomized_suite))
2031
# But not the length. (Possibly redundant with the set test, but not
2033
self.assertEqual(len(self.all_names), len(_test_ids(randomized_suite)))
2035
def test_split_suit_by_condition(self):
2036
self.all_names = _test_ids(self.suite)
2037
condition = condition_id_re('test_filter_suite_by_r')
2038
split_suite = split_suite_by_condition(self.suite, condition)
2039
filtered_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
2040
'test_filter_suite_by_re')
2041
self.assertEqual([filtered_name], _test_ids(split_suite[0]))
2042
self.assertFalse(filtered_name in _test_ids(split_suite[1]))
2043
remaining_names = list(self.all_names)
2044
remaining_names.remove(filtered_name)
2045
self.assertEqual(remaining_names, _test_ids(split_suite[1]))
2047
def test_split_suit_by_re(self):
2048
self.all_names = _test_ids(self.suite)
2049
split_suite = split_suite_by_re(self.suite, 'test_filter_suite_by_r')
2050
filtered_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
2051
'test_filter_suite_by_re')
2052
self.assertEqual([filtered_name], _test_ids(split_suite[0]))
2053
self.assertFalse(filtered_name in _test_ids(split_suite[1]))
2054
remaining_names = list(self.all_names)
2055
remaining_names.remove(filtered_name)
2056
self.assertEqual(remaining_names, _test_ids(split_suite[1]))
2059
class TestCheckInventoryShape(TestCaseWithTransport):
2061
def test_check_inventory_shape(self):
2062
files = ['a', 'b/', 'b/c']
2063
tree = self.make_branch_and_tree('.')
2064
self.build_tree(files)
2068
self.check_inventory_shape(tree.inventory, files)
2073
class TestBlackboxSupport(TestCase):
2074
"""Tests for testsuite blackbox features."""
2076
def test_run_bzr_failure_not_caught(self):
2077
# When we run bzr in blackbox mode, we want any unexpected errors to
2078
# propagate up to the test suite so that it can show the error in the
2079
# usual way, and we won't get a double traceback.
2080
e = self.assertRaises(
2082
self.run_bzr, ['assert-fail'])
2083
# make sure we got the real thing, not an error from somewhere else in
2084
# the test framework
2085
self.assertEquals('always fails', str(e))
2086
# check that there's no traceback in the test log
2087
self.assertNotContainsRe(self._get_log(keep_log_file=True),
2090
def test_run_bzr_user_error_caught(self):
2091
# Running bzr in blackbox mode, normal/expected/user errors should be
2092
# caught in the regular way and turned into an error message plus exit
2094
out, err = self.run_bzr(["log", "/nonexistantpath"], retcode=3)
2095
self.assertEqual(out, '')
2096
self.assertContainsRe(err,
2097
'bzr: ERROR: Not a branch: ".*nonexistantpath/".\n')
2100
class TestTestLoader(TestCase):
2101
"""Tests for the test loader."""
2103
def _get_loader_and_module(self):
2104
"""Gets a TestLoader and a module with one test in it."""
2105
loader = TestUtil.TestLoader()
2107
class Stub(TestCase):
2110
class MyModule(object):
2112
MyModule.a_class = Stub
2114
return loader, module
2116
def test_module_no_load_tests_attribute_loads_classes(self):
2117
loader, module = self._get_loader_and_module()
2118
self.assertEqual(1, loader.loadTestsFromModule(module).countTestCases())
2120
def test_module_load_tests_attribute_gets_called(self):
2121
loader, module = self._get_loader_and_module()
2122
# 'self' is here because we're faking the module with a class. Regular
2123
# load_tests do not need that :)
2124
def load_tests(self, standard_tests, module, loader):
2125
result = loader.suiteClass()
2126
for test in iter_suite_tests(standard_tests):
2127
result.addTests([test, test])
2129
# add a load_tests() method which multiplies the tests from the module.
2130
module.__class__.load_tests = load_tests
2131
self.assertEqual(2, loader.loadTestsFromModule(module).countTestCases())
2133
def test_load_tests_from_module_name_smoke_test(self):
2134
loader = TestUtil.TestLoader()
2135
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2136
self.assertEquals(['bzrlib.tests.test_sampler.DemoTest.test_nothing'],
2139
def test_load_tests_from_module_name_with_bogus_module_name(self):
2140
loader = TestUtil.TestLoader()
2141
self.assertRaises(ImportError, loader.loadTestsFromModuleName, 'bogus')
2144
class TestTestIdList(tests.TestCase):
2146
def _create_id_list(self, test_list):
2147
return tests.TestIdList(test_list)
2149
def _create_suite(self, test_id_list):
2151
class Stub(TestCase):
2155
def _create_test_id(id):
2158
suite = TestUtil.TestSuite()
2159
for id in test_id_list:
2160
t = Stub('test_foo')
2161
t.id = _create_test_id(id)
2165
def _test_ids(self, test_suite):
2166
"""Get the ids for the tests in a test suite."""
2167
return [t.id() for t in iter_suite_tests(test_suite)]
2169
def test_empty_list(self):
2170
id_list = self._create_id_list([])
2171
self.assertEquals({}, id_list.tests)
2172
self.assertEquals({}, id_list.modules)
2174
def test_valid_list(self):
2175
id_list = self._create_id_list(
2176
['mod1.cl1.meth1', 'mod1.cl1.meth2',
2177
'mod1.func1', 'mod1.cl2.meth2',
2179
'mod1.submod2.cl1.meth1', 'mod1.submod2.cl2.meth2',
2181
self.assertTrue(id_list.refers_to('mod1'))
2182
self.assertTrue(id_list.refers_to('mod1.submod1'))
2183
self.assertTrue(id_list.refers_to('mod1.submod2'))
2184
self.assertTrue(id_list.includes('mod1.cl1.meth1'))
2185
self.assertTrue(id_list.includes('mod1.submod1'))
2186
self.assertTrue(id_list.includes('mod1.func1'))
2188
def test_bad_chars_in_params(self):
2189
id_list = self._create_id_list(['mod1.cl1.meth1(xx.yy)'])
2190
self.assertTrue(id_list.refers_to('mod1'))
2191
self.assertTrue(id_list.includes('mod1.cl1.meth1(xx.yy)'))
2193
def test_module_used(self):
2194
id_list = self._create_id_list(['mod.class.meth'])
2195
self.assertTrue(id_list.refers_to('mod'))
2196
self.assertTrue(id_list.refers_to('mod.class'))
2197
self.assertTrue(id_list.refers_to('mod.class.meth'))
2199
def test_test_suite(self):
2200
# This test is slow, so we do a single test with one test in each
2204
'bzrlib.tests.blackbox.test_branch.TestBranch.test_branch',
2205
'bzrlib.tests.test_selftest.TestTestIdList.test_test_suite',
2206
# transport implementations
2207
'bzrlib.tests.test_transport_implementations.TransportTests'
2208
'.test_abspath(LocalURLServer)',
2209
# modules_to_doctest
2210
'bzrlib.timestamp.format_highres_date',
2211
# plugins can't be tested that way since selftest may be run with
2214
suite = tests.test_suite(test_list)
2215
self.assertEquals(test_list, _test_ids(suite))
2217
def test_test_suite_matches_id_list_with_unknown(self):
2218
loader = TestUtil.TestLoader()
2219
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2220
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing',
2222
not_found, duplicates = tests.suite_matches_id_list(suite, test_list)
2223
self.assertEquals(['bogus'], not_found)
2224
self.assertEquals([], duplicates)
2226
def test_suite_matches_id_list_with_duplicates(self):
2227
loader = TestUtil.TestLoader()
2228
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2229
dupes = loader.suiteClass()
2230
for test in iter_suite_tests(suite):
2232
dupes.addTest(test) # Add it again
2234
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing',]
2235
not_found, duplicates = tests.suite_matches_id_list(
2237
self.assertEquals([], not_found)
2238
self.assertEquals(['bzrlib.tests.test_sampler.DemoTest.test_nothing'],
2242
class TestLoadTestIdList(tests.TestCaseInTempDir):
2244
def _create_test_list_file(self, file_name, content):
2245
fl = open(file_name, 'wt')
2249
def test_load_unknown(self):
2250
self.assertRaises(errors.NoSuchFile,
2251
tests.load_test_id_list, 'i_do_not_exist')
2253
def test_load_test_list(self):
2254
test_list_fname = 'test.list'
2255
self._create_test_list_file(test_list_fname,
2256
'mod1.cl1.meth1\nmod2.cl2.meth2\n')
2257
tlist = tests.load_test_id_list(test_list_fname)
2258
self.assertEquals(2, len(tlist))
2259
self.assertEquals('mod1.cl1.meth1', tlist[0])
2260
self.assertEquals('mod2.cl2.meth2', tlist[1])
2262
def test_load_dirty_file(self):
2263
test_list_fname = 'test.list'
2264
self._create_test_list_file(test_list_fname,
2265
' mod1.cl1.meth1\n\nmod2.cl2.meth2 \n'
2267
tlist = tests.load_test_id_list(test_list_fname)
2268
self.assertEquals(4, len(tlist))
2269
self.assertEquals('mod1.cl1.meth1', tlist[0])
2270
self.assertEquals('', tlist[1])
2271
self.assertEquals('mod2.cl2.meth2', tlist[2])
2272
self.assertEquals('bar baz', tlist[3])
2275
class TestFilteredByModuleTestLoader(tests.TestCase):
2277
def _create_loader(self, test_list):
2278
id_filter = tests.TestIdList(test_list)
2279
loader = TestUtil.FilteredByModuleTestLoader(id_filter.refers_to)
2282
def test_load_tests(self):
2283
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
2284
loader = self._create_loader(test_list)
2286
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2287
self.assertEquals(test_list, _test_ids(suite))
2289
def test_exclude_tests(self):
2290
test_list = ['bogus']
2291
loader = self._create_loader(test_list)
2293
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2294
self.assertEquals([], _test_ids(suite))
2297
class TestFilteredByNameStartTestLoader(tests.TestCase):
2299
def _create_loader(self, name_start):
2300
def needs_module(name):
2301
return name.startswith(name_start) or name_start.startswith(name)
2302
loader = TestUtil.FilteredByModuleTestLoader(needs_module)
2305
def test_load_tests(self):
2306
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
2307
loader = self._create_loader('bzrlib.tests.test_samp')
2309
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2310
self.assertEquals(test_list, _test_ids(suite))
2312
def test_load_tests_inside_module(self):
2313
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
2314
loader = self._create_loader('bzrlib.tests.test_sampler.Demo')
2316
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2317
self.assertEquals(test_list, _test_ids(suite))
2319
def test_exclude_tests(self):
2320
test_list = ['bogus']
2321
loader = self._create_loader('bogus')
2323
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2324
self.assertEquals([], _test_ids(suite))
2327
class TestTestPrefixRegistry(tests.TestCase):
2329
def _get_registry(self):
2330
tp_registry = tests.TestPrefixAliasRegistry()
2333
def test_register_new_prefix(self):
2334
tpr = self._get_registry()
2335
tpr.register('foo', 'fff.ooo.ooo')
2336
self.assertEquals('fff.ooo.ooo', tpr.get('foo'))
2338
def test_register_existing_prefix(self):
2339
tpr = self._get_registry()
2340
tpr.register('bar', 'bbb.aaa.rrr')
2341
tpr.register('bar', 'bBB.aAA.rRR')
2342
self.assertEquals('bbb.aaa.rrr', tpr.get('bar'))
2343
self.assertContainsRe(self._get_log(keep_log_file=True),
2344
r'.*bar.*bbb.aaa.rrr.*bBB.aAA.rRR')
2346
def test_get_unknown_prefix(self):
2347
tpr = self._get_registry()
2348
self.assertRaises(KeyError, tpr.get, 'I am not a prefix')
2350
def test_resolve_prefix(self):
2351
tpr = self._get_registry()
2352
tpr.register('bar', 'bb.aa.rr')
2353
self.assertEquals('bb.aa.rr', tpr.resolve_alias('bar'))
2355
def test_resolve_unknown_alias(self):
2356
tpr = self._get_registry()
2357
self.assertRaises(errors.BzrCommandError,
2358
tpr.resolve_alias, 'I am not a prefix')
2360
def test_predefined_prefixes(self):
2361
tpr = tests.test_prefix_alias_registry
2362
self.assertEquals('bzrlib', tpr.resolve_alias('bzrlib'))
2363
self.assertEquals('bzrlib.doc', tpr.resolve_alias('bd'))
2364
self.assertEquals('bzrlib.utils', tpr.resolve_alias('bu'))
2365
self.assertEquals('bzrlib.tests', tpr.resolve_alias('bt'))
2366
self.assertEquals('bzrlib.tests.blackbox', tpr.resolve_alias('bb'))
2367
self.assertEquals('bzrlib.plugins', tpr.resolve_alias('bp'))
2370
class TestRunSuite(TestCase):
2372
def test_runner_class(self):
2373
"""run_suite accepts and uses a runner_class keyword argument."""
2374
class Stub(TestCase):
2377
suite = Stub("test_foo")
2379
class MyRunner(TextTestRunner):
2380
def run(self, test):
2382
return ExtendedTestResult(self.stream, self.descriptions,
2384
run_suite(suite, runner_class=MyRunner, stream=StringIO())
2385
self.assertEqual(calls, [suite])
2387
def test_done(self):
2388
"""run_suite should call result.done()"""
2390
def one_more_call(): self.calls += 1
2391
def test_function():
2393
test = unittest.FunctionTestCase(test_function)
2394
class InstrumentedTestResult(ExtendedTestResult):
2395
def done(self): one_more_call()
2396
class MyRunner(TextTestRunner):
2397
def run(self, test):
2398
return InstrumentedTestResult(self.stream, self.descriptions,
2400
run_suite(test, runner_class=MyRunner, stream=StringIO())
2401
self.assertEquals(1, self.calls)