~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-17 20:17:55 UTC
  • mfrom: (1185.16.59)
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1474.
  • Revision ID: abentley@panoramicfeedback.com-20051017201755-48ed4650792388ab
Merged latest 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):
188
191
            return
189
192
        raise AssertionError("texts not equal:\n" + 
190
193
                             self._ndiff_strings(a, b))      
 
194
 
 
195
    def assertContainsRe(self, haystack, needle_re):
 
196
        """Assert that a contains something matching a regular expression."""
 
197
        if not re.search(needle_re, haystack):
 
198
            raise AssertionError('pattern "%s" not found in "%s"'
 
199
                    % (needle_re, haystack))
191
200
        
192
201
    def _enable_file_logging(self):
193
202
        fileno, name = tempfile.mkstemp(suffix='.log', prefix='testbzr')
416
425
                print >>f, "contents of", name
417
426
                f.close()
418
427
 
 
428
    def build_tree_contents(self, shape):
 
429
        bzrlib.selftest.build_tree_contents(shape)
 
430
 
419
431
    def failUnlessExists(self, path):
420
432
        """Fail unless path, which may be abs or relative, exists."""
421
433
        self.failUnless(osutils.lexists(path))
427
439
        logging.info('an info message')
428
440
        warning('something looks dodgy...')
429
441
        logging.debug('hello, test is running')
430
 
        ##assert 0
 
442
        ## assert 0
431
443
 
432
444
 
433
445
def filter_suite_by_re(suite, pattern):
439
451
    return result
440
452
 
441
453
 
442
 
def run_suite(suite, name='test', verbose=False, pattern=".*"):
 
454
def run_suite(suite, name='test', verbose=False, pattern=".*",
 
455
              stop_on_failure=False):
443
456
    TestCaseInTempDir._TEST_NAME = name
444
457
    if verbose:
445
458
        verbosity = 2
448
461
    runner = TextTestRunner(stream=sys.stdout,
449
462
                            descriptions=0,
450
463
                            verbosity=verbosity)
 
464
    runner.stop_on_failure=stop_on_failure
451
465
    if pattern != '.*':
452
466
        suite = filter_suite_by_re(suite, pattern)
453
467
    result = runner.run(suite)
462
476
    return result.wasSuccessful()
463
477
 
464
478
 
465
 
def selftest(verbose=False, pattern=".*"):
 
479
def selftest(verbose=False, pattern=".*", stop_on_failure=True):
466
480
    """Run the whole test suite under the enhanced runner"""
467
 
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern)
 
481
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern,
 
482
                     stop_on_failure=stop_on_failure)
468
483
 
469
484
 
470
485
def test_suite():
514
529
                   'bzrlib.selftest.testtestament',
515
530
                   'bzrlib.selftest.testannotate',
516
531
                   'bzrlib.selftest.testrevprops',
 
532
                   'bzrlib.selftest.testoptions',
517
533
                   ]
518
534
 
519
535
    for m in (bzrlib.store, bzrlib.inventory, bzrlib.branch,