File: rtest.py

package info (click to toggle)
libvcflib 1.0.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 49,628 kB
  • sloc: cpp: 39,244; perl: 474; python: 329; ruby: 285; sh: 247; ansic: 198; makefile: 131; javascript: 94; lisp: 57
file content (63 lines) | stat: -rw-r--r-- 1,860 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import sys
import pprint
import difflib
import inspect
import re
from subprocess import Popen, PIPE

bindir = "../build"

regressiondir = "data/regression"
tmpdir = "tmp"

VERSION = open("../VERSION").read().strip()

def cat(cmd):
    head(cmd, -1)

def head(cmd, lines=4):
    cmd2 = cmd.split(" ")
    # print("-------------------->",cmd2,file=sys.stderr)
    cmd1 = cmd2[0]
    if not os.path.isfile(cmd1):
        cmd1 = f"{bindir}/{cmd1}"
    cmds = [cmd1]+cmd2[1:]
    p = Popen(cmds, stdout=PIPE, stderr=PIPE, close_fds=True)
    output = p.communicate()
    out = output[0]
    if len(out) == 0:
        # if stdout is empty fetch stderr
        out = output[1]
    # out=subprocess.check_output(cmd2, universal_newlines=True)
    header = out.decode().expandtabs(tabsize=8).split("\n")[0:lines]
    header = ['>' if l=='' else l for l in header]
    header = [l.replace(VERSION+" ", "") for l in header]
    header = [l.replace("../build/", "") for l in header]
    print("\n".join(header))

def run_stdout(cmd, ext = "vcf"):
    os.makedirs(tmpdir,exist_ok=True)
    curframe = inspect.currentframe()
    # pp = pprint.PrettyPrinter(indent=4)
    # pp.pprint(inspect.getouterframes(curframe))
    # print("------------n")
    calframe = inspect.getouterframes(curframe, 1)
    p = re.compile('\[([0-9])\]')
    index = p.findall(calframe[1].filename)[0]

    name = calframe[1].filename[0:-4]
    if "doctest" in name:
        name = name[9:-3]
    else:
        name = name[18:-1]

    name += "_"+index
    if ext:
        name += "." + ext

    tmpfn = tmpdir + "/" + name
    os.system(f"{bindir}/{cmd} > {tmpfn}")
    cmpfn = regressiondir+"/"+name
    sys.stdout.writelines(difflib.unified_diff(open(cmpfn).readlines(),open(tmpfn).readlines(),cmpfn,tmpfn,n=1))
    print(f"output in <a href=\"../data/regression/{name}\">{name}</a>")