/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Ian Clatworthy
  • Date: 2007-04-04 09:10:10 UTC
  • mto: (2418.4.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 2448.
  • Revision ID: ian.clatworthy@internode.on.net-20070404091010-1j1sdngh8t77ef9v
--list and --exclude first cut

Show diffs side-by-side

added added

removed removed

Lines of Context:
493
493
                 descriptions=0,
494
494
                 verbosity=1,
495
495
                 keep_output=False,
496
 
                 bench_history=None):
 
496
                 bench_history=None,
 
497
                 list_only=False):
497
498
        self.stream = unittest._WritelnDecorator(stream)
498
499
        self.descriptions = descriptions
499
500
        self.verbosity = verbosity
500
501
        self.keep_output = keep_output
501
502
        self._bench_history = bench_history
 
503
        self.list_only = list_only
502
504
 
503
505
    def run(self, test):
504
506
        "Run the given test case or test suite."
515
517
                              )
516
518
        result.stop_early = self.stop_on_failure
517
519
        result.report_starting()
518
 
        test.run(result)
 
520
        if self.list_only:
 
521
            self.stream.writeln("Listing tests only ...\n")
 
522
            for t in iter_suite_tests(test):
 
523
                self.stream.writeln("%s" % (t.id()))
 
524
        else: 
 
525
            test.run(result)
519
526
        stopTime = time.time()
520
527
        timeTaken = stopTime - startTime
521
528
        result.printErrors()
599
606
                            % (item, suite))
600
607
 
601
608
 
 
609
 
 
610
 
602
611
class TestSkipped(Exception):
603
612
    """Indicates that a test was intentionally skipped, rather than failing."""
604
613
 
2027
2036
            self.transport_readonly_server = HttpServer
2028
2037
 
2029
2038
 
2030
 
def filter_suite_by_re(suite, pattern):
 
2039
def filter_suite_by_re(suite, pattern, exclude_pattern=None):
2031
2040
    result = TestUtil.TestSuite()
2032
2041
    filter_re = re.compile(pattern)
 
2042
    if exclude_pattern is not None:
 
2043
        exclude_re = re.compile(exclude_pattern)
2033
2044
    for test in iter_suite_tests(suite):
2034
 
        if filter_re.search(test.id()):
2035
 
            result.addTest(test)
 
2045
        test_id = test.id()
 
2046
        if exclude_pattern is None or not exclude_re.search(test_id):
 
2047
            if filter_re.search(test_id):
 
2048
                result.addTest(test)
2036
2049
    return result
2037
2050
 
2038
2051
 
2039
 
def sort_suite_by_re(suite, pattern):
 
2052
def sort_suite_by_re(suite, pattern, exclude_pattern=None):
2040
2053
    first = []
2041
2054
    second = []
2042
2055
    filter_re = re.compile(pattern)
 
2056
    if exclude_pattern is not None:
 
2057
        exclude_re = re.compile(exclude_pattern)
2043
2058
    for test in iter_suite_tests(suite):
2044
 
        if filter_re.search(test.id()):
2045
 
            first.append(test)
2046
 
        else:
2047
 
            second.append(test)
 
2059
        test_id = test.id()
 
2060
        if exclude_pattern is None or not exclude_re.search(test_id):
 
2061
            if filter_re.search(test_id):
 
2062
                first.append(test)
 
2063
            else:
 
2064
                second.append(test)
2048
2065
    return TestUtil.TestSuite(first + second)
2049
2066
 
2050
2067
 
 
2068
def list_tests(suite):
 
2069
    "Lists the tests in the suite."
 
2070
 
2051
2071
def run_suite(suite, name='test', verbose=False, pattern=".*",
2052
2072
              stop_on_failure=False, keep_output=False,
2053
2073
              transport=None, lsprof_timed=None, bench_history=None,
2054
2074
              matching_tests_first=None,
2055
 
              numbered_dirs=None):
 
2075
              numbered_dirs=None,
 
2076
              list_only=False,
 
2077
              exclude_pattern=None):
2056
2078
    global NUMBERED_DIRS
2057
2079
    if numbered_dirs is not None:
2058
2080
        NUMBERED_DIRS = bool(numbered_dirs)
2066
2088
                            descriptions=0,
2067
2089
                            verbosity=verbosity,
2068
2090
                            keep_output=keep_output,
2069
 
                            bench_history=bench_history)
 
2091
                            bench_history=bench_history,
 
2092
                            list_only=list_only)
2070
2093
    runner.stop_on_failure=stop_on_failure
2071
 
    if pattern != '.*':
 
2094
    if pattern != '.*' or exclude_pattern is not None:
2072
2095
        if matching_tests_first:
2073
 
            suite = sort_suite_by_re(suite, pattern)
 
2096
            suite = sort_suite_by_re(suite, pattern, exclude_pattern)
2074
2097
        else:
2075
 
            suite = filter_suite_by_re(suite, pattern)
 
2098
            suite = filter_suite_by_re(suite, pattern, exclude_pattern)
2076
2099
    result = runner.run(suite)
2077
2100
    return result.wasSuccessful()
2078
2101
 
2084
2107
             lsprof_timed=None,
2085
2108
             bench_history=None,
2086
2109
             matching_tests_first=None,
2087
 
             numbered_dirs=None):
 
2110
             numbered_dirs=None,
 
2111
             list_only=False,
 
2112
             exclude_pattern=None):
2088
2113
    """Run the whole test suite under the enhanced runner"""
2089
2114
    # XXX: Very ugly way to do this...
2090
2115
    # Disable warning about old formats because we don't want it to disturb
2108
2133
                     lsprof_timed=lsprof_timed,
2109
2134
                     bench_history=bench_history,
2110
2135
                     matching_tests_first=matching_tests_first,
2111
 
                     numbered_dirs=numbered_dirs)
 
2136
                     numbered_dirs=numbered_dirs,
 
2137
                     list_only=list_only,
 
2138
                     exclude_pattern=exclude_pattern)
2112
2139
    finally:
2113
2140
        default_transport = old_transport
2114
2141