~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Martin Pool
  • Date: 2009-07-24 03:15:56 UTC
  • mfrom: (4565 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4566.
  • Revision ID: mbp@sourcefrog.net-20090724031556-5zyef6f1ixtn6r3z
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
                          TestLoader,
103
103
                          )
104
104
from bzrlib.tests.treeshape import build_tree_contents
 
105
from bzrlib.ui.text import TextUIFactory
105
106
import bzrlib.version_info_formats.format_custom
106
107
from bzrlib.workingtree import WorkingTree, WorkingTreeFormat2
107
108
 
195
196
    def _testTimeString(self, testCase):
196
197
        benchmark_time = self._extractBenchmarkTime(testCase)
197
198
        if benchmark_time is not None:
198
 
            return "%s/%s" % (
199
 
                self._formatTime(benchmark_time),
200
 
                self._elapsedTestTimeString())
 
199
            return self._formatTime(benchmark_time) + "*"
201
200
        else:
202
 
            return "           %s" % self._elapsedTestTimeString()
 
201
            return self._elapsedTestTimeString()
203
202
 
204
203
    def _formatTime(self, seconds):
205
204
        """Format seconds as milliseconds with leading spaces."""
346
345
            self.stream.write("%s: " % flavour)
347
346
            self.stream.writeln(self.getDescription(test))
348
347
            if getattr(test, '_get_log', None) is not None:
349
 
                self.stream.write('\n')
350
 
                self.stream.write(
351
 
                        ('vvvv[log from %s]' % test.id()).ljust(78,'-'))
352
 
                self.stream.write('\n')
353
 
                self.stream.write(test._get_log())
354
 
                self.stream.write('\n')
355
 
                self.stream.write(
356
 
                        ('^^^^[log from %s]' % test.id()).ljust(78,'-'))
357
 
                self.stream.write('\n')
 
348
                log_contents = test._get_log()
 
349
                if log_contents:
 
350
                    self.stream.write('\n')
 
351
                    self.stream.write(
 
352
                            ('vvvv[log from %s]' % test.id()).ljust(78,'-'))
 
353
                    self.stream.write('\n')
 
354
                    self.stream.write(log_contents)
 
355
                    self.stream.write('\n')
 
356
                    self.stream.write(
 
357
                            ('^^^^[log from %s]' % test.id()).ljust(78,'-'))
 
358
                    self.stream.write('\n')
358
359
            self.stream.writeln(self.separator2)
359
360
            self.stream.writeln("%s" % err)
360
361
 
486
487
    def report_test_start(self, test):
487
488
        self.count += 1
488
489
        name = self._shortened_test_description(test)
489
 
        # width needs space for 6 char status, plus 1 for slash, plus 2 10-char
490
 
        # numbers, plus a trailing blank
 
490
        # width needs space for 6 char status, plus 1 for slash, plus an
 
491
        # 11-char time string, plus a trailing blank
491
492
        # when NUMBERED_DIRS: plus 5 chars on test number, plus 1 char on space
492
493
        self.stream.write(self._ellipsize_to_right(name,
493
 
                          osutils.terminal_width()-30))
 
494
                          osutils.terminal_width()-18))
494
495
        self.stream.flush()
495
496
 
496
497
    def _error_summary(self, err):
702
703
            return setattr(self._cstring, name, val)
703
704
 
704
705
 
705
 
class TestUIFactory(ui.CLIUIFactory):
 
706
class TestUIFactory(TextUIFactory):
706
707
    """A UI Factory for testing.
707
708
 
708
709
    Hide the progress bar but emit note()s.
1093
1094
                         osutils.realpath(path2),
1094
1095
                         "apparent paths:\na = %s\nb = %s\n," % (path1, path2))
1095
1096
 
1096
 
    def assertIsInstance(self, obj, kls):
1097
 
        """Fail if obj is not an instance of kls"""
 
1097
    def assertIsInstance(self, obj, kls, msg=None):
 
1098
        """Fail if obj is not an instance of kls
 
1099
        
 
1100
        :param msg: Supplementary message to show if the assertion fails.
 
1101
        """
1098
1102
        if not isinstance(obj, kls):
1099
 
            self.fail("%r is an instance of %s rather than %s" % (
1100
 
                obj, obj.__class__, kls))
 
1103
            m = "%r is an instance of %s rather than %s" % (
 
1104
                obj, obj.__class__, kls)
 
1105
            if msg:
 
1106
                m += ": " + msg
 
1107
            self.fail(m)
1101
1108
 
1102
1109
    def expectFailure(self, reason, assertion, *args, **kwargs):
1103
1110
        """Invoke a test, expecting it to fail for the given reason.
1325
1332
            'BZR_PROGRESS_BAR': None,
1326
1333
            'BZR_LOG': None,
1327
1334
            'BZR_PLUGIN_PATH': None,
 
1335
            # Make sure that any text ui tests are consistent regardless of
 
1336
            # the environment the test case is run in; you may want tests that
 
1337
            # test other combinations.  'dumb' is a reasonable guess for tests
 
1338
            # going to a pipe or a StringIO.
 
1339
            'TERM': 'dumb',
 
1340
            'LINES': '25',
 
1341
            'COLUMNS': '80',
1328
1342
            # SSH Agent
1329
1343
            'SSH_AUTH_SOCK': None,
1330
1344
            # Proxies
2959
2973
    concurrency = osutils.local_concurrency()
2960
2974
    result = []
2961
2975
    from subunit import TestProtocolClient, ProtocolTestCase
 
2976
    try:
 
2977
        from subunit.test_results import AutoTimingTestResultDecorator
 
2978
    except ImportError:
 
2979
        AutoTimingTestResultDecorator = lambda x:x
2962
2980
    class TestInOtherProcess(ProtocolTestCase):
2963
2981
        # Should be in subunit, I think. RBC.
2964
2982
        def __init__(self, stream, pid):
2987
3005
                sys.stdin.close()
2988
3006
                sys.stdin = None
2989
3007
                stream = os.fdopen(c2pwrite, 'wb', 1)
2990
 
                subunit_result = TestProtocolClient(stream)
 
3008
                subunit_result = AutoTimingTestResultDecorator(
 
3009
                    TestProtocolClient(stream))
2991
3010
                process_suite.run(subunit_result)
2992
3011
            finally:
2993
3012
                os._exit(0)
3333
3352
    testmod_names = [
3334
3353
                   'bzrlib.doc',
3335
3354
                   'bzrlib.tests.blackbox',
3336
 
                   'bzrlib.tests.branch_implementations',
3337
 
                   'bzrlib.tests.bzrdir_implementations',
3338
3355
                   'bzrlib.tests.commands',
3339
 
                   'bzrlib.tests.interrepository_implementations',
3340
 
                   'bzrlib.tests.intertree_implementations',
3341
 
                   'bzrlib.tests.inventory_implementations',
 
3356
                   'bzrlib.tests.per_branch',
 
3357
                   'bzrlib.tests.per_bzrdir',
 
3358
                   'bzrlib.tests.per_interrepository',
 
3359
                   'bzrlib.tests.per_intertree',
 
3360
                   'bzrlib.tests.per_inventory',
3342
3361
                   'bzrlib.tests.per_interbranch',
3343
3362
                   'bzrlib.tests.per_lock',
 
3363
                   'bzrlib.tests.per_transport',
 
3364
                   'bzrlib.tests.per_tree',
3344
3365
                   'bzrlib.tests.per_repository',
3345
3366
                   'bzrlib.tests.per_repository_chk',
3346
3367
                   'bzrlib.tests.per_repository_reference',
 
3368
                   'bzrlib.tests.per_workingtree',
 
3369
                   'bzrlib.tests.test__annotator',
3347
3370
                   'bzrlib.tests.test__chk_map',
3348
3371
                   'bzrlib.tests.test__dirstate_helpers',
3349
3372
                   'bzrlib.tests.test__groupcompress',
3481
3504
                   'bzrlib.tests.test_transactions',
3482
3505
                   'bzrlib.tests.test_transform',
3483
3506
                   'bzrlib.tests.test_transport',
3484
 
                   'bzrlib.tests.test_transport_implementations',
3485
3507
                   'bzrlib.tests.test_transport_log',
3486
3508
                   'bzrlib.tests.test_tree',
3487
3509
                   'bzrlib.tests.test_treebuilder',
3502
3524
                   'bzrlib.tests.test_workingtree_4',
3503
3525
                   'bzrlib.tests.test_wsgi',
3504
3526
                   'bzrlib.tests.test_xml',
3505
 
                   'bzrlib.tests.tree_implementations',
3506
 
                   'bzrlib.tests.workingtree_implementations',
3507
3527
                   ]
3508
3528
 
3509
3529
    loader = TestUtil.TestLoader()
3980
4000
# Only define SubUnitBzrRunner if subunit is available.
3981
4001
try:
3982
4002
    from subunit import TestProtocolClient
 
4003
    try:
 
4004
        from subunit.test_results import AutoTimingTestResultDecorator
 
4005
    except ImportError:
 
4006
        AutoTimingTestResultDecorator = lambda x:x
3983
4007
    class SubUnitBzrRunner(TextTestRunner):
3984
4008
        def run(self, test):
3985
 
            result = TestProtocolClient(self.stream)
 
4009
            result = AutoTimingTestResultDecorator(
 
4010
                TestProtocolClient(self.stream))
3986
4011
            test.run(result)
3987
4012
            return result
3988
4013
except ImportError: