forked from OpenFAST/r-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunCertTestsLocally.py
75 lines (65 loc) · 2.57 KB
/
runCertTestsLocally.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
"""
This script runs all of the CertTest cases to create a local 'gold standard'
set of solutions.
Usage: python runCertTestsLocally.py openfast_executable
- openfast_executable is an optional argument pointing to the openfast executable of choice.
- if not openfast_executable is given, an attempt will be made to search for one in $PATH
Examples:
$ python runCertTestsLocally.py
$ python runCertTestsLocally.py openfast
$ python runCertTestsLocally.py /openfast/install/bin/openfast
"""
import os
import sys
import shutil
import subprocess
def exitWithError(error, code=1):
print error
sys.exit(code)
# if the local output directory already exists, bail for two reasons
# 1. don't silenty overwrite previous outputs
# 2. the python filesystem methods arent robust enough to do something like 'cp * .'
# error code 2 at this location in meaningful to other programs, do not modify
localDirectory = "outputs-local"
if os.path.isdir(localDirectory):
exitWithError("The local output directory, {}, already exists.".format(localDirectory), 2)
# if no openfast executable was given, search in path
if len(sys.argv) == 1:
try:
devnull = open(os.devnull, 'w')
subprocess.call("openfast", stdout=devnull)
except OSError as e:
if e.errno == os.errno.ENOENT:
exitWithError("{}: openfast\n".format(e) +
"Usage: python runCertTestsLocally.py openfast_executable")
else:
raise
else:
executable = "openfast"
print "Using openfast executable found in path"
# verify that the given executable exists and can be run
elif len(sys.argv) == 2:
executable = sys.argv[1]
try:
devnull = open(os.devnull, 'w')
subprocess.call(executable, stdout=devnull)
except OSError as e:
if e.errno == os.errno.ENOENT:
exitWithError("{}: {}".format(e, executable))
else:
raise
# unhandled arguments so bail
else:
exitWithError("Invalid arguments given: {}\n".format(" ".join(sys.argv)) +
"Usage: python runCertTestsLocally.py openfast_executable")
# get the input files from /inputs
shutil.copytree("inputs", "{}".format(localDirectory))
# run through each case
os.chdir("{}".format(localDirectory))
num = [str(i).zfill(2) for i in range(1,26)]
for n in num:
caseName = "Test{}".format(n)
command = "{} {}.fst > {}.log".format(executable, caseName, caseName)
print "'{}' - running".format(command)
return_code = subprocess.call(command, shell=True)
print "'{}' - finished with exit code {}".format(command, return_code)