110
84
'a test message\n')
113
class TestUnicodeFilename(TestCase):
115
def test_probe_passes(self):
116
"""UnicodeFilename._probe passes."""
117
# We can't test much more than that because the behaviour depends
119
tests.UnicodeFilename._probe()
122
87
class TestTreeShape(TestCaseInTempDir):
124
89
def test_unicode_paths(self):
125
self.requireFeature(tests.UnicodeFilename)
127
90
filename = u'hell\u00d8'
128
self.build_tree_contents([(filename, 'contents of hello')])
92
self.build_tree_contents([(filename, 'contents of hello')])
93
except UnicodeEncodeError:
94
raise TestSkipped("can't build unicode working tree in "
95
"filesystem encoding %s" % sys.getfilesystemencoding())
129
96
self.failUnlessExists(filename)
132
class TestTransportScenarios(TestCase):
99
class TestTransportProviderAdapter(TestCase):
133
100
"""A group of tests that test the transport implementation adaption core.
135
This is a meta test that the tests are applied to all available
102
This is a meta test that the tests are applied to all available
138
This will be generalised in the future which is why it is in this
105
This will be generalised in the future which is why it is in this
139
106
test file even though it is specific to transport tests at the moment.
142
109
def test_get_transport_permutations(self):
143
# this checks that get_test_permutations defined by the module is
144
# called by the get_transport_test_permutations function.
110
# this checks that we the module get_test_permutations call
111
# is made by the adapter get_transport_test_permitations method.
145
112
class MockModule(object):
146
113
def get_test_permutations(self):
147
114
return sample_permutation
148
115
sample_permutation = [(1,2), (3,4)]
149
116
from bzrlib.tests.test_transport_implementations \
150
import get_transport_test_permutations
117
import TransportTestProviderAdapter
118
adapter = TransportTestProviderAdapter()
151
119
self.assertEqual(sample_permutation,
152
get_transport_test_permutations(MockModule()))
120
adapter.get_transport_test_permutations(MockModule()))
154
def test_scenarios_invlude_all_modules(self):
155
# this checks that the scenario generator returns as many permutations
156
# as there are in all the registered transport modules - we assume if
157
# this matches its probably doing the right thing especially in
158
# combination with the tests for setting the right classes below.
122
def test_adapter_checks_all_modules(self):
123
# this checks that the adapter returns as many permurtations as
124
# there are in all the registered# transport modules for there
125
# - we assume if this matches its probably doing the right thing
126
# especially in combination with the tests for setting the right
159
128
from bzrlib.tests.test_transport_implementations \
160
import transport_test_permutations
129
import TransportTestProviderAdapter
161
130
from bzrlib.transport import _get_transport_modules
162
131
modules = _get_transport_modules()
163
132
permutation_count = 0
164
133
for module in modules:
166
permutation_count += len(reduce(getattr,
135
permutation_count += len(reduce(getattr,
167
136
(module + ".get_test_permutations").split('.')[1:],
168
137
__import__(module))())
169
138
except errors.DependencyNotPresent:
171
scenarios = transport_test_permutations()
172
self.assertEqual(permutation_count, len(scenarios))
140
input_test = TestTransportProviderAdapter(
141
"test_adapter_sets_transport_class")
142
adapter = TransportTestProviderAdapter()
143
self.assertEqual(permutation_count,
144
len(list(iter(adapter.adapt(input_test)))))
174
def test_scenarios_include_transport_class(self):
146
def test_adapter_sets_transport_class(self):
147
# Check that the test adapter inserts a transport and server into the
175
150
# This test used to know about all the possible transports and the
176
151
# order they were returned but that seems overly brittle (mbp
178
153
from bzrlib.tests.test_transport_implementations \
179
import transport_test_permutations
180
scenarios = transport_test_permutations()
154
import TransportTestProviderAdapter
155
scenarios = TransportTestProviderAdapter().scenarios
181
156
# there are at least that many builtin transports
182
157
self.assertTrue(len(scenarios) > 6)
183
158
one_scenario = scenarios[0]
235
213
'transport_readonly_server': 'b',
236
214
'transport_server': 'a',
237
215
'vfs_transport_factory': 'v'})],
241
class TestRepositoryScenarios(TestCase):
219
class TestRepositoryProviderAdapter(TestCase):
220
"""A group of tests that test the repository implementation test adapter."""
222
def test_constructor(self):
223
# check that constructor parameters are passed through to the
225
from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
228
formats = [("c", "C"), ("d", "D")]
229
adapter = RepositoryTestProviderAdapter(server1, server2, formats)
232
{'bzrdir_format': 'C',
233
'repository_format': 'c',
234
'transport_readonly_server': 'b',
235
'transport_server': 'a'}),
237
{'bzrdir_format': 'D',
238
'repository_format': 'd',
239
'transport_readonly_server': 'b',
240
'transport_server': 'a'})],
243
def test_setting_vfs_transport(self):
244
"""The vfs_transport_factory can be set optionally."""
245
from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
246
formats = [("a", "b"), ("c", "d")]
247
adapter = RepositoryTestProviderAdapter(None, None, formats,
248
vfs_transport_factory="vfs")
251
{'bzrdir_format': 'b',
252
'repository_format': 'a',
253
'transport_readonly_server': None,
254
'transport_server': None,
255
'vfs_transport_factory': 'vfs'}),
257
{'bzrdir_format': 'd',
258
'repository_format': 'c',
259
'transport_readonly_server': None,
260
'transport_server': None,
261
'vfs_transport_factory': 'vfs'})],
243
264
def test_formats_to_scenarios(self):
244
from bzrlib.tests.per_repository import formats_to_scenarios
245
formats = [("(c)", remote.RemoteRepositoryFormat()),
246
("(d)", repository.format_registry.get(
247
'Bazaar pack repository format 1 (needs bzr 0.92)\n'))]
248
no_vfs_scenarios = formats_to_scenarios(formats, "server", "readonly",
250
vfs_scenarios = formats_to_scenarios(formats, "server", "readonly",
251
vfs_transport_factory="vfs")
252
# no_vfs generate scenarios without vfs_transport_factory
265
"""The adapter can generate all the scenarios needed."""
266
from bzrlib.tests.repository_implementations import RepositoryTestProviderAdapter
267
no_vfs_adapter = RepositoryTestProviderAdapter("server", "readonly",
269
vfs_adapter = RepositoryTestProviderAdapter("server", "readonly",
270
[], vfs_transport_factory="vfs")
271
# no_vfs generate scenarios without vfs_transport_factor
272
formats = [("c", "C"), (1, "D")]
253
273
self.assertEqual([
254
('RemoteRepositoryFormat(c)',
255
{'bzrdir_format': remote.RemoteBzrDirFormat(),
256
'repository_format': remote.RemoteRepositoryFormat(),
275
{'bzrdir_format': 'C',
276
'repository_format': 'c',
257
277
'transport_readonly_server': 'readonly',
258
278
'transport_server': 'server'}),
259
('RepositoryFormatKnitPack1(d)',
260
{'bzrdir_format': bzrdir.BzrDirMetaFormat1(),
261
'repository_format': pack_repo.RepositoryFormatKnitPack1(),
280
{'bzrdir_format': 'D',
281
'repository_format': 1,
262
282
'transport_readonly_server': 'readonly',
263
283
'transport_server': 'server'})],
284
no_vfs_adapter.formats_to_scenarios(formats))
265
285
self.assertEqual([
266
('RemoteRepositoryFormat(c)',
267
{'bzrdir_format': remote.RemoteBzrDirFormat(),
268
'repository_format': remote.RemoteRepositoryFormat(),
287
{'bzrdir_format': 'C',
288
'repository_format': 'c',
269
289
'transport_readonly_server': 'readonly',
270
290
'transport_server': 'server',
271
291
'vfs_transport_factory': 'vfs'}),
272
('RepositoryFormatKnitPack1(d)',
273
{'bzrdir_format': bzrdir.BzrDirMetaFormat1(),
274
'repository_format': pack_repo.RepositoryFormatKnitPack1(),
293
{'bzrdir_format': 'D',
294
'repository_format': 1,
275
295
'transport_readonly_server': 'readonly',
276
296
'transport_server': 'server',
277
297
'vfs_transport_factory': 'vfs'})],
281
class TestTestScenarioApplication(TestCase):
298
vfs_adapter.formats_to_scenarios(formats))
301
class TestTestScenarioApplier(TestCase):
282
302
"""Tests for the test adaption facilities."""
284
def test_apply_scenario(self):
285
from bzrlib.tests import apply_scenario
286
input_test = TestTestScenarioApplication("test_apply_scenario")
304
def test_adapt_applies_scenarios(self):
305
from bzrlib.tests.repository_implementations import TestScenarioApplier
306
input_test = TestTestScenarioApplier("test_adapt_test_to_scenario")
307
adapter = TestScenarioApplier()
308
adapter.scenarios = [("1", "dict"), ("2", "settings")]
310
def capture_call(test, scenario):
311
calls.append((test, scenario))
313
adapter.adapt_test_to_scenario = capture_call
314
adapter.adapt(input_test)
315
self.assertEqual([(input_test, ("1", "dict")),
316
(input_test, ("2", "settings"))], calls)
318
def test_adapt_test_to_scenario(self):
319
from bzrlib.tests.repository_implementations import TestScenarioApplier
320
input_test = TestTestScenarioApplier("test_adapt_test_to_scenario")
321
adapter = TestScenarioApplier()
287
322
# setup two adapted tests
288
adapted_test1 = apply_scenario(input_test,
323
adapted_test1 = adapter.adapt_test_to_scenario(input_test,
290
325
{"bzrdir_format":"bzr_format",
291
326
"repository_format":"repo_fmt",
292
327
"transport_server":"transport_server",
293
328
"transport_readonly_server":"readonly-server"}))
294
adapted_test2 = apply_scenario(input_test,
329
adapted_test2 = adapter.adapt_test_to_scenario(input_test,
295
330
("new id 2", {"bzrdir_format":None}))
296
331
# input_test should have been altered.
297
332
self.assertRaises(AttributeError, getattr, input_test, "bzrdir_format")
298
# the new tests are mutually incompatible, ensuring it has
333
# the new tests are mutually incompatible, ensuring it has
299
334
# made new ones, and unspecified elements in the scenario
300
335
# should not have been altered.
301
336
self.assertEqual("bzr_format", adapted_test1.bzrdir_format)
304
339
self.assertEqual("readonly-server",
305
340
adapted_test1.transport_readonly_server)
306
341
self.assertEqual(
307
"bzrlib.tests.test_selftest.TestTestScenarioApplication."
308
"test_apply_scenario(new id)",
342
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
343
"test_adapt_test_to_scenario(new id)",
309
344
adapted_test1.id())
310
345
self.assertEqual(None, adapted_test2.bzrdir_format)
311
346
self.assertEqual(
312
"bzrlib.tests.test_selftest.TestTestScenarioApplication."
313
"test_apply_scenario(new id 2)",
347
"bzrlib.tests.test_selftest.TestTestScenarioApplier."
348
"test_adapt_test_to_scenario(new id 2)",
314
349
adapted_test2.id())
317
class TestInterRepositoryScenarios(TestCase):
352
class TestInterRepositoryProviderAdapter(TestCase):
353
"""A group of tests that test the InterRepository test adapter."""
319
def test_scenarios(self):
355
def test_adapted_tests(self):
320
356
# check that constructor parameters are passed through to the adapted
322
358
from bzrlib.tests.interrepository_implementations import \
359
InterRepositoryTestProviderAdapter
326
362
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
327
scenarios = make_scenarios(server1, server2, formats)
363
adapter = InterRepositoryTestProviderAdapter(server1, server2, formats)
328
364
self.assertEqual([
330
366
{'interrepo_class': str,
331
367
'repository_format': 'C1',
332
368
'repository_format_to': 'C2',
333
369
'transport_readonly_server': 'b',
334
370
'transport_server': 'a'}),
336
372
{'interrepo_class': int,
337
373
'repository_format': 'D1',
338
374
'repository_format_to': 'D2',
339
375
'transport_readonly_server': 'b',
340
376
'transport_server': 'a'})],
344
class TestWorkingTreeScenarios(TestCase):
377
adapter.formats_to_scenarios(formats))
380
class TestInterVersionedFileProviderAdapter(TestCase):
381
"""A group of tests that test the InterVersionedFile test adapter."""
383
def test_scenarios(self):
384
# check that constructor parameters are passed through to the adapted
386
from bzrlib.tests.interversionedfile_implementations \
387
import InterVersionedFileTestProviderAdapter
390
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
391
adapter = InterVersionedFileTestProviderAdapter(server1, server2, formats)
394
{'interversionedfile_class':str,
395
'transport_readonly_server': 'b',
396
'transport_server': 'a',
397
'versionedfile_factory': 'C1',
398
'versionedfile_factory_to': 'C2'}),
400
{'interversionedfile_class': int,
401
'transport_readonly_server': 'b',
402
'transport_server': 'a',
403
'versionedfile_factory': 'D1',
404
'versionedfile_factory_to': 'D2'})],
408
class TestRevisionStoreProviderAdapter(TestCase):
409
"""A group of tests that test the RevisionStore test adapter."""
411
def test_scenarios(self):
412
# check that constructor parameters are passed through to the adapted
414
from bzrlib.tests.revisionstore_implementations \
415
import RevisionStoreTestProviderAdapter
416
# revision stores need a store factory - i.e. RevisionKnit
417
#, a readonly and rw transport
421
store_factories = ["c", "d"]
422
adapter = RevisionStoreTestProviderAdapter(server1, server2, store_factories)
425
{'store_factory': 'c',
426
'transport_readonly_server': 'b',
427
'transport_server': 'a'}),
429
{'store_factory': 'd',
430
'transport_readonly_server': 'b',
431
'transport_server': 'a'})],
435
class TestWorkingTreeProviderAdapter(TestCase):
436
"""A group of tests that test the workingtree implementation test adapter."""
346
438
def test_scenarios(self):
347
439
# check that constructor parameters are passed through to the adapted
349
441
from bzrlib.tests.workingtree_implementations \
350
import make_scenarios
442
import WorkingTreeTestProviderAdapter
353
formats = [workingtree.WorkingTreeFormat2(),
354
workingtree.WorkingTreeFormat3(),]
355
scenarios = make_scenarios(server1, server2, formats)
445
formats = [("c", "C"), ("d", "D")]
446
adapter = WorkingTreeTestProviderAdapter(server1, server2, formats)
356
447
self.assertEqual([
357
('WorkingTreeFormat2',
358
{'bzrdir_format': formats[0]._matchingbzrdir,
359
'transport_readonly_server': 'b',
360
'transport_server': 'a',
361
'workingtree_format': formats[0]}),
362
('WorkingTreeFormat3',
363
{'bzrdir_format': formats[1]._matchingbzrdir,
364
'transport_readonly_server': 'b',
365
'transport_server': 'a',
366
'workingtree_format': formats[1]})],
370
class TestTreeScenarios(TestCase):
372
def test_scenarios(self):
373
# the tree implementation scenario generator is meant to setup one
374
# instance for each working tree format, and one additional instance
375
# that will use the default wt format, but create a revision tree for
376
# the tests. this means that the wt ones should have the
377
# workingtree_to_test_tree attribute set to 'return_parameter' and the
378
# revision one set to revision_tree_from_workingtree.
449
{'bzrdir_format': 'C',
450
'transport_readonly_server': 'b',
451
'transport_server': 'a',
452
'workingtree_format': 'c'}),
454
{'bzrdir_format': 'D',
455
'transport_readonly_server': 'b',
456
'transport_server': 'a',
457
'workingtree_format': 'd'})],
461
class TestTreeProviderAdapter(TestCase):
462
"""Test the setup of tree_implementation tests."""
464
def test_adapted_tests(self):
465
# the tree implementation adapter is meant to setup one instance for
466
# each working tree format, and one additional instance that will
467
# use the default wt format, but create a revision tree for the tests.
468
# this means that the wt ones should have the workingtree_to_test_tree
469
# attribute set to 'return_parameter' and the revision one set to
470
# revision_tree_from_workingtree.
380
472
from bzrlib.tests.tree_implementations import (
381
_dirstate_tree_from_workingtree,
473
TreeTestProviderAdapter,
385
474
return_parameter,
386
475
revision_tree_from_workingtree
477
from bzrlib.workingtree import WorkingTreeFormat, WorkingTreeFormat3
478
input_test = TestTreeProviderAdapter(
479
"test_adapted_tests")
390
formats = [workingtree.WorkingTreeFormat2(),
391
workingtree.WorkingTreeFormat3(),]
392
scenarios = make_scenarios(server1, server2, formats)
393
self.assertEqual(7, len(scenarios))
394
default_wt_format = workingtree.WorkingTreeFormat4._default_format
395
wt4_format = workingtree.WorkingTreeFormat4()
396
wt5_format = workingtree.WorkingTreeFormat5()
397
expected_scenarios = [
398
('WorkingTreeFormat2',
399
{'bzrdir_format': formats[0]._matchingbzrdir,
400
'transport_readonly_server': 'b',
401
'transport_server': 'a',
402
'workingtree_format': formats[0],
403
'_workingtree_to_test_tree': return_parameter,
405
('WorkingTreeFormat3',
406
{'bzrdir_format': formats[1]._matchingbzrdir,
407
'transport_readonly_server': 'b',
408
'transport_server': 'a',
409
'workingtree_format': formats[1],
410
'_workingtree_to_test_tree': return_parameter,
413
{'_workingtree_to_test_tree': revision_tree_from_workingtree,
414
'bzrdir_format': default_wt_format._matchingbzrdir,
415
'transport_readonly_server': 'b',
416
'transport_server': 'a',
417
'workingtree_format': default_wt_format,
419
('DirStateRevisionTree,WT4',
420
{'_workingtree_to_test_tree': _dirstate_tree_from_workingtree,
421
'bzrdir_format': wt4_format._matchingbzrdir,
422
'transport_readonly_server': 'b',
423
'transport_server': 'a',
424
'workingtree_format': wt4_format,
426
('DirStateRevisionTree,WT5',
427
{'_workingtree_to_test_tree': _dirstate_tree_from_workingtree,
428
'bzrdir_format': wt5_format._matchingbzrdir,
429
'transport_readonly_server': 'b',
430
'transport_server': 'a',
431
'workingtree_format': wt5_format,
434
{'_workingtree_to_test_tree': preview_tree_pre,
435
'bzrdir_format': default_wt_format._matchingbzrdir,
436
'transport_readonly_server': 'b',
437
'transport_server': 'a',
438
'workingtree_format': default_wt_format}),
440
{'_workingtree_to_test_tree': preview_tree_post,
441
'bzrdir_format': default_wt_format._matchingbzrdir,
442
'transport_readonly_server': 'b',
443
'transport_server': 'a',
444
'workingtree_format': default_wt_format}),
446
self.assertEqual(expected_scenarios, scenarios)
449
class TestInterTreeScenarios(TestCase):
482
formats = [("c", "C"), ("d", "D")]
483
adapter = TreeTestProviderAdapter(server1, server2, formats)
484
suite = adapter.adapt(input_test)
485
tests = list(iter(suite))
486
self.assertEqual(4, len(tests))
487
# this must match the default format setp up in
488
# TreeTestProviderAdapter.adapt
489
default_format = WorkingTreeFormat3
490
self.assertEqual(tests[0].workingtree_format, formats[0][0])
491
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
492
self.assertEqual(tests[0].transport_server, server1)
493
self.assertEqual(tests[0].transport_readonly_server, server2)
494
self.assertEqual(tests[0].workingtree_to_test_tree, return_parameter)
495
self.assertEqual(tests[1].workingtree_format, formats[1][0])
496
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
497
self.assertEqual(tests[1].transport_server, server1)
498
self.assertEqual(tests[1].transport_readonly_server, server2)
499
self.assertEqual(tests[1].workingtree_to_test_tree, return_parameter)
500
self.assertIsInstance(tests[2].workingtree_format, default_format)
501
#self.assertEqual(tests[2].bzrdir_format,
502
# default_format._matchingbzrdir)
503
self.assertEqual(tests[2].transport_server, server1)
504
self.assertEqual(tests[2].transport_readonly_server, server2)
505
self.assertEqual(tests[2].workingtree_to_test_tree,
506
revision_tree_from_workingtree)
509
class TestInterTreeProviderAdapter(TestCase):
450
510
"""A group of tests that test the InterTreeTestAdapter."""
452
def test_scenarios(self):
512
def test_adapted_tests(self):
453
513
# check that constructor parameters are passed through to the adapted
455
515
# for InterTree tests we want the machinery to bring up two trees in
457
517
# because each optimiser can be direction specific, we need to test
458
518
# each optimiser in its chosen direction.
459
519
# unlike the TestProviderAdapter we dont want to automatically add a
460
# parameterized one for WorkingTree - the optimisers will tell us what
520
# parameterised one for WorkingTree - the optimisers will tell us what
462
522
from bzrlib.tests.tree_implementations import (
463
523
return_parameter,
464
524
revision_tree_from_workingtree
466
526
from bzrlib.tests.intertree_implementations import (
527
InterTreeTestProviderAdapter,
469
529
from bzrlib.workingtree import WorkingTreeFormat2, WorkingTreeFormat3
470
input_test = TestInterTreeScenarios(
530
input_test = TestInterTreeProviderAdapter(
531
"test_adapted_tests")
474
534
format1 = WorkingTreeFormat2()
475
535
format2 = WorkingTreeFormat3()
476
formats = [("1", str, format1, format2, "converter1"),
477
("2", int, format2, format1, "converter2")]
478
scenarios = make_scenarios(server1, server2, formats)
479
self.assertEqual(2, len(scenarios))
480
expected_scenarios = [
482
"bzrdir_format": format1._matchingbzrdir,
483
"intertree_class": formats[0][1],
484
"workingtree_format": formats[0][2],
485
"workingtree_format_to": formats[0][3],
486
"mutable_trees_to_test_trees": formats[0][4],
487
"_workingtree_to_test_tree": return_parameter,
488
"transport_server": server1,
489
"transport_readonly_server": server2,
492
"bzrdir_format": format2._matchingbzrdir,
493
"intertree_class": formats[1][1],
494
"workingtree_format": formats[1][2],
495
"workingtree_format_to": formats[1][3],
496
"mutable_trees_to_test_trees": formats[1][4],
497
"_workingtree_to_test_tree": return_parameter,
498
"transport_server": server1,
499
"transport_readonly_server": server2,
502
self.assertEqual(scenarios, expected_scenarios)
536
formats = [(str, format1, format2, "converter1"),
537
(int, format2, format1, "converter2")]
538
adapter = InterTreeTestProviderAdapter(server1, server2, formats)
539
suite = adapter.adapt(input_test)
540
tests = list(iter(suite))
541
self.assertEqual(2, len(tests))
542
self.assertEqual(tests[0].intertree_class, formats[0][0])
543
self.assertEqual(tests[0].workingtree_format, formats[0][1])
544
self.assertEqual(tests[0].workingtree_format_to, formats[0][2])
545
self.assertEqual(tests[0].mutable_trees_to_test_trees, formats[0][3])
546
self.assertEqual(tests[0].workingtree_to_test_tree, return_parameter)
547
self.assertEqual(tests[0].transport_server, server1)
548
self.assertEqual(tests[0].transport_readonly_server, server2)
549
self.assertEqual(tests[1].intertree_class, formats[1][0])
550
self.assertEqual(tests[1].workingtree_format, formats[1][1])
551
self.assertEqual(tests[1].workingtree_format_to, formats[1][2])
552
self.assertEqual(tests[1].mutable_trees_to_test_trees, formats[1][3])
553
self.assertEqual(tests[1].workingtree_to_test_tree, return_parameter)
554
self.assertEqual(tests[1].transport_server, server1)
555
self.assertEqual(tests[1].transport_readonly_server, server2)
505
558
class TestTestCaseInTempDir(TestCaseInTempDir):
569
608
self.assertEqual(format.repository_format.__class__,
570
609
tree.branch.repository._format.__class__)
572
def test_make_branch_builder(self):
573
builder = self.make_branch_builder('dir')
574
self.assertIsInstance(builder, branchbuilder.BranchBuilder)
575
# Guard against regression into MemoryTransport leaking
576
# files to disk instead of keeping them in memory.
577
self.failIf(osutils.lexists('dir'))
579
def test_make_branch_builder_with_format(self):
580
# Use a repo layout that doesn't conform to a 'named' layout, to ensure
581
# that the format objects are used.
582
format = bzrdir.BzrDirMetaFormat1()
583
repo_format = weaverepo.RepositoryFormat7()
584
format.repository_format = repo_format
585
builder = self.make_branch_builder('dir', format=format)
586
the_branch = builder.get_branch()
587
# Guard against regression into MemoryTransport leaking
588
# files to disk instead of keeping them in memory.
589
self.failIf(osutils.lexists('dir'))
590
self.assertEqual(format.repository_format.__class__,
591
the_branch.repository._format.__class__)
592
self.assertEqual(repo_format.get_format_string(),
593
self.get_transport().get_bytes(
594
'dir/.bzr/repository/format'))
596
def test_make_branch_builder_with_format_name(self):
597
builder = self.make_branch_builder('dir', format='knit')
598
the_branch = builder.get_branch()
599
# Guard against regression into MemoryTransport leaking
600
# files to disk instead of keeping them in memory.
601
self.failIf(osutils.lexists('dir'))
602
dir_format = bzrdir.format_registry.make_bzrdir('knit')
603
self.assertEqual(dir_format.repository_format.__class__,
604
the_branch.repository._format.__class__)
605
self.assertEqual('Bazaar-NG Knit Repository Format 1',
606
self.get_transport().get_bytes(
607
'dir/.bzr/repository/format'))
609
def test_safety_net(self):
610
"""No test should modify the safety .bzr directory.
612
We just test that the _check_safety_net private method raises
613
AssertionError, it's easier than building a test suite with the same
616
# Oops, a commit in the current directory (i.e. without local .bzr
617
# directory) will crawl up the hierarchy to find a .bzr directory.
618
self.run_bzr(['commit', '-mfoo', '--unchanged'])
619
# But we have a safety net in place.
620
self.assertRaises(AssertionError, self._check_safety_net)
623
612
class TestTestCaseWithTransport(TestCaseWithTransport):
624
613
"""Tests for the convenience functions TestCaseWithTransport introduces."""
1347
1216
def _test_pass(self):
1350
class _TestException(Exception):
1353
1220
class TestTestCase(TestCase):
1354
1221
"""Tests that test the core bzrlib TestCase."""
1356
def test_assertLength_matches_empty(self):
1358
self.assertLength(0, a_list)
1360
def test_assertLength_matches_nonempty(self):
1362
self.assertLength(3, a_list)
1364
def test_assertLength_fails_different(self):
1366
self.assertRaises(AssertionError, self.assertLength, 1, a_list)
1368
def test_assertLength_shows_sequence_in_failure(self):
1370
exception = self.assertRaises(AssertionError, self.assertLength, 2,
1372
self.assertEqual('Incorrect length: wanted 2, got 3 for [1, 2, 3]',
1375
def test_base_setUp_not_called_causes_failure(self):
1376
class TestCaseWithBrokenSetUp(TestCase):
1378
pass # does not call TestCase.setUp
1381
test = TestCaseWithBrokenSetUp('test_foo')
1382
result = unittest.TestResult()
1384
self.assertFalse(result.wasSuccessful())
1385
self.assertEqual(1, result.testsRun)
1387
def test_base_tearDown_not_called_causes_failure(self):
1388
class TestCaseWithBrokenTearDown(TestCase):
1390
pass # does not call TestCase.tearDown
1393
test = TestCaseWithBrokenTearDown('test_foo')
1394
result = unittest.TestResult()
1396
self.assertFalse(result.wasSuccessful())
1397
self.assertEqual(1, result.testsRun)
1399
1223
def test_debug_flags_sanitised(self):
1400
1224
"""The bzrlib debug flags should be sanitised by setUp."""
1401
if 'allow_debug' in tests.selftest_debug_flags:
1402
raise TestNotApplicable(
1403
'-Eallow_debug option prevents debug flag sanitisation')
1404
1225
# we could set something and run a test that will check
1405
1226
# it gets santised, but this is probably sufficient for now:
1406
1227
# if someone runs the test with -Dsomething it will error.
1407
1228
self.assertEqual(set(), bzrlib.debug.debug_flags)
1409
def change_selftest_debug_flags(self, new_flags):
1410
orig_selftest_flags = tests.selftest_debug_flags
1411
self.addCleanup(self._restore_selftest_debug_flags, orig_selftest_flags)
1412
tests.selftest_debug_flags = set(new_flags)
1414
def _restore_selftest_debug_flags(self, flags):
1415
tests.selftest_debug_flags = flags
1417
def test_allow_debug_flag(self):
1418
"""The -Eallow_debug flag prevents bzrlib.debug.debug_flags from being
1419
sanitised (i.e. cleared) before running a test.
1421
self.change_selftest_debug_flags(set(['allow_debug']))
1422
bzrlib.debug.debug_flags = set(['a-flag'])
1423
class TestThatRecordsFlags(TestCase):
1424
def test_foo(nested_self):
1425
self.flags = set(bzrlib.debug.debug_flags)
1426
test = TestThatRecordsFlags('test_foo')
1427
test.run(self.make_test_result())
1428
self.assertEqual(set(['a-flag']), self.flags)
1430
def test_debug_flags_restored(self):
1431
"""The bzrlib debug flags should be restored to their original state
1432
after the test was run, even if allow_debug is set.
1434
self.change_selftest_debug_flags(set(['allow_debug']))
1435
# Now run a test that modifies debug.debug_flags.
1436
bzrlib.debug.debug_flags = set(['original-state'])
1437
class TestThatModifiesFlags(TestCase):
1439
bzrlib.debug.debug_flags = set(['modified'])
1440
test = TestThatModifiesFlags('test_foo')
1441
test.run(self.make_test_result())
1442
self.assertEqual(set(['original-state']), bzrlib.debug.debug_flags)
1444
def make_test_result(self):
1445
return bzrlib.tests.TextTestResult(
1446
self._log_file, descriptions=0, verbosity=1)
1448
1230
def inner_test(self):
1449
1231
# the inner child test
1450
1232
note("inner_test")
1697
1422
def test_applyDeprecated_not_deprecated(self):
1698
1423
sample_object = ApplyDeprecatedHelper()
1699
1424
# calling an undeprecated callable raises an assertion
1700
self.assertRaises(AssertionError, self.applyDeprecated,
1701
deprecated_in((0, 11, 0)),
1425
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
1702
1426
sample_object.sample_normal_method)
1703
self.assertRaises(AssertionError, self.applyDeprecated,
1704
deprecated_in((0, 11, 0)),
1427
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
1705
1428
sample_undeprecated_function, "a param value")
1706
1429
# calling a deprecated callable (function or method) with the wrong
1707
1430
# expected deprecation fails.
1708
self.assertRaises(AssertionError, self.applyDeprecated,
1709
deprecated_in((0, 10, 0)),
1431
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
1710
1432
sample_object.sample_deprecated_method, "a param value")
1711
self.assertRaises(AssertionError, self.applyDeprecated,
1712
deprecated_in((0, 10, 0)),
1433
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
1713
1434
sample_deprecated_function)
1714
1435
# calling a deprecated callable (function or method) with the right
1715
1436
# expected deprecation returns the functions result.
1716
self.assertEqual("a param value",
1717
self.applyDeprecated(deprecated_in((0, 11, 0)),
1437
self.assertEqual("a param value", self.applyDeprecated(zero_eleven,
1718
1438
sample_object.sample_deprecated_method, "a param value"))
1719
self.assertEqual(2, self.applyDeprecated(deprecated_in((0, 11, 0)),
1439
self.assertEqual(2, self.applyDeprecated(zero_eleven,
1720
1440
sample_deprecated_function))
1721
1441
# calling a nested deprecation with the wrong deprecation version
1722
# fails even if a deeper nested function was deprecated with the
1442
# fails even if a deeper nested function was deprecated with the
1723
1443
# supplied version.
1724
1444
self.assertRaises(AssertionError, self.applyDeprecated,
1725
deprecated_in((0, 11, 0)), sample_object.sample_nested_deprecation)
1445
zero_eleven, sample_object.sample_nested_deprecation)
1726
1446
# calling a nested deprecation with the right deprecation value
1727
1447
# returns the calls result.
1728
self.assertEqual(2, self.applyDeprecated(deprecated_in((0, 10, 0)),
1448
self.assertEqual(2, self.applyDeprecated(zero_ten,
1729
1449
sample_object.sample_nested_deprecation))
1731
1451
def test_callDeprecated(self):
1732
1452
def testfunc(be_deprecated, result=None):
1733
1453
if be_deprecated is True:
1734
symbol_versioning.warn('i am deprecated', DeprecationWarning,
1454
symbol_versioning.warn('i am deprecated', DeprecationWarning,
1737
1457
result = self.callDeprecated(['i am deprecated'], testfunc, True)
1873
1577
class TestSelftestFiltering(TestCase):
1875
1579
def setUp(self):
1876
TestCase.setUp(self)
1877
1580
self.suite = TestUtil.TestSuite()
1878
1581
self.loader = TestUtil.TestLoader()
1879
1582
self.suite.addTest(self.loader.loadTestsFromModuleNames([
1880
1583
'bzrlib.tests.test_selftest']))
1881
self.all_names = _test_ids(self.suite)
1883
def test_condition_id_re(self):
1884
test_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1885
'test_condition_id_re')
1886
filtered_suite = filter_suite_by_condition(self.suite,
1887
condition_id_re('test_condition_id_re'))
1888
self.assertEqual([test_name], _test_ids(filtered_suite))
1890
def test_condition_id_in_list(self):
1891
test_names = ['bzrlib.tests.test_selftest.TestSelftestFiltering.'
1892
'test_condition_id_in_list']
1893
id_list = tests.TestIdList(test_names)
1894
filtered_suite = filter_suite_by_condition(
1895
self.suite, tests.condition_id_in_list(id_list))
1896
my_pattern = 'TestSelftestFiltering.*test_condition_id_in_list'
1897
re_filtered = filter_suite_by_re(self.suite, my_pattern)
1898
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1900
def test_condition_id_startswith(self):
1901
klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1902
start1 = klass + 'test_condition_id_starts'
1903
start2 = klass + 'test_condition_id_in'
1904
test_names = [ klass + 'test_condition_id_in_list',
1905
klass + 'test_condition_id_startswith',
1907
filtered_suite = filter_suite_by_condition(
1908
self.suite, tests.condition_id_startswith([start1, start2]))
1909
self.assertEqual(test_names, _test_ids(filtered_suite))
1911
def test_condition_isinstance(self):
1912
filtered_suite = filter_suite_by_condition(self.suite,
1913
condition_isinstance(self.__class__))
1914
class_pattern = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1915
re_filtered = filter_suite_by_re(self.suite, class_pattern)
1916
self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1918
def test_exclude_tests_by_condition(self):
1919
excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1920
'test_exclude_tests_by_condition')
1921
filtered_suite = exclude_tests_by_condition(self.suite,
1922
lambda x:x.id() == excluded_name)
1923
self.assertEqual(len(self.all_names) - 1,
1924
filtered_suite.countTestCases())
1925
self.assertFalse(excluded_name in _test_ids(filtered_suite))
1926
remaining_names = list(self.all_names)
1927
remaining_names.remove(excluded_name)
1928
self.assertEqual(remaining_names, _test_ids(filtered_suite))
1930
def test_exclude_tests_by_re(self):
1931
self.all_names = _test_ids(self.suite)
1932
filtered_suite = exclude_tests_by_re(self.suite, 'exclude_tests_by_re')
1933
excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1934
'test_exclude_tests_by_re')
1935
self.assertEqual(len(self.all_names) - 1,
1936
filtered_suite.countTestCases())
1937
self.assertFalse(excluded_name in _test_ids(filtered_suite))
1938
remaining_names = list(self.all_names)
1939
remaining_names.remove(excluded_name)
1940
self.assertEqual(remaining_names, _test_ids(filtered_suite))
1942
def test_filter_suite_by_condition(self):
1943
test_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1944
'test_filter_suite_by_condition')
1945
filtered_suite = filter_suite_by_condition(self.suite,
1946
lambda x:x.id() == test_name)
1947
self.assertEqual([test_name], _test_ids(filtered_suite))
1584
self.all_names = [t.id() for t in iter_suite_tests(self.suite)]
1949
1586
def test_filter_suite_by_re(self):
1950
filtered_suite = filter_suite_by_re(self.suite, 'test_filter_suite_by_r')
1951
filtered_names = _test_ids(filtered_suite)
1587
filtered_suite = filter_suite_by_re(self.suite, 'test_filter')
1588
filtered_names = [t.id() for t in iter_suite_tests(filtered_suite)]
1952
1589
self.assertEqual(filtered_names, ['bzrlib.tests.test_selftest.'
1953
1590
'TestSelftestFiltering.test_filter_suite_by_re'])
1955
def test_filter_suite_by_id_list(self):
1956
test_list = ['bzrlib.tests.test_selftest.'
1957
'TestSelftestFiltering.test_filter_suite_by_id_list']
1958
filtered_suite = tests.filter_suite_by_id_list(
1959
self.suite, tests.TestIdList(test_list))
1960
filtered_names = _test_ids(filtered_suite)
1963
['bzrlib.tests.test_selftest.'
1964
'TestSelftestFiltering.test_filter_suite_by_id_list'])
1966
def test_filter_suite_by_id_startswith(self):
1967
# By design this test may fail if another test is added whose name also
1968
# begins with one of the start value used.
1969
klass = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1970
start1 = klass + 'test_filter_suite_by_id_starts'
1971
start2 = klass + 'test_filter_suite_by_id_li'
1972
test_list = [klass + 'test_filter_suite_by_id_list',
1973
klass + 'test_filter_suite_by_id_startswith',
1975
filtered_suite = tests.filter_suite_by_id_startswith(
1976
self.suite, [start1, start2])
1979
_test_ids(filtered_suite),
1982
def test_preserve_input(self):
1983
# NB: Surely this is something in the stdlib to do this?
1984
self.assertTrue(self.suite is preserve_input(self.suite))
1985
self.assertTrue("@#$" is preserve_input("@#$"))
1987
def test_randomize_suite(self):
1988
randomized_suite = randomize_suite(self.suite)
1989
# randomizing should not add or remove test names.
1990
self.assertEqual(set(_test_ids(self.suite)),
1991
set(_test_ids(randomized_suite)))
1992
# Technically, this *can* fail, because random.shuffle(list) can be
1993
# equal to list. Trying multiple times just pushes the frequency back.
1994
# As its len(self.all_names)!:1, the failure frequency should be low
1995
# enough to ignore. RBC 20071021.
1996
# It should change the order.
1997
self.assertNotEqual(self.all_names, _test_ids(randomized_suite))
1998
# But not the length. (Possibly redundant with the set test, but not
2000
self.assertEqual(len(self.all_names), len(_test_ids(randomized_suite)))
2002
def test_split_suit_by_condition(self):
2003
self.all_names = _test_ids(self.suite)
2004
condition = condition_id_re('test_filter_suite_by_r')
2005
split_suite = split_suite_by_condition(self.suite, condition)
2006
filtered_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
2007
'test_filter_suite_by_re')
2008
self.assertEqual([filtered_name], _test_ids(split_suite[0]))
2009
self.assertFalse(filtered_name in _test_ids(split_suite[1]))
2010
remaining_names = list(self.all_names)
2011
remaining_names.remove(filtered_name)
2012
self.assertEqual(remaining_names, _test_ids(split_suite[1]))
2014
def test_split_suit_by_re(self):
2015
self.all_names = _test_ids(self.suite)
2016
split_suite = split_suite_by_re(self.suite, 'test_filter_suite_by_r')
2017
filtered_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
2018
'test_filter_suite_by_re')
2019
self.assertEqual([filtered_name], _test_ids(split_suite[0]))
2020
self.assertFalse(filtered_name in _test_ids(split_suite[1]))
2021
remaining_names = list(self.all_names)
2022
remaining_names.remove(filtered_name)
2023
self.assertEqual(remaining_names, _test_ids(split_suite[1]))
1592
def test_sort_suite_by_re(self):
1593
sorted_suite = sort_suite_by_re(self.suite, 'test_filter')
1594
sorted_names = [t.id() for t in iter_suite_tests(sorted_suite)]
1595
self.assertEqual(sorted_names[0], 'bzrlib.tests.test_selftest.'
1596
'TestSelftestFiltering.test_filter_suite_by_re')
1597
self.assertEquals(sorted(self.all_names), sorted(sorted_names))
2026
1600
class TestCheckInventoryShape(TestCaseWithTransport):
2035
1609
self.check_inventory_shape(tree.inventory, files)
2040
class TestBlackboxSupport(TestCase):
2041
"""Tests for testsuite blackbox features."""
2043
def test_run_bzr_failure_not_caught(self):
2044
# When we run bzr in blackbox mode, we want any unexpected errors to
2045
# propagate up to the test suite so that it can show the error in the
2046
# usual way, and we won't get a double traceback.
2047
e = self.assertRaises(
2049
self.run_bzr, ['assert-fail'])
2050
# make sure we got the real thing, not an error from somewhere else in
2051
# the test framework
2052
self.assertEquals('always fails', str(e))
2053
# check that there's no traceback in the test log
2054
self.assertNotContainsRe(self._get_log(keep_log_file=True),
2057
def test_run_bzr_user_error_caught(self):
2058
# Running bzr in blackbox mode, normal/expected/user errors should be
2059
# caught in the regular way and turned into an error message plus exit
2061
out, err = self.run_bzr(["log", "/nonexistantpath"], retcode=3)
2062
self.assertEqual(out, '')
2063
self.assertContainsRe(err,
2064
'bzr: ERROR: Not a branch: ".*nonexistantpath/".\n')
2067
class TestTestLoader(TestCase):
2068
"""Tests for the test loader."""
2070
def _get_loader_and_module(self):
2071
"""Gets a TestLoader and a module with one test in it."""
2072
loader = TestUtil.TestLoader()
2074
class Stub(TestCase):
2077
class MyModule(object):
2079
MyModule.a_class = Stub
2081
return loader, module
2083
def test_module_no_load_tests_attribute_loads_classes(self):
2084
loader, module = self._get_loader_and_module()
2085
self.assertEqual(1, loader.loadTestsFromModule(module).countTestCases())
2087
def test_module_load_tests_attribute_gets_called(self):
2088
loader, module = self._get_loader_and_module()
2089
# 'self' is here because we're faking the module with a class. Regular
2090
# load_tests do not need that :)
2091
def load_tests(self, standard_tests, module, loader):
2092
result = loader.suiteClass()
2093
for test in iter_suite_tests(standard_tests):
2094
result.addTests([test, test])
2096
# add a load_tests() method which multiplies the tests from the module.
2097
module.__class__.load_tests = load_tests
2098
self.assertEqual(2, loader.loadTestsFromModule(module).countTestCases())
2100
def test_load_tests_from_module_name_smoke_test(self):
2101
loader = TestUtil.TestLoader()
2102
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2103
self.assertEquals(['bzrlib.tests.test_sampler.DemoTest.test_nothing'],
2106
def test_load_tests_from_module_name_with_bogus_module_name(self):
2107
loader = TestUtil.TestLoader()
2108
self.assertRaises(ImportError, loader.loadTestsFromModuleName, 'bogus')
2111
class TestTestIdList(tests.TestCase):
2113
def _create_id_list(self, test_list):
2114
return tests.TestIdList(test_list)
2116
def _create_suite(self, test_id_list):
2118
class Stub(TestCase):
2122
def _create_test_id(id):
2125
suite = TestUtil.TestSuite()
2126
for id in test_id_list:
2127
t = Stub('test_foo')
2128
t.id = _create_test_id(id)
2132
def _test_ids(self, test_suite):
2133
"""Get the ids for the tests in a test suite."""
2134
return [t.id() for t in iter_suite_tests(test_suite)]
2136
def test_empty_list(self):
2137
id_list = self._create_id_list([])
2138
self.assertEquals({}, id_list.tests)
2139
self.assertEquals({}, id_list.modules)
2141
def test_valid_list(self):
2142
id_list = self._create_id_list(
2143
['mod1.cl1.meth1', 'mod1.cl1.meth2',
2144
'mod1.func1', 'mod1.cl2.meth2',
2146
'mod1.submod2.cl1.meth1', 'mod1.submod2.cl2.meth2',
2148
self.assertTrue(id_list.refers_to('mod1'))
2149
self.assertTrue(id_list.refers_to('mod1.submod1'))
2150
self.assertTrue(id_list.refers_to('mod1.submod2'))
2151
self.assertTrue(id_list.includes('mod1.cl1.meth1'))
2152
self.assertTrue(id_list.includes('mod1.submod1'))
2153
self.assertTrue(id_list.includes('mod1.func1'))
2155
def test_bad_chars_in_params(self):
2156
id_list = self._create_id_list(['mod1.cl1.meth1(xx.yy)'])
2157
self.assertTrue(id_list.refers_to('mod1'))
2158
self.assertTrue(id_list.includes('mod1.cl1.meth1(xx.yy)'))
2160
def test_module_used(self):
2161
id_list = self._create_id_list(['mod.class.meth'])
2162
self.assertTrue(id_list.refers_to('mod'))
2163
self.assertTrue(id_list.refers_to('mod.class'))
2164
self.assertTrue(id_list.refers_to('mod.class.meth'))
2166
def test_test_suite(self):
2167
# This test is slow, so we do a single test with one test in each
2171
'bzrlib.tests.blackbox.test_branch.TestBranch.test_branch',
2172
'bzrlib.tests.test_selftest.TestTestIdList.test_test_suite',
2173
# transport implementations
2174
'bzrlib.tests.test_transport_implementations.TransportTests'
2175
'.test_abspath(LocalURLServer)',
2176
# modules_to_doctest
2177
'bzrlib.timestamp.format_highres_date',
2178
# plugins can't be tested that way since selftest may be run with
2181
suite = tests.test_suite(test_list)
2182
self.assertEquals(test_list, _test_ids(suite))
2184
def test_test_suite_matches_id_list_with_unknown(self):
2185
loader = TestUtil.TestLoader()
2186
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2187
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing',
2189
not_found, duplicates = tests.suite_matches_id_list(suite, test_list)
2190
self.assertEquals(['bogus'], not_found)
2191
self.assertEquals([], duplicates)
2193
def test_suite_matches_id_list_with_duplicates(self):
2194
loader = TestUtil.TestLoader()
2195
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2196
dupes = loader.suiteClass()
2197
for test in iter_suite_tests(suite):
2199
dupes.addTest(test) # Add it again
2201
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing',]
2202
not_found, duplicates = tests.suite_matches_id_list(
2204
self.assertEquals([], not_found)
2205
self.assertEquals(['bzrlib.tests.test_sampler.DemoTest.test_nothing'],
2209
class TestLoadTestIdList(tests.TestCaseInTempDir):
2211
def _create_test_list_file(self, file_name, content):
2212
fl = open(file_name, 'wt')
2216
def test_load_unknown(self):
2217
self.assertRaises(errors.NoSuchFile,
2218
tests.load_test_id_list, 'i_do_not_exist')
2220
def test_load_test_list(self):
2221
test_list_fname = 'test.list'
2222
self._create_test_list_file(test_list_fname,
2223
'mod1.cl1.meth1\nmod2.cl2.meth2\n')
2224
tlist = tests.load_test_id_list(test_list_fname)
2225
self.assertEquals(2, len(tlist))
2226
self.assertEquals('mod1.cl1.meth1', tlist[0])
2227
self.assertEquals('mod2.cl2.meth2', tlist[1])
2229
def test_load_dirty_file(self):
2230
test_list_fname = 'test.list'
2231
self._create_test_list_file(test_list_fname,
2232
' mod1.cl1.meth1\n\nmod2.cl2.meth2 \n'
2234
tlist = tests.load_test_id_list(test_list_fname)
2235
self.assertEquals(4, len(tlist))
2236
self.assertEquals('mod1.cl1.meth1', tlist[0])
2237
self.assertEquals('', tlist[1])
2238
self.assertEquals('mod2.cl2.meth2', tlist[2])
2239
self.assertEquals('bar baz', tlist[3])
2242
class TestFilteredByModuleTestLoader(tests.TestCase):
2244
def _create_loader(self, test_list):
2245
id_filter = tests.TestIdList(test_list)
2246
loader = TestUtil.FilteredByModuleTestLoader(id_filter.refers_to)
2249
def test_load_tests(self):
2250
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
2251
loader = self._create_loader(test_list)
2253
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2254
self.assertEquals(test_list, _test_ids(suite))
2256
def test_exclude_tests(self):
2257
test_list = ['bogus']
2258
loader = self._create_loader(test_list)
2260
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2261
self.assertEquals([], _test_ids(suite))
2264
class TestFilteredByNameStartTestLoader(tests.TestCase):
2266
def _create_loader(self, name_start):
2267
def needs_module(name):
2268
return name.startswith(name_start) or name_start.startswith(name)
2269
loader = TestUtil.FilteredByModuleTestLoader(needs_module)
2272
def test_load_tests(self):
2273
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
2274
loader = self._create_loader('bzrlib.tests.test_samp')
2276
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2277
self.assertEquals(test_list, _test_ids(suite))
2279
def test_load_tests_inside_module(self):
2280
test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
2281
loader = self._create_loader('bzrlib.tests.test_sampler.Demo')
2283
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2284
self.assertEquals(test_list, _test_ids(suite))
2286
def test_exclude_tests(self):
2287
test_list = ['bogus']
2288
loader = self._create_loader('bogus')
2290
suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2291
self.assertEquals([], _test_ids(suite))
2294
class TestTestPrefixRegistry(tests.TestCase):
2296
def _get_registry(self):
2297
tp_registry = tests.TestPrefixAliasRegistry()
2300
def test_register_new_prefix(self):
2301
tpr = self._get_registry()
2302
tpr.register('foo', 'fff.ooo.ooo')
2303
self.assertEquals('fff.ooo.ooo', tpr.get('foo'))
2305
def test_register_existing_prefix(self):
2306
tpr = self._get_registry()
2307
tpr.register('bar', 'bbb.aaa.rrr')
2308
tpr.register('bar', 'bBB.aAA.rRR')
2309
self.assertEquals('bbb.aaa.rrr', tpr.get('bar'))
2310
self.assertContainsRe(self._get_log(keep_log_file=True),
2311
r'.*bar.*bbb.aaa.rrr.*bBB.aAA.rRR')
2313
def test_get_unknown_prefix(self):
2314
tpr = self._get_registry()
2315
self.assertRaises(KeyError, tpr.get, 'I am not a prefix')
2317
def test_resolve_prefix(self):
2318
tpr = self._get_registry()
2319
tpr.register('bar', 'bb.aa.rr')
2320
self.assertEquals('bb.aa.rr', tpr.resolve_alias('bar'))
2322
def test_resolve_unknown_alias(self):
2323
tpr = self._get_registry()
2324
self.assertRaises(errors.BzrCommandError,
2325
tpr.resolve_alias, 'I am not a prefix')
2327
def test_predefined_prefixes(self):
2328
tpr = tests.test_prefix_alias_registry
2329
self.assertEquals('bzrlib', tpr.resolve_alias('bzrlib'))
2330
self.assertEquals('bzrlib.doc', tpr.resolve_alias('bd'))
2331
self.assertEquals('bzrlib.utils', tpr.resolve_alias('bu'))
2332
self.assertEquals('bzrlib.tests', tpr.resolve_alias('bt'))
2333
self.assertEquals('bzrlib.tests.blackbox', tpr.resolve_alias('bb'))
2334
self.assertEquals('bzrlib.plugins', tpr.resolve_alias('bp'))
2337
class TestRunSuite(TestCase):
2339
def test_runner_class(self):
2340
"""run_suite accepts and uses a runner_class keyword argument."""
2341
class Stub(TestCase):
2344
suite = Stub("test_foo")
2346
class MyRunner(TextTestRunner):
2347
def run(self, test):
2349
return ExtendedTestResult(self.stream, self.descriptions,
2351
run_suite(suite, runner_class=MyRunner)
2352
self.assertEqual(calls, [suite])