~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

[merge] config file and other things from robert

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import sys
26
26
import tempfile
27
27
import unittest
 
28
import time
28
29
 
29
30
import bzrlib.commands
30
31
import bzrlib.trace
31
32
import bzrlib.fetch
 
33
import bzrlib.osutils as osutils
32
34
from bzrlib.selftest import TestUtil
33
35
from bzrlib.selftest.TestUtil import TestLoader, TestSuite
34
36
 
70
72
    No special behaviour for now.
71
73
    """
72
74
 
 
75
    def _elapsedTime(self):
 
76
        return "(Took %.3fs)" % (time.time() - self._start_time)
 
77
 
73
78
    def startTest(self, test):
74
79
        unittest.TestResult.startTest(self, test)
75
80
        # TODO: Maybe show test.shortDescription somewhere?
77
82
        if self.showAll:
78
83
            self.stream.write('%-70.70s' % what)
79
84
        self.stream.flush()
 
85
        self._start_time = time.time()
80
86
 
81
87
    def addError(self, test, err):
82
 
        super(_MyResult, self).addError(test, err)
 
88
        unittest.TestResult.addError(self, test, err)
 
89
        if self.showAll:
 
90
            self.stream.writeln("ERROR %s" % self._elapsedTime())
 
91
        elif self.dots:
 
92
            self.stream.write('E')
83
93
        self.stream.flush()
84
94
 
85
95
    def addFailure(self, test, err):
86
 
        super(_MyResult, self).addFailure(test, err)
 
96
        unittest.TestResult.addFailure(self, test, err)
 
97
        if self.showAll:
 
98
            self.stream.writeln("FAIL %s" % self._elapsedTime())
 
99
        elif self.dots:
 
100
            self.stream.write('F')
87
101
        self.stream.flush()
88
102
 
89
103
    def addSuccess(self, test):
90
104
        if self.showAll:
91
 
            self.stream.writeln('OK')
 
105
            self.stream.writeln('OK %s' % self._elapsedTime())
92
106
        elif self.dots:
93
107
            self.stream.write('~')
94
108
        self.stream.flush()
404
418
 
405
419
    def failUnlessExists(self, path):
406
420
        """Fail unless path, which may be abs or relative, exists."""
407
 
        self.failUnless(os.path.exists(path))
 
421
        self.failUnless(osutils.lexists(path))
408
422
        
409
423
 
410
424
class MetaTestLog(TestCase):
420
434
    result = TestUtil.TestSuite()
421
435
    filter_re = re.compile(pattern)
422
436
    for test in iter_suite_tests(suite):
423
 
        if filter_re.match(test.id()):
 
437
        if filter_re.search(test.id()):
424
438
            result.addTest(test)
425
439
    return result
426
440
 
427
441
 
428
 
def filter_suite_by_names(suite, wanted_names):
429
 
    """Return a new suite containing only selected tests.
430
 
    
431
 
    Names are considered to match if any name is a substring of the 
432
 
    fully-qualified test id (i.e. the class ."""
433
 
    result = TestSuite()
434
 
    for test in iter_suite_tests(suite):
435
 
        this_id = test.id()
436
 
        for p in wanted_names:
437
 
            if this_id.find(p) != -1:
438
 
                result.addTest(test)
439
 
    return result
440
 
 
441
 
 
442
 
def run_suite(suite, name='test', verbose=False, pattern=".*", testnames=None):
 
442
def run_suite(suite, name='test', verbose=False, pattern=".*"):
443
443
    TestCaseInTempDir._TEST_NAME = name
444
444
    if verbose:
445
445
        verbosity = 2
448
448
    runner = TextTestRunner(stream=sys.stdout,
449
449
                            descriptions=0,
450
450
                            verbosity=verbosity)
451
 
    if testnames:
452
 
        suite = filter_suite_by_names(suite, testnames)
453
451
    if pattern != '.*':
454
452
        suite = filter_suite_by_re(suite, pattern)
455
453
    result = runner.run(suite)
464
462
    return result.wasSuccessful()
465
463
 
466
464
 
467
 
def selftest(verbose=False, pattern=".*", testnames=None):
 
465
def selftest(verbose=False, pattern=".*"):
468
466
    """Run the whole test suite under the enhanced runner"""
469
 
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern,
470
 
                     testnames=testnames)
 
467
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern)
471
468
 
472
469
 
473
470
def test_suite():
485
482
                   'bzrlib.selftest.test_ancestry',
486
483
                   'bzrlib.selftest.test_commit',
487
484
                   'bzrlib.selftest.test_commit_merge',
 
485
                   'bzrlib.selftest.testconfig',
488
486
                   'bzrlib.selftest.versioning',
489
487
                   'bzrlib.selftest.testmerge3',
490
488
                   'bzrlib.selftest.testmerge',