~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

  • Committer: Robert Collins
  • Date: 2005-10-04 04:49:21 UTC
  • Revision ID: robertc@robertcollins.net-20051004044921-45fd2dc3f70abe59
remove debug print statement

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import errno
25
25
import subprocess
26
26
import shutil
27
 
import re
28
27
 
29
28
import bzrlib.commands
30
29
import bzrlib.trace
113
112
        return EarlyStoppingTestResultAdapter(result)
114
113
 
115
114
 
116
 
def iter_suite_tests(suite):
117
 
    """Return all tests in a suite, recursing through nested suites"""
118
 
    for item in suite._tests:
119
 
        if isinstance(item, unittest.TestCase):
120
 
            yield item
121
 
        elif isinstance(item, unittest.TestSuite):
122
 
            for r in iter_suite_tests(item):
123
 
                yield r
124
 
        else:
125
 
            raise Exception('unknown object %r inside test suite %r'
126
 
                            % (item, suite))
127
 
 
 
115
class filteringVisitor(TestUtil.TestVisitor):
 
116
    """I accruse all the testCases I visit that pass a regexp filter on id
 
117
    into my suite
 
118
    """
 
119
 
 
120
    def __init__(self, filter):
 
121
        import re
 
122
        TestUtil.TestVisitor.__init__(self)
 
123
        self._suite=None
 
124
        self.filter=re.compile(filter)
 
125
 
 
126
    def suite(self):
 
127
        """answer the suite we are building"""
 
128
        if self._suite is None:
 
129
            self._suite=TestUtil.TestSuite()
 
130
        return self._suite
 
131
 
 
132
    def visitCase(self, aCase):
 
133
        if self.filter.match(aCase.id()):
 
134
            self.suite().addTest(aCase)
128
135
 
129
136
class TestSkipped(Exception):
130
137
    """Indicates that a test was intentionally skipped, rather than failing."""
380
387
                print >>f, "contents of", name
381
388
                f.close()
382
389
 
383
 
    def failUnlessExists(self, path):
384
 
        """Fail unless path, which may be abs or relative, exists."""
385
 
        self.failUnless(os.path.exists(path))
386
 
        
387
390
 
388
391
class MetaTestLog(TestCase):
389
392
    def test_logging(self):
394
397
        ##assert 0
395
398
 
396
399
 
397
 
def filter_suite_by_re(suite, pattern):
398
 
    result = TestUtil.TestSuite()
399
 
    filter_re = re.compile(pattern)
400
 
    for test in iter_suite_tests(suite):
401
 
        if filter_re.match(test.id()):
402
 
            result.addTest(test)
403
 
    return result
404
 
 
405
 
 
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):
 
400
 
 
401
def run_suite(suite, name='test', verbose=False, pattern=".*"):
421
402
    TestCaseInTempDir._TEST_NAME = name
422
403
    if verbose:
423
404
        verbosity = 2
426
407
    runner = TextTestRunner(stream=sys.stdout,
427
408
                            descriptions=0,
428
409
                            verbosity=verbosity)
429
 
    if testnames:
430
 
        suite = filter_suite_by_names(suite, testnames)
431
 
    if pattern != '.*':
432
 
        suite = filter_suite_by_re(suite, pattern)
433
 
    result = runner.run(suite)
 
410
    visitor = filteringVisitor(pattern)
 
411
    suite.visit(visitor)
 
412
    result = runner.run(visitor.suite())
434
413
    # This is still a little bogus, 
435
414
    # but only a little. Folk not using our testrunner will
436
415
    # have to delete their temp directories themselves.
442
421
    return result.wasSuccessful()
443
422
 
444
423
 
445
 
def selftest(verbose=False, pattern=".*", testnames=None):
 
424
def selftest(verbose=False, pattern=".*"):
446
425
    """Run the whole test suite under the enhanced runner"""
447
 
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern,
448
 
                     testnames=testnames)
 
426
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern)
449
427
 
450
428
 
451
429
def test_suite():
483
461
                   'bzrlib.selftest.whitebox',
484
462
                   'bzrlib.selftest.teststore',
485
463
                   'bzrlib.selftest.blackbox',
486
 
                   'bzrlib.selftest.testsampler',
487
464
                   'bzrlib.selftest.testtransport',
488
465
                   'bzrlib.selftest.testgraph',
489
466
                   'bzrlib.selftest.testworkingtree',
490
 
                   'bzrlib.selftest.test_upgrade',
491
 
                   'bzrlib.selftest.test_conflicts',
492
467
                   ]
493
468
 
494
469
    for m in (bzrlib.store, bzrlib.inventory, bzrlib.branch,