~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Aaron Bentley
  • Date: 2007-01-17 15:39:21 UTC
  • mfrom: (1551.9.35 Aaron's mergeable stuff)
  • mto: This revision was merged to the branch mainline in revision 2239.
  • Revision ID: abentley@panoramicfeedback.com-20070117153921-6pp9ssa2r8n5izoo
Merge bzr.ab, to avoid conflicts submitting

Show diffs side-by-side

added added

removed removed

Lines of Context:
1262
1262
        self.transport_server = default_transport
1263
1263
        self.transport_readonly_server = None
1264
1264
 
1265
 
    def failUnlessExists(self, path):
1266
 
        """Fail unless path, which may be abs or relative, exists."""
1267
 
        self.failUnless(osutils.lexists(path))
1268
 
 
1269
 
    def failIfExists(self, path):
1270
 
        """Fail if path, which may be abs or relative, exists."""
1271
 
        self.failIf(osutils.lexists(path))
1272
 
        
1273
1265
    def get_transport(self):
1274
1266
        """Return a writeable transport for the test scratch space"""
1275
1267
        t = get_transport(self.get_url())
1531
1523
                elif line_endings == 'native':
1532
1524
                    end = os.linesep
1533
1525
                else:
1534
 
                    raise errors.BzrError('Invalid line ending request %r' % (line_endings,))
 
1526
                    raise errors.BzrError(
 
1527
                        'Invalid line ending request %r' % line_endings)
1535
1528
                content = "contents of %s%s" % (name.encode('utf-8'), end)
1536
 
                # Technically 'put()' is the right command. However, put
1537
 
                # uses an AtomicFile, which requires an extra rename into place
1538
 
                # As long as the files didn't exist in the past, append() will
1539
 
                # do the same thing as put()
1540
 
                # On jam's machine, make_kernel_like_tree is:
1541
 
                #   put:    4.5-7.5s (averaging 6s)
1542
 
                #   append: 2.9-4.5s
1543
 
                #   put_non_atomic: 2.9-4.5s
1544
1529
                transport.put_bytes_non_atomic(urlutils.escape(name), content)
1545
1530
 
1546
1531
    def build_tree_contents(self, shape):
1548
1533
 
1549
1534
    def assertFileEqual(self, content, path):
1550
1535
        """Fail if path does not contain 'content'."""
1551
 
        self.failUnless(osutils.lexists(path))
 
1536
        self.failUnlessExists(path)
1552
1537
        # TODO: jam 20060427 Shouldn't this be 'rb'?
1553
1538
        self.assertEqualDiff(content, open(path, 'r').read())
1554
1539
 
 
1540
    def failUnlessExists(self, path):
 
1541
        """Fail unless path, which may be abs or relative, exists."""
 
1542
        self.failUnless(osutils.lexists(path))
 
1543
 
 
1544
    def failIfExists(self, path):
 
1545
        """Fail if path, which may be abs or relative, exists."""
 
1546
        self.failIf(osutils.lexists(path))
 
1547
 
1555
1548
 
1556
1549
class TestCaseWithTransport(TestCaseInTempDir):
1557
1550
    """A test case that provides get_url and get_readonly_url facilities.
1665
1658
    return result
1666
1659
 
1667
1660
 
 
1661
def sort_suite_by_re(suite, pattern):
 
1662
    first = []
 
1663
    second = []
 
1664
    filter_re = re.compile(pattern)
 
1665
    for test in iter_suite_tests(suite):
 
1666
        if filter_re.search(test.id()):
 
1667
            first.append(test)
 
1668
        else:
 
1669
            second.append(test)
 
1670
    return TestUtil.TestSuite(first + second)
 
1671
 
 
1672
 
1668
1673
def run_suite(suite, name='test', verbose=False, pattern=".*",
1669
1674
              stop_on_failure=False, keep_output=False,
1670
 
              transport=None, lsprof_timed=None, bench_history=None):
 
1675
              transport=None, lsprof_timed=None, bench_history=None,
 
1676
              matching_tests_first=None):
1671
1677
    TestCase._gather_lsprof_in_benchmarks = lsprof_timed
1672
1678
    if verbose:
1673
1679
        verbosity = 2
1680
1686
                            bench_history=bench_history)
1681
1687
    runner.stop_on_failure=stop_on_failure
1682
1688
    if pattern != '.*':
1683
 
        suite = filter_suite_by_re(suite, pattern)
 
1689
        if matching_tests_first:
 
1690
            suite = sort_suite_by_re(suite, pattern)
 
1691
        else:
 
1692
            suite = filter_suite_by_re(suite, pattern)
1684
1693
    result = runner.run(suite)
1685
1694
    return result.wasSuccessful()
1686
1695
 
1690
1699
             transport=None,
1691
1700
             test_suite_factory=None,
1692
1701
             lsprof_timed=None,
1693
 
             bench_history=None):
 
1702
             bench_history=None,
 
1703
             matching_tests_first=None):
1694
1704
    """Run the whole test suite under the enhanced runner"""
1695
1705
    # XXX: Very ugly way to do this...
1696
1706
    # Disable warning about old formats because we don't want it to disturb
1712
1722
                     stop_on_failure=stop_on_failure, keep_output=keep_output,
1713
1723
                     transport=transport,
1714
1724
                     lsprof_timed=lsprof_timed,
1715
 
                     bench_history=bench_history)
 
1725
                     bench_history=bench_history,
 
1726
                     matching_tests_first=matching_tests_first)
1716
1727
    finally:
1717
1728
        default_transport = old_transport
1718
1729