323
324
self.assertEqual(tests[1].transport_readonly_server, server2)
327
class TestTreeProviderAdapter(TestCase):
328
"""Test the setup of tree_implementation tests."""
330
def test_adapted_tests(self):
331
# the tree implementation adapter is meant to setup one instance for
332
# each working tree format, and one additional instance that will
333
# use the default wt format, but create a revision tree for the tests.
334
# this means that the wt ones should have the workingtree_to_test_tree
335
# attribute set to 'return_parameter' and the revision one set to
336
# revision_tree_from_workingtree.
338
from bzrlib.tests.tree_implementations import (
339
TreeTestProviderAdapter,
341
revision_tree_from_workingtree
343
from bzrlib.workingtree import WorkingTreeFormat
344
input_test = TestTreeProviderAdapter(
345
"test_adapted_tests")
348
formats = [("c", "C"), ("d", "D")]
349
adapter = TreeTestProviderAdapter(server1, server2, formats)
350
suite = adapter.adapt(input_test)
351
tests = list(iter(suite))
352
self.assertEqual(3, len(tests))
353
default_format = WorkingTreeFormat.get_default_format()
354
self.assertEqual(tests[0].workingtree_format, formats[0][0])
355
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
356
self.assertEqual(tests[0].transport_server, server1)
357
self.assertEqual(tests[0].transport_readonly_server, server2)
358
self.assertEqual(tests[0].workingtree_to_test_tree, return_parameter)
359
self.assertEqual(tests[1].workingtree_format, formats[1][0])
360
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
361
self.assertEqual(tests[1].transport_server, server1)
362
self.assertEqual(tests[1].transport_readonly_server, server2)
363
self.assertEqual(tests[1].workingtree_to_test_tree, return_parameter)
364
self.assertEqual(tests[2].workingtree_format, default_format)
365
self.assertEqual(tests[2].bzrdir_format, default_format._matchingbzrdir)
366
self.assertEqual(tests[2].transport_server, server1)
367
self.assertEqual(tests[2].transport_readonly_server, server2)
368
self.assertEqual(tests[2].workingtree_to_test_tree,
369
revision_tree_from_workingtree)
372
class TestInterTreeProviderAdapter(TestCase):
373
"""A group of tests that test the InterTreeTestAdapter."""
375
def test_adapted_tests(self):
376
# check that constructor parameters are passed through to the adapted
378
# for InterTree tests we want the machinery to bring up two trees in
379
# each instance: the base one, and the one we are interacting with.
380
# because each optimiser can be direction specific, we need to test
381
# each optimiser in its chosen direction.
382
# unlike the TestProviderAdapter we dont want to automatically add a
383
# parameterised one for WorkingTree - the optimisers will tell us what
385
from bzrlib.tests.tree_implementations import (
387
revision_tree_from_workingtree
389
from bzrlib.tests.intertree_implementations import (
390
InterTreeTestProviderAdapter,
392
from bzrlib.workingtree import WorkingTreeFormat2, WorkingTreeFormat3
393
input_test = TestInterTreeProviderAdapter(
394
"test_adapted_tests")
397
format1 = WorkingTreeFormat2()
398
format2 = WorkingTreeFormat3()
399
formats = [(str, format1, format2, False, True),
400
(int, format2, format1, False, True)]
401
adapter = InterTreeTestProviderAdapter(server1, server2, formats)
402
suite = adapter.adapt(input_test)
403
tests = list(iter(suite))
404
self.assertEqual(2, len(tests))
405
self.assertEqual(tests[0].intertree_class, formats[0][0])
406
self.assertEqual(tests[0].workingtree_format, formats[0][1])
407
self.assertEqual(tests[0].workingtree_to_test_tree, formats[0][2])
408
self.assertEqual(tests[0].workingtree_format_to, formats[0][3])
409
self.assertEqual(tests[0].workingtree_to_test_tree_to, formats[0][4])
410
self.assertEqual(tests[0].transport_server, server1)
411
self.assertEqual(tests[0].transport_readonly_server, server2)
412
self.assertEqual(tests[1].intertree_class, formats[1][0])
413
self.assertEqual(tests[1].workingtree_format, formats[1][1])
414
self.assertEqual(tests[1].workingtree_to_test_tree, formats[1][2])
415
self.assertEqual(tests[1].workingtree_format_to, formats[1][3])
416
self.assertEqual(tests[1].workingtree_to_test_tree_to, formats[1][4])
417
self.assertEqual(tests[1].transport_server, server1)
418
self.assertEqual(tests[1].transport_readonly_server, server2)
326
420
class TestTestCaseWithTransport(TestCaseWithTransport):
327
421
"""Tests for the convenience functions TestCaseWithTransport introduces."""
405
502
mypb = MockProgress()
406
503
mypb.update('Running tests', 0, 4)
407
504
last_calls = mypb.calls[:]
408
506
result = bzrlib.tests._MyResult(self._log_file,
412
510
self.assertEqual(last_calls, mypb.calls)
513
"""Shorten a string based on the terminal width"""
514
return result._ellipsise_unimportant_words(s,
515
osutils.terminal_width())
415
518
result.startTest(dummy_test)
416
519
# starting a test prints the test name
417
self.assertEqual(last_calls + [('update', '...tyle_quiet', 0, None)], mypb.calls)
418
last_calls = mypb.calls[:]
520
last_calls += [('update', '...tyle_quiet', 0, None)]
521
self.assertEqual(last_calls, mypb.calls)
419
522
result.addError(dummy_test, dummy_error)
420
self.assertEqual(last_calls + [('update', 'ERROR ', 1, None)], mypb.calls)
421
last_calls = mypb.calls[:]
523
last_calls += [('update', 'ERROR ', 1, None),
524
('note', shorten(dummy_test.id() + ': ERROR'), ())
526
self.assertEqual(last_calls, mypb.calls)
424
529
result.startTest(dummy_test)
425
self.assertEqual(last_calls + [('update', '...tyle_quiet', 1, None)], mypb.calls)
426
last_calls = mypb.calls[:]
530
last_calls += [('update', '...tyle_quiet', 1, None)]
531
self.assertEqual(last_calls, mypb.calls)
532
last_calls += [('update', 'FAIL ', 2, None),
533
('note', shorten(dummy_test.id() + ': FAIL'), ())
427
535
result.addFailure(dummy_test, dummy_error)
428
self.assertEqual(last_calls + [('update', 'FAIL ', 2, None)], mypb.calls)
429
last_calls = mypb.calls[:]
536
self.assertEqual(last_calls, mypb.calls)
432
539
result.startTest(dummy_test)
433
self.assertEqual(last_calls + [('update', '...tyle_quiet', 2, None)], mypb.calls)
434
last_calls = mypb.calls[:]
540
last_calls += [('update', '...tyle_quiet', 2, None)]
541
self.assertEqual(last_calls, mypb.calls)
435
542
result.addSuccess(dummy_test)
436
self.assertEqual(last_calls + [('update', 'OK ', 3, None)], mypb.calls)
437
last_calls = mypb.calls[:]
543
last_calls += [('update', 'OK ', 3, None)]
544
self.assertEqual(last_calls, mypb.calls)
440
547
result.startTest(dummy_test)
441
self.assertEqual(last_calls + [('update', '...tyle_quiet', 3, None)], mypb.calls)
442
last_calls = mypb.calls[:]
548
last_calls += [('update', '...tyle_quiet', 3, None)]
549
self.assertEqual(last_calls, mypb.calls)
443
550
result.addSkipped(dummy_test, dummy_error)
444
self.assertEqual(last_calls + [('update', 'SKIP ', 4, None)], mypb.calls)
445
last_calls = mypb.calls[:]
551
last_calls += [('update', 'SKIP ', 4, None)]
552
self.assertEqual(last_calls, mypb.calls)
447
554
def test_elapsed_time_with_benchmarking(self):
448
555
result = bzrlib.tests._MyResult(self._log_file,
681
788
self.apply_redirected(out, err, None, bzrlib.tests.selftest,
682
789
test_suite_factory=factory)
683
790
self.assertEqual([True], factory_called)
685
def test_run_bzr_subprocess(self):
686
"""The run_bzr_helper_external comand behaves nicely."""
687
result = self.run_bzr_subprocess('--version')
688
result = self.run_bzr_subprocess('--version', retcode=None)
689
self.assertContainsRe(result[0], 'is free software')
690
self.assertRaises(AssertionError, self.run_bzr_subprocess,
692
result = self.run_bzr_subprocess('--versionn', retcode=3)
693
result = self.run_bzr_subprocess('--versionn', retcode=None)
694
self.assertContainsRe(result[1], 'unknown command')
695
err = self.run_bzr_subprocess('merge', '--merge-type', 'magic merge',
697
self.assertContainsRe(err, 'No known merge type magic merge')
699
def test_run_bzr_error(self):
700
out, err = self.run_bzr_error(['^$'], 'rocks', retcode=0)
701
self.assertEqual(out, 'it sure does!\n')
703
out, err = self.run_bzr_error(["'foobarbaz' is not a versioned file"],
704
'file-id', 'foobarbaz')