File: smoketest.py

package info (click to toggle)
scalene 1.5.51-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,528 kB
  • sloc: cpp: 22,930; python: 13,403; javascript: 11,769; ansic: 817; makefile: 196; sh: 45
file content (49 lines) | stat: -rw-r--r-- 1,585 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
import json
import pathlib
import tempfile
import subprocess
import sys

def smoketest(fname, rest):
    outfile = pathlib.Path(tempfile.mkdtemp(prefix="scalene") / pathlib.Path("smoketest.json"))
    cmd = [sys.executable, "-m", "scalene", "--cli", "--json", "--outfile", str(outfile), *rest, fname]
    print("COMMAND", ' '.join(cmd))
    proc = subprocess.run(cmd ,capture_output=True)
    stdout = proc.stdout.decode('utf-8')
    stderr = proc.stderr.decode('utf-8')

    if proc.returncode != 0:
        print("Exited with a non-zero code:", proc.returncode)
        print("STDOUT", stdout)
        print("STDERR", stderr)

        exit(proc.returncode)
   #    print("STDOUT", stdout)
#    print("\nSTDERR", stderr)
    try:
        with open(outfile, "r") as f:
            outfile_contents = f.read()
        scalene_json = json.loads(outfile_contents)
    except json.JSONDecodeError:
        print("Invalid JSON", stderr)
        print("STDOUT", stdout)
        print("STDERR", stderr)
        exit(1)
    if len(scalene_json) == 0:
        print("No JSON output")
        print("STDOUT", stdout)
        print("STDERR", stderr)
        exit(1)
    files = scalene_json['files']
    if not len(files) > 0:
        print("No files found in output")
        exit(1)
    for _fname in files:

        if not any( (line['n_cpu_percent_c'] > 0 or line['n_cpu_percent_python'] > 0) for line in files[_fname]['lines']):
            print("No non-zero lines in", _fname)
            exit(1)

if __name__ == '__main__':
    smoketest(sys.argv[1], sys.argv[2:])