~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import unittest
23
23
import warnings
24
24
 
 
25
from bzrlib import osutils
25
26
import bzrlib
26
27
from bzrlib.progress import _BaseProgressBar
27
28
from bzrlib.tests import (
440
441
    def clear(self):
441
442
        self.calls.append(('clear',))
442
443
 
 
444
    def note(self, msg, *args):
 
445
        self.calls.append(('note', msg, args))
 
446
 
443
447
 
444
448
class TestTestResult(TestCase):
445
449
 
450
454
        mypb = MockProgress()
451
455
        mypb.update('Running tests', 0, 4)
452
456
        last_calls = mypb.calls[:]
 
457
 
453
458
        result = bzrlib.tests._MyResult(self._log_file,
454
459
                                        descriptions=0,
455
460
                                        verbosity=1,
456
461
                                        pb=mypb)
457
462
        self.assertEqual(last_calls, mypb.calls)
458
463
 
 
464
        def shorten(s):
 
465
            """Shorten a string based on the terminal width"""
 
466
            return result._ellipsise_unimportant_words(s,
 
467
                                 osutils.terminal_width())
 
468
 
459
469
        # an error 
460
470
        result.startTest(dummy_test)
461
471
        # starting a test prints the test name
462
 
        self.assertEqual(last_calls + [('update', '...tyle_quiet', 0, None)], mypb.calls)
463
 
        last_calls = mypb.calls[:]
 
472
        last_calls += [('update', '...tyle_quiet', 0, None)]
 
473
        self.assertEqual(last_calls, mypb.calls)
464
474
        result.addError(dummy_test, dummy_error)
465
 
        self.assertEqual(last_calls + [('update', 'ERROR        ', 1, None)], mypb.calls)
466
 
        last_calls = mypb.calls[:]
 
475
        last_calls += [('update', 'ERROR        ', 1, None),
 
476
                       ('note', shorten(dummy_test.id() + ': ERROR'), ())
 
477
                      ]
 
478
        self.assertEqual(last_calls, mypb.calls)
467
479
 
468
480
        # a failure
469
481
        result.startTest(dummy_test)
470
 
        self.assertEqual(last_calls + [('update', '...tyle_quiet', 1, None)], mypb.calls)
471
 
        last_calls = mypb.calls[:]
 
482
        last_calls += [('update', '...tyle_quiet', 1, None)]
 
483
        self.assertEqual(last_calls, mypb.calls)
 
484
        last_calls += [('update', 'FAIL         ', 2, None),
 
485
                       ('note', shorten(dummy_test.id() + ': FAIL'), ())
 
486
                      ]
472
487
        result.addFailure(dummy_test, dummy_error)
473
 
        self.assertEqual(last_calls + [('update', 'FAIL         ', 2, None)], mypb.calls)
474
 
        last_calls = mypb.calls[:]
 
488
        self.assertEqual(last_calls, mypb.calls)
475
489
 
476
490
        # a success
477
491
        result.startTest(dummy_test)
478
 
        self.assertEqual(last_calls + [('update', '...tyle_quiet', 2, None)], mypb.calls)
479
 
        last_calls = mypb.calls[:]
 
492
        last_calls += [('update', '...tyle_quiet', 2, None)]
 
493
        self.assertEqual(last_calls, mypb.calls)
480
494
        result.addSuccess(dummy_test)
481
 
        self.assertEqual(last_calls + [('update', 'OK           ', 3, None)], mypb.calls)
482
 
        last_calls = mypb.calls[:]
 
495
        last_calls += [('update', 'OK           ', 3, None)]
 
496
        self.assertEqual(last_calls, mypb.calls)
483
497
 
484
498
        # a skip
485
499
        result.startTest(dummy_test)
486
 
        self.assertEqual(last_calls + [('update', '...tyle_quiet', 3, None)], mypb.calls)
487
 
        last_calls = mypb.calls[:]
 
500
        last_calls += [('update', '...tyle_quiet', 3, None)]
 
501
        self.assertEqual(last_calls, mypb.calls)
488
502
        result.addSkipped(dummy_test, dummy_error)
489
 
        self.assertEqual(last_calls + [('update', 'SKIP         ', 4, None)], mypb.calls)
490
 
        last_calls = mypb.calls[:]
 
503
        last_calls += [('update', 'SKIP         ', 4, None)]
 
504
        self.assertEqual(last_calls, mypb.calls)
491
505
 
492
506
    def test_elapsed_time_with_benchmarking(self):
493
507
        result = bzrlib.tests._MyResult(self._log_file,
726
740
        self.apply_redirected(out, err, None, bzrlib.tests.selftest, 
727
741
            test_suite_factory=factory)
728
742
        self.assertEqual([True], factory_called)
729
 
 
730
 
    def test_run_bzr_subprocess(self):
731
 
        """The run_bzr_helper_external comand behaves nicely."""
732
 
        result = self.run_bzr_subprocess('--version')
733
 
        result = self.run_bzr_subprocess('--version', retcode=None)
734
 
        self.assertContainsRe(result[0], 'is free software')
735
 
        self.assertRaises(AssertionError, self.run_bzr_subprocess, 
736
 
                          '--versionn')
737
 
        result = self.run_bzr_subprocess('--versionn', retcode=3)
738
 
        result = self.run_bzr_subprocess('--versionn', retcode=None)
739
 
        self.assertContainsRe(result[1], 'unknown command')
740
 
        err = self.run_bzr_subprocess('merge', '--merge-type', 'magic merge', 
741
 
                                      retcode=3)[1]
742
 
        self.assertContainsRe(err, 'No known merge type magic merge')
743
 
 
744
 
    def test_run_bzr_error(self):
745
 
        out, err = self.run_bzr_error(['^$'], 'rocks', retcode=0)
746
 
        self.assertEqual(out, 'it sure does!\n')
747
 
 
748
 
        out, err = self.run_bzr_error(["'foobarbaz' is not a versioned file"],
749
 
                                      'file-id', 'foobarbaz')