Debian Codegraph @

test/smoketest.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 import json
3 import pathlib
4 import tempfile
5 import subprocess
6 import sys
7
8
9 def smoketest(fname, rest):
10 outfile = pathlib.Path(
11 tempfile.mkdtemp(prefix="scalene") / pathlib.Path("smoketest.json")
12 )
13 cmd = [
14 sys.executable,
15 "-m",
16 "scalene",
17 "--cli",
18 "--json",
19 "--outfile",
20 str(outfile),
21 *rest,
22 fname,
23 ]
24 print("COMMAND", " ".join(cmd))
25 proc = subprocess.run(cmd, capture_output=True)
26 stdout = proc.stdout.decode("utf-8")
27 stderr = proc.stderr.decode("utf-8")
28
29 if proc.returncode != 0:
30 print("Exited with a non-zero code:", proc.returncode)
31 print("STDOUT", stdout)
32 print("STDERR", stderr)
33
34 exit(proc.returncode)
35 # print("STDOUT", stdout)
36 # print("\nSTDERR", stderr)
37 try:
38 with open(outfile, "r") as f:
39 outfile_contents = f.read()
40 scalene_json = json.loads(outfile_contents)
41 except json.JSONDecodeError:
42 print("Invalid JSON", stderr)
43 print("STDOUT", stdout)
44 print("STDERR", stderr)
45 exit(1)
46 if len(scalene_json) == 0:
47 print("No JSON output")
48 print("STDOUT", stdout)
49 print("STDERR", stderr)
50 exit(1)
51 files = scalene_json["files"]
52 if not len(files) > 0:
53 print("No files found in output")
54 exit(1)
55 for _fname in files:
56
57 if not any(
58 (line["n_cpu_percent_c"] > 0 or line["n_cpu_percent_python"] > 0)
59 for line in files[_fname]["lines"]
60 ):
61 print("No non-zero lines in", _fname)
62 exit(1)
63
64
65 if __name__ == "__main__":
66 smoketest(sys.argv[1], sys.argv[2:])