324
322
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)
420
325
class TestTestCaseWithTransport(TestCaseWithTransport):
421
326
"""Tests for the convenience functions TestCaseWithTransport introduces."""
502
404
mypb = MockProgress()
503
405
mypb.update('Running tests', 0, 4)
504
406
last_calls = mypb.calls[:]
506
407
result = bzrlib.tests._MyResult(self._log_file,
510
411
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())
518
414
result.startTest(dummy_test)
519
415
# starting a test prints the test name
520
last_calls += [('update', '...tyle_quiet', 0, None)]
521
self.assertEqual(last_calls, mypb.calls)
416
self.assertEqual(last_calls + [('update', '...tyle_quiet', 0, None)], mypb.calls)
417
last_calls = mypb.calls[:]
522
418
result.addError(dummy_test, dummy_error)
523
last_calls += [('update', 'ERROR ', 1, None),
524
('note', shorten(dummy_test.id() + ': ERROR'), ())
526
self.assertEqual(last_calls, mypb.calls)
419
self.assertEqual(last_calls + [('update', 'ERROR ', 1, None)], mypb.calls)
420
last_calls = mypb.calls[:]
529
423
result.startTest(dummy_test)
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'), ())
424
self.assertEqual(last_calls + [('update', '...tyle_quiet', 1, None)], mypb.calls)
425
last_calls = mypb.calls[:]
535
426
result.addFailure(dummy_test, dummy_error)
536
self.assertEqual(last_calls, mypb.calls)
427
self.assertEqual(last_calls + [('update', 'FAIL ', 2, None)], mypb.calls)
428
last_calls = mypb.calls[:]
539
431
result.startTest(dummy_test)
540
last_calls += [('update', '...tyle_quiet', 2, None)]
541
self.assertEqual(last_calls, mypb.calls)
432
self.assertEqual(last_calls + [('update', '...tyle_quiet', 2, None)], mypb.calls)
433
last_calls = mypb.calls[:]
542
434
result.addSuccess(dummy_test)
543
last_calls += [('update', 'OK ', 3, None)]
544
self.assertEqual(last_calls, mypb.calls)
435
self.assertEqual(last_calls + [('update', 'OK ', 3, None)], mypb.calls)
436
last_calls = mypb.calls[:]
547
439
result.startTest(dummy_test)
548
last_calls += [('update', '...tyle_quiet', 3, None)]
549
self.assertEqual(last_calls, mypb.calls)
440
self.assertEqual(last_calls + [('update', '...tyle_quiet', 3, None)], mypb.calls)
441
last_calls = mypb.calls[:]
550
442
result.addSkipped(dummy_test, dummy_error)
551
last_calls += [('update', 'SKIP ', 4, None)]
552
self.assertEqual(last_calls, mypb.calls)
443
self.assertEqual(last_calls + [('update', 'SKIP ', 4, None)], mypb.calls)
444
last_calls = mypb.calls[:]
554
446
def test_elapsed_time_with_benchmarking(self):
555
447
result = bzrlib.tests._MyResult(self._log_file,
614
506
# 1 0 ??? ??? ???(sleep)
615
507
# and then repeated but with 'world', rather than 'hello'.
616
508
# this should appear in the output stream of our test result.
617
output = result_stream.getvalue()
618
self.assertContainsRe(output,
619
r"LSProf output for <type 'unicode'>\(\('hello',\), {'errors': 'replace'}\)")
620
self.assertContainsRe(output,
621
r" *CallCount *Recursive *Total\(ms\) *Inline\(ms\) *module:lineno\(function\)\n")
622
self.assertContainsRe(output,
623
r"( +1 +0 +0\.\d+ +0\.\d+ +<method 'disable' of '_lsprof\.Profiler' objects>\n)?")
624
self.assertContainsRe(output,
625
r"LSProf output for <type 'unicode'>\(\('world',\), {'errors': 'replace'}\)\n")
509
self.assertContainsRe(result_stream.getvalue(),
510
r"LSProf output for <type 'unicode'>\(\('hello',\), {'errors': 'replace'}\)\n"
511
r" *CallCount *Recursive *Total\(ms\) *Inline\(ms\) *module:lineno\(function\)\n"
512
r" +1 +0 +0\.\d+ +0\.\d+ +<method 'disable' of '_lsprof\.Profiler' objects>\n"
513
r"LSProf output for <type 'unicode'>\(\('world',\), {'errors': 'replace'}\)\n"
514
r" *CallCount *Recursive *Total\(ms\) *Inline\(ms\) *module:lineno\(function\)\n"
515
r" +1 +0 +0\.\d+ +0\.\d+ +<method 'disable' of '_lsprof\.Profiler' objects>\n"
628
519
class TestRunner(TestCase):