-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
executable file
·81 lines (57 loc) · 1.67 KB
/
run.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
import webbrowser
import sys
import os
import shutil
import pytest
import glob
import fdrsp.makehtml
import fdrsp
FUNCTIONALS = "tested_functionals"
def main():
config = {"tmp": "sample_tests", "functional_file": FUNCTIONALS}
args = parse_input()
assert_dalton()
save_selected_functionals(args)
logs = run_tests(**config)
fdrsp.html(*logs, **config)
if not args.no_view:
view_logs(**config)
def parse_input():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"xc", nargs="*", default=[], help="Exchange-correlation functionals"
)
parser.add_argument(
"-f", "--file", help="Exchange-correlation functionals"
)
parser.add_argument(
"-n",
"--no-view",
action="store_true",
help="Do not open results in browser",
)
args = parser.parse_args()
return args
def assert_dalton():
if not shutil.which("dalton"):
print("Dalton not in PATH")
sys.exit(1)
def save_selected_functionals(args):
with open(FUNCTIONALS, "w") as funcs:
if args.file:
with open(args.file) as f:
funcs.write(f.read())
elif args.xc:
funcs.write("\n".join(args.xc))
def run_tests(**config):
tests = glob.glob(os.path.join(config["tmp"], "test_findif*.py"))
logs = [os.path.splitext(test)[0] + ".log" for test in tests]
for test, log in zip(tests, logs):
pytest.main([test, "-v", "--junit-xml", log])
return logs
def view_logs(**config):
webbrowser.open_new_tab(os.path.join(config["tmp"], "index.html"))
if __name__ == "__main__":
sys.exit(main())