/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: 2018-06-29 17:57:21 UTC
  • mto: This revision was merged to the branch mainline in revision 7026.
  • Revision ID: jelmer@jelmer.uk-20180629175721-ptg2fk3k2lul7lch
Fix some more tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
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
parser = argparse.ArgumentParser(
 
12
    description="Test runner that supports both Python 2 and Python 3.")
 
13
 
 
14
parser.add_argument(
 
15
    "--load-list", metavar="PATH", help="Path to read list of tests to run from.",
 
16
    type=str)
 
17
parser.add_argument(
 
18
    "--list", help="List available tests.", action="store_true")
 
19
 
 
20
args = parser.parse_args()
 
21
 
 
22
if args.list:
 
23
    testids = []
 
24
    with subprocess.Popen(['python', './brz', 'selftest', '--subunit2', '--list'],
 
25
                         stdout=subprocess.PIPE).stdout as f:
 
26
        for n in parse_enumeration(f.read()):
 
27
            testids.append('python2.' + n)
 
28
    with subprocess.Popen(['python3', './brz', 'selftest', '--subunit2', '--list'],
 
29
                         stdout=subprocess.PIPE).stdout as f:
 
30
        for n in parse_enumeration(f.read()):
 
31
            testids.append('python3.' + n)
 
32
    stream = StreamResultToBytes(sys.stdout)
 
33
    for testid in testids:
 
34
        stream.status(test_id=testid, test_status='exists')
 
35
else:
 
36
    if args.load_list:
 
37
        py2_tests = []
 
38
        py3_tests = []
 
39
        with open(args.load_list, 'r') as f:
 
40
            all_tests = parse_list(f.read())
 
41
        for testname in all_tests:
 
42
            if testname.startswith("python2."):
 
43
                py2_tests.append(testname[len('python2.'):].strip())
 
44
            elif testname.startswith("python3."):
 
45
                py3_tests.append(testname[len('python3.'):].strip())
 
46
            else:
 
47
                sys.stderr.write("unknown prefix %s\n" % testname)
 
48
        if py2_tests:
 
49
            with tempfile.NamedTemporaryFile() as py2f:
 
50
                write_list(py2f, py2_tests)
 
51
                py2f.flush()
 
52
                subprocess.call(
 
53
                    'python ./brz selftest --subunit2 --load-list=%s | subunit-filter -s --passthrough --rename "^" "python2."' % py2f.name, shell=True)
 
54
 
 
55
        if py3_tests:
 
56
            with tempfile.NamedTemporaryFile() as py3f:
 
57
                write_list(py3f, py3_tests)
 
58
                py3f.flush()
 
59
                subprocess.call(
 
60
                    'python3 ./brz selftest --subunit2 --load-list=%s | subunit-filter -s --passthrough --rename "^" "python3."' % py3f.name, shell=True)
 
61
    else:
 
62
        subprocess.call(
 
63
            'python ./brz selftest --subunit2 | subunit-filter -s --passthrough --rename "^" "python2."', shell=True)
 
64
        subprocess.call(
 
65
            'python3 ./brz selftest --subunit2 | subunit-filter -s --passthrough --rename "^" "python3."', shell=True)