/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6997.5.1 by Jelmer Vernooij
Support running against both python versions.
1
#!/usr/bin/python
2
3
import argparse
4
import subprocess
6997.5.4 by Jelmer Vernooij
Fix test list handling.
5
from subunit.v2 import StreamResultToBytes
6997.5.1 by Jelmer Vernooij
Support running against both python versions.
6
import sys
6997.5.4 by Jelmer Vernooij
Fix test list handling.
7
import tempfile
8
from testrepository.testlist import parse_enumeration, parse_list, write_list
9
10
6997.5.10 by Jelmer Vernooij
Address review comments:
11
def main():
12
    parser = argparse.ArgumentParser(
13
        description="Test runner that supports both Python 2 and Python 3.")
14
15
    parser.add_argument(
16
        "--load-list", metavar="PATH", help="Path to read list of tests to run from.",
17
        type=str)
18
    parser.add_argument(
19
        "--list", help="List available tests.", action="store_true")
20
21
    args = parser.parse_args()
22
23
    if args.list:
24
        testids = []
25
        output = subprocess.check_output(
26
            ['python2', './brz', 'selftest', '--subunit2', '--list'])
27
        for n in parse_enumeration(output):
6997.5.5 by Jelmer Vernooij
Inline function.
28
            testids.append('python2.' + n)
6997.5.10 by Jelmer Vernooij
Address review comments:
29
6997.5.11 by Jelmer Vernooij
Fix --list.
30
        output = subprocess.check_output(
6997.5.10 by Jelmer Vernooij
Address review comments:
31
            ['python3', './brz', 'selftest', '--subunit2', '--list'])
6997.5.11 by Jelmer Vernooij
Fix --list.
32
        for n in parse_enumeration(output):
6997.5.5 by Jelmer Vernooij
Inline function.
33
            testids.append('python3.' + n)
6997.5.10 by Jelmer Vernooij
Address review comments:
34
        stream = StreamResultToBytes(sys.stdout)
35
        for testid in testids:
36
            stream.status(test_id=testid, test_status='exists')
6997.5.2 by Jelmer Vernooij
Read/Write subunit2 test files.
37
    else:
6997.5.10 by Jelmer Vernooij
Address review comments:
38
        if args.load_list:
39
            py2_tests = []
40
            py3_tests = []
41
            with open(args.load_list, 'r') as f:
42
                all_tests = parse_list(f.read())
43
            for testname in all_tests:
44
                if testname.startswith("python2."):
45
                    py2_tests.append(testname[len('python2.'):].strip())
46
                elif testname.startswith("python3."):
47
                    py3_tests.append(testname[len('python3.'):].strip())
48
                else:
49
                    sys.stderr.write("unknown prefix %s\n" % testname)
50
            if py2_tests:
51
                with tempfile.NamedTemporaryFile() as py2f:
52
                    write_list(py2f, py2_tests)
53
                    py2f.flush()
54
                    subprocess.call(
55
                        'python2 ./brz selftest --subunit2 --load-list=%s | subunit-filter -s --passthrough --rename "^" "python2."' % py2f.name, shell=True)
56
57
            if py3_tests:
58
                with tempfile.NamedTemporaryFile() as py3f:
59
                    write_list(py3f, py3_tests)
60
                    py3f.flush()
61
                    subprocess.call(
62
                        'python3 ./brz selftest --subunit2 --load-list=%s | subunit-filter -s --passthrough --rename "^" "python3."' % py3f.name, shell=True)
63
        else:
64
            subprocess.call(
65
                'python2 ./brz selftest --subunit2 | subunit-filter -s --passthrough --rename "^" "python2."', shell=True)
66
            subprocess.call(
67
                'python3 ./brz selftest --subunit2 | subunit-filter -s --passthrough --rename "^" "python3."', shell=True)
68
69
70
if __name__ == '__main__':
71
    main()