~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2007-01-24 20:40:20 UTC
  • mfrom: (2242 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2245.
  • Revision ID: john@arbash-meinel.com-20070124204020-szyxbjpn9mzbsks7
[merge] bzr.dev 2242

Show diffs side-by-side

added added

removed removed

Lines of Context:
661
661
                excName = str(excClass)
662
662
            raise self.failureException, "%s not raised" % excName
663
663
 
664
 
    def assertIs(self, left, right):
 
664
    def assertIs(self, left, right, message=None):
665
665
        if not (left is right):
666
 
            raise AssertionError("%r is not %r." % (left, right))
 
666
            if message is not None:
 
667
                raise AssertionError(message)
 
668
            else:
 
669
                raise AssertionError("%r is not %r." % (left, right))
 
670
 
 
671
    def assertIsNot(self, left, right, message=None):
 
672
        if (left is right):
 
673
            if message is not None:
 
674
                raise AssertionError(message)
 
675
            else:
 
676
                raise AssertionError("%r is %r." % (left, right))
667
677
 
668
678
    def assertTransportMode(self, transport, path, mode):
669
679
        """Fail if a path does not have mode mode.
1539
1549
 
1540
1550
    def failUnlessExists(self, path):
1541
1551
        """Fail unless path, which may be abs or relative, exists."""
1542
 
        self.failUnless(osutils.lexists(path))
 
1552
        self.failUnless(osutils.lexists(path),path+" does not exist")
1543
1553
 
1544
1554
    def failIfExists(self, path):
1545
1555
        """Fail if path, which may be abs or relative, exists."""
1546
 
        self.failIf(osutils.lexists(path))
 
1556
        self.failIf(osutils.lexists(path),path+" exists")
1547
1557
 
1548
1558
 
1549
1559
class TestCaseWithTransport(TestCaseInTempDir):
1658
1668
    return result
1659
1669
 
1660
1670
 
 
1671
def sort_suite_by_re(suite, pattern):
 
1672
    first = []
 
1673
    second = []
 
1674
    filter_re = re.compile(pattern)
 
1675
    for test in iter_suite_tests(suite):
 
1676
        if filter_re.search(test.id()):
 
1677
            first.append(test)
 
1678
        else:
 
1679
            second.append(test)
 
1680
    return TestUtil.TestSuite(first + second)
 
1681
 
 
1682
 
1661
1683
def run_suite(suite, name='test', verbose=False, pattern=".*",
1662
1684
              stop_on_failure=False, keep_output=False,
1663
 
              transport=None, lsprof_timed=None, bench_history=None):
 
1685
              transport=None, lsprof_timed=None, bench_history=None,
 
1686
              matching_tests_first=None):
1664
1687
    TestCase._gather_lsprof_in_benchmarks = lsprof_timed
1665
1688
    if verbose:
1666
1689
        verbosity = 2
1673
1696
                            bench_history=bench_history)
1674
1697
    runner.stop_on_failure=stop_on_failure
1675
1698
    if pattern != '.*':
1676
 
        suite = filter_suite_by_re(suite, pattern)
 
1699
        if matching_tests_first:
 
1700
            suite = sort_suite_by_re(suite, pattern)
 
1701
        else:
 
1702
            suite = filter_suite_by_re(suite, pattern)
1677
1703
    result = runner.run(suite)
1678
1704
    return result.wasSuccessful()
1679
1705
 
1683
1709
             transport=None,
1684
1710
             test_suite_factory=None,
1685
1711
             lsprof_timed=None,
1686
 
             bench_history=None):
 
1712
             bench_history=None,
 
1713
             matching_tests_first=None):
1687
1714
    """Run the whole test suite under the enhanced runner"""
1688
1715
    # XXX: Very ugly way to do this...
1689
1716
    # Disable warning about old formats because we don't want it to disturb
1705
1732
                     stop_on_failure=stop_on_failure, keep_output=keep_output,
1706
1733
                     transport=transport,
1707
1734
                     lsprof_timed=lsprof_timed,
1708
 
                     bench_history=bench_history)
 
1735
                     bench_history=bench_history,
 
1736
                     matching_tests_first=matching_tests_first)
1709
1737
    finally:
1710
1738
        default_transport = old_transport
1711
1739