Debian Codegraph @

selftest/format-subunit-json

raw
1 #!/usr/bin/env python3
2 # Copyright (C) 2008-2010 Jelmer Vernooij <[email protected]>
3 # Copyright (C) 2016 Douglas Bagnall <[email protected]>
4 # Published under the GNU GPL, v3 or later
5 import optparse
6 import os
7 import signal
8 import sys
9 import json
10
11 sys.path.insert(0, "bin/python")
12
13
14 def json_formatter(src_f, dest_f):
15 """We're not even pretending to be a TestResult subclass; just read
16 from stdin and look for elapsed-time tags."""
17 results = {}
18
19 for line in src_f:
20 line = line.strip()
21 if line[:14] == 'elapsed-time: ':
22 name, time = line[14:].rsplit(':', 1)
23 results[name] = float(time)
24
25 json.dump(results, dest_f,
26 sort_keys=True, indent=2, separators=(',', ': '))
27
28
29 def main():
30 parser = optparse.OptionParser("format-subunit-json [options]")
31 parser.add_option("--verbose", action="store_true",
32 help="ignored, for compatibility")
33 parser.add_option("--immediate", action="store_true",
34 help="ignored, for compatibility")
35 parser.add_option("--prefix", type="string", default=".",
36 help="Prefix to write summary.json to")
37 opts, args = parser.parse_args()
38
39 fn = os.path.join(opts.prefix, "summary.json")
40 f = open(fn, 'w')
41 json_formatter(sys.stdin, f)
42 f.close()
43 print()
44 print("A JSON file summarising these tests performance found in:")
45 print(" ", fn)
46
47
48 def handle_sigint(sig, stack):
49 sys.exit(0)
50
51 signal.signal(signal.SIGINT, handle_sigint)
52 main()