~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-17 11:56:54 UTC
  • mfrom: (1185.16.59)
  • Revision ID: robertc@robertcollins.net-20051017115654-662239e1587524a8
mergeĀ fromĀ martin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
import bzrlib.osutils as osutils
34
34
from bzrlib.selftest import TestUtil
35
35
from bzrlib.selftest.TestUtil import TestLoader, TestSuite
36
 
 
 
36
from bzrlib.selftest.treeshape import build_tree_contents
37
37
 
38
38
MODULES_TO_TEST = []
39
39
MODULES_TO_DOCTEST = []
121
121
 
122
122
 
123
123
class TextTestRunner(unittest.TextTestRunner):
 
124
    stop_on_failure = False
124
125
 
125
126
    def _makeResult(self):
126
127
        result = _MyResult(self.stream, self.descriptions, self.verbosity)
127
 
        return EarlyStoppingTestResultAdapter(result)
 
128
        if self.stop_on_failure:
 
129
            result = EarlyStoppingTestResultAdapter(result)
 
130
        return result
128
131
 
129
132
 
130
133
def iter_suite_tests(suite):
196
199
            return
197
200
        raise AssertionError("texts not equal:\n" + 
198
201
                             self._ndiff_strings(a, b))      
 
202
 
 
203
    def assertContainsRe(self, haystack, needle_re):
 
204
        """Assert that a contains something matching a regular expression."""
 
205
        if not re.search(needle_re, haystack):
 
206
            raise AssertionError('pattern "%s" not found in "%s"'
 
207
                    % (needle_re, haystack))
199
208
        
200
209
    def _enable_file_logging(self):
201
210
        fileno, name = tempfile.mkstemp(suffix='.log', prefix='testbzr')
433
442
                print >>f, "contents of", name
434
443
                f.close()
435
444
 
 
445
    def build_tree_contents(self, shape):
 
446
        bzrlib.selftest.build_tree_contents(shape)
 
447
 
436
448
    def failUnlessExists(self, path):
437
449
        """Fail unless path, which may be abs or relative, exists."""
438
450
        self.failUnless(osutils.lexists(path))
444
456
        logging.info('an info message')
445
457
        warning('something looks dodgy...')
446
458
        logging.debug('hello, test is running')
447
 
        ##assert 0
 
459
        ## assert 0
448
460
 
449
461
 
450
462
def filter_suite_by_re(suite, pattern):
456
468
    return result
457
469
 
458
470
 
459
 
def run_suite(suite, name='test', verbose=False, pattern=".*"):
 
471
def run_suite(suite, name='test', verbose=False, pattern=".*",
 
472
              stop_on_failure=False):
460
473
    TestCaseInTempDir._TEST_NAME = name
461
474
    if verbose:
462
475
        verbosity = 2
465
478
    runner = TextTestRunner(stream=sys.stdout,
466
479
                            descriptions=0,
467
480
                            verbosity=verbosity)
 
481
    runner.stop_on_failure=stop_on_failure
468
482
    if pattern != '.*':
469
483
        suite = filter_suite_by_re(suite, pattern)
470
484
    result = runner.run(suite)
479
493
    return result.wasSuccessful()
480
494
 
481
495
 
482
 
def selftest(verbose=False, pattern=".*"):
 
496
def selftest(verbose=False, pattern=".*", stop_on_failure=True):
483
497
    """Run the whole test suite under the enhanced runner"""
484
 
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern)
 
498
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern,
 
499
                     stop_on_failure=stop_on_failure)
485
500
 
486
501
 
487
502
def test_suite():
532
547
                   'bzrlib.selftest.testtestament',
533
548
                   'bzrlib.selftest.testannotate',
534
549
                   'bzrlib.selftest.testrevprops',
 
550
                   'bzrlib.selftest.testoptions',
535
551
                   ]
536
552
 
537
553
    for m in (bzrlib.store, bzrlib.inventory, bzrlib.branch,