forked from python-hydro/pyro2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·129 lines (86 loc) · 3.81 KB
/
test.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python3
from __future__ import print_function
import argparse
import datetime
import nose
import os
import sys
import pyro
import multigrid.mg_test as mg_test
import multigrid.mg_test_vc_dirichlet as mg_test_vc_dirichlet
import multigrid.mg_test_vc_periodic as mg_test_vc_periodic
import multigrid.mg_test_general_inhomogeneous as mg_test_general_inhomogeneous
class PyroTest(object):
def __init__(self, solver, problem, inputs, options):
self.solver = solver
self.problem = problem
self.inputs = inputs
self.options = options
def do_tests(build, out_file, do_standalone=True, do_main=True):
# make sure we've built stuff
print("build = ", build)
if build: os.system("./mk.sh")
opts = "driver.verbose=0 vis.dovis=0 io.do_io=0".split()
results = {}
if do_main:
tests = []
tests.append(PyroTest("advection", "smooth", "inputs.smooth", opts))
tests.append(PyroTest("compressible", "quad", "inputs.quad", opts))
tests.append(PyroTest("compressible", "sod", "inputs.sod.x", opts))
tests.append(PyroTest("compressible", "rt", "inputs.rt", opts))
tests.append(PyroTest("diffusion", "gaussian", "inputs.gaussian", opts))
tests.append(PyroTest("incompressible", "shear", "inputs.shear", opts))
tests.append(PyroTest("lm_atm", "bubble", "inputs.bubble", opts))
for t in tests:
err = pyro.doit(t.solver, t.problem, t.inputs,
other_commands=t.options, comp_bench=True)
results["{}-{}".format(t.solver, t.problem)] = err
# standalone tests
if do_standalone:
err = mg_test.test_poisson_dirichlet(256, comp_bench=True, verbose=0)
results["mg_poisson_dirichlet"] = err
err = mg_test_vc_dirichlet.test_vc_poisson_dirichlet(512, comp_bench=True, verbose=0)
results["mg_vc_poisson_dirichlet"] = err
err = mg_test_vc_periodic.test_vc_poisson_periodic(512, comp_bench=True, verbose=0)
results["mg_vc_poisson_periodic"] = err
err = mg_test_general_inhomogeneous.test_general_poisson_inhomogeneous(512, comp_bench=True, verbose=0)
results["mg_general_poisson_inhomogeneous"] = err
failed = 0
out = [sys.stdout]
if not out_file == None:
out.append(open(out_file, "w"))
for f in out:
f.write("pyro tests run: {}\n\n".format(str(datetime.datetime.now().replace(microsecond=0))))
for s, r in sorted(results.items()):
if not r == 0:
f.write("{:42} failed\n".format(s))
failed += 1
else:
f.write("{:42} passed\n".format(s))
f.write("\n{} test(s) failed\n".format(failed))
if not f == sys.stdout: f.close()
if __name__ == "__main__":
p = argparse.ArgumentParser()
p.add_argument("-o",
help="name of file to output the report to (otherwise output to the screen",
type=str, nargs=1)
p.add_argument("--build",
help="execute the mk.sh script first before any tests",
action="store_true")
p.add_argument("--skip_standalone",
help="skip the tests that don't go through pyro.py",
action="store_true")
p.add_argument("--skip_main",
help="skip the tests that go through pyro.py, and only run standalone tests",
action="store_true")
args = p.parse_args()
try: outfile = args.o[0]
except: outfile = None
build = args.build
do_main = True
if args.skip_main: do_main = False
do_standalone = True
if args.skip_standalone: do_standalone = False
do_tests(build, outfile, do_standalone=do_standalone, do_main=do_main)
# unit tests
nose.run(argv=["", "-s"])