~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to testsweet.py

  • Committer: Robert Collins
  • Date: 2005-08-24 08:34:10 UTC
  • mto: (974.1.50) (1185.1.10) (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: robertc@robertcollins.net-20050824083410-98aa4eeb52653394
import and use TestUtil to do regex based partial test runs

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
import unittest
41
41
import sys
 
42
from bzrlib.selftest import TestUtil
42
43
 
43
44
# XXX: Don't need this anymore now we depend on python2.4
44
45
def _need_subprocess():
340
341
        return EarlyStoppingTestResultAdapter(result)
341
342
 
342
343
 
343
 
def run_suite(suite, name='test', verbose=False):
 
344
class filteringVisitor(TestUtil.TestVisitor):
 
345
    """I accruse all the testCases I visit that pass a regexp filter on id
 
346
    into my suite
 
347
    """
 
348
 
 
349
    def __init__(self, filter):
 
350
        import re
 
351
        TestUtil.TestVisitor.__init__(self)
 
352
        self._suite=None
 
353
        self.filter=re.compile(filter)
 
354
 
 
355
    def suite(self):
 
356
        """answer the suite we are building"""
 
357
        if self._suite is None:
 
358
            self._suite=TestUtil.TestSuite()
 
359
        return self._suite
 
360
 
 
361
    def visitCase(self, aCase):
 
362
        if self.filter.match(aCase.id()):
 
363
            self.suite().addTest(aCase)
 
364
 
 
365
 
 
366
def run_suite(suite, name='test', verbose=False, pattern=".*"):
344
367
    import shutil
345
368
    FunctionalTestCase._TEST_NAME = name
346
369
    if verbose:
350
373
    runner = TextTestRunner(stream=sys.stdout,
351
374
                            descriptions=0,
352
375
                            verbosity=verbosity)
353
 
    result = runner.run(suite)
 
376
    visitor = filteringVisitor(pattern)
 
377
    suite.visit(visitor)
 
378
    result = runner.run(visitor.suite())
354
379
    # This is still a little bogus, 
355
380
    # but only a little. Folk not using our testrunner will
356
381
    # have to delete their temp directories themselves.
357
382
    if result.wasSuccessful():
358
 
        shutil.rmtree(FunctionalTestCase.TEST_ROOT) 
 
383
        if FunctionalTestCase.TEST_ROOT is not None:
 
384
            shutil.rmtree(FunctionalTestCase.TEST_ROOT) 
359
385
    else:
360
386
        print "Failed tests working directories are in '%s'\n" % FunctionalTestCase.TEST_ROOT
361
387
    return result.wasSuccessful()