~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

  • Committer: Aaron Bentley
  • Date: 2005-10-13 21:29:09 UTC
  • mfrom: (1451)
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1460.
  • Revision ID: abentley@troll-20051013212909-cfde7d2d05ccd47e
Merged latest from robert collins

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import unittest
21
21
import tempfile
22
22
import os
23
 
import sys
24
23
import errno
 
24
import re
 
25
import shutil
25
26
import subprocess
26
 
import shutil
27
 
import re
 
27
import sys
 
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()
382
396
 
383
397
    def failUnlessExists(self, path):
384
398
        """Fail unless path, which may be abs or relative, exists."""
385
 
        self.failUnless(os.path.exists(path))
 
399
        self.failUnless(osutils.lexists(path))
386
400
        
387
401
 
388
402
class MetaTestLog(TestCase):
398
412
    result = TestUtil.TestSuite()
399
413
    filter_re = re.compile(pattern)
400
414
    for test in iter_suite_tests(suite):
401
 
        if filter_re.match(test.id()):
 
415
        if filter_re.search(test.id()):
402
416
            result.addTest(test)
403
417
    return result
404
418
 
405
419
 
406
 
def filter_suite_by_names(suite, wanted_names):
407
 
    """Return a new suite containing only selected tests.
408
 
    
409
 
    Names are considered to match if any name is a substring of the 
410
 
    fully-qualified test id (i.e. the class ."""
411
 
    result = TestSuite()
412
 
    for test in iter_suite_tests(suite):
413
 
        this_id = test.id()
414
 
        for p in wanted_names:
415
 
            if this_id.find(p) != -1:
416
 
                result.addTest(test)
417
 
    return result
418
 
 
419
 
 
420
 
def run_suite(suite, name='test', verbose=False, pattern=".*", testnames=None):
 
420
def run_suite(suite, name='test', verbose=False, pattern=".*"):
421
421
    TestCaseInTempDir._TEST_NAME = name
422
422
    if verbose:
423
423
        verbosity = 2
426
426
    runner = TextTestRunner(stream=sys.stdout,
427
427
                            descriptions=0,
428
428
                            verbosity=verbosity)
429
 
    if testnames:
430
 
        suite = filter_suite_by_names(suite, testnames)
431
429
    if pattern != '.*':
432
430
        suite = filter_suite_by_re(suite, pattern)
433
431
    result = runner.run(suite)
442
440
    return result.wasSuccessful()
443
441
 
444
442
 
445
 
def selftest(verbose=False, pattern=".*", testnames=None):
 
443
def selftest(verbose=False, pattern=".*"):
446
444
    """Run the whole test suite under the enhanced runner"""
447
 
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern,
448
 
                     testnames=testnames)
 
445
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern)
449
446
 
450
447
 
451
448
def test_suite():
463
460
                   'bzrlib.selftest.test_ancestry',
464
461
                   'bzrlib.selftest.test_commit',
465
462
                   'bzrlib.selftest.test_commit_merge',
 
463
                   'bzrlib.selftest.testconfig',
466
464
                   'bzrlib.selftest.versioning',
467
465
                   'bzrlib.selftest.testmerge3',
468
466
                   'bzrlib.selftest.testmerge',