selftest: Make sure format-subunit and filter-subunit can find testtools/subunit.
[sfrench/samba-autobuild/.git] / selftest / filter-subunit
1 #!/usr/bin/env python
2 # Filter a subunit stream
3 # Copyright (C) Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later
5
6 import optparse
7 import os
8 import subunithelper
9 import sys
10 import signal
11
12 sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../lib/subunit/python"))
13 sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../lib/testtools"))
14
15 parser = optparse.OptionParser("filter-subunit [options] < instream > outstream")
16 parser.add_option("--expected-failures", type="string", 
17         help="File containing list of regexes matching tests to consider known "
18              "failures")
19 parser.add_option("--strip-passed-output", action="store_true", 
20     help="Whether to strip output from tests that passed")
21
22 parser.add_option("--prefix", type="string",
23         help="Add prefix to all test names")
24
25 opts, args = parser.parse_args()
26
27 if opts.expected_failures:
28         expected_failures = list(subunithelper.read_test_regexes(opts.expected_failures))
29 else:
30         expected_failures = []
31
32 statistics = {
33         'TESTS_UNEXPECTED_OK': 0,
34         'TESTS_EXPECTED_OK': 0,
35         'TESTS_UNEXPECTED_FAIL': 0,
36         'TESTS_EXPECTED_FAIL': 0,
37         'TESTS_ERROR': 0,
38         'TESTS_SKIP': 0,
39 }
40
41 def handle_sigint(sig, stack):
42         sys.exit(0)
43 signal.signal(signal.SIGINT, handle_sigint)
44
45 msg_ops = subunithelper.FilterOps(opts.prefix, expected_failures, 
46         opts.strip_passed_output)
47
48 sys.exit(subunithelper.parse_results(msg_ops, statistics, sys.stdin))