/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 tools/testr-run.py

  • Committer: Jelmer Vernooij
  • Date: 2020-02-07 02:14:30 UTC
  • mto: This revision was merged to the branch mainline in revision 7492.
  • Revision ID: jelmer@jelmer.uk-20200207021430-m49iq3x4x8xlib6x
Drop python2 support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python3
2
 
 
3
 
import argparse
4
 
import subprocess
5
 
from subunit.v2 import StreamResultToBytes
6
 
import sys
7
 
import tempfile
8
 
from testrepository.testlist import parse_enumeration, parse_list, write_list
9
 
 
10
 
 
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):
28
 
            testids.append('python2.' + n)
29
 
 
30
 
        output = subprocess.check_output(
31
 
            ['python3', './brz', 'selftest', '--subunit2', '--list'])
32
 
        for n in parse_enumeration(output):
33
 
            testids.append('python3.' + n)
34
 
        stream = StreamResultToBytes(sys.stdout)
35
 
        for testid in testids:
36
 
            stream.status(test_id=testid, test_status='exists')
37
 
    else:
38
 
        if args.load_list:
39
 
            py2_tests = []
40
 
            py3_tests = []
41
 
            with open(args.load_list, 'rb') 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()