Skip to content
This repository was archived by the owner on Apr 18, 2018. It is now read-only.

Commit 8acbfb6

Browse files
authored
Merge pull request #3 from edoddridge/testreport_parser
Testreport parser
2 parents 1f39f01 + 52d1a4d commit 8acbfb6

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ before_install:
1010
- docker exec -i fc11-testreport ls -altr /MITgcm
1111
- docker exec -i fc11-testreport yum install python-pip
1212
- docker exec -i fc11-testreport yum install gcc-gfortran
13+
- docker exec -i fc11-testreport yum install python-argparse
1314

1415
script:
1516
- echo `pwd`
16-
- docker exec -i fc11-testreport bash -c "cd /MITgcm/verification; ./testreport -t tutorial_barotropic_gyre"
17+
- docker exec -i fc11-testreport bash -c "cd /MITgcm/verification; ./testreport -t tutorial_barotropic_gyre | tee tutorial_barotropic_gyre/testreport_out.txt"
18+
- docker exec -i fc11-testreport bash -c "cd /MITgcm/verification; python verification_parser.py -filename 'tutorial_barotropic_gyre/testreport_out.txt' -threshold 15"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Parse verification outputs."""
2+
3+
import re
4+
5+
def verification_parser(filename, threshold):
6+
with open(filename) as f:
7+
lines = f.readlines()
8+
9+
first_match = True
10+
11+
# extract lines from output
12+
for i, line in enumerate(lines):
13+
if line[:5] == '2 d e':
14+
if first_match:
15+
# skip the first match, since it doesn't contain output,
16+
# but set to false to catch next matches.
17+
first_match = False
18+
else:
19+
test_results = lines[i+2]
20+
21+
# split test_results into a list with values for each number.
22+
# this uses spaces and the < > characters to separate the numbers.
23+
test_results = re.split('[ ><]',test_results)
24+
# ignore the Genmake, depend, make, and run checks, as well as
25+
# the "pass" or "fail" and test name at the end of the line
26+
test_results = test_results[4:-3]
27+
# convert to floats
28+
dp_similarity = []
29+
for i, x in enumerate(test_results):
30+
try:
31+
dp_similarity.append(float(x))
32+
except ValueError:
33+
pass
34+
35+
assert all(elements > threshold for elements in dp_similarity)
36+
37+
if __name__ == '__main__':
38+
39+
import argparse
40+
41+
parser = argparse.ArgumentParser(description='Check that verification simulation passed the test.')
42+
43+
parser.add_argument('-filename', type=str,
44+
help='path to output file from the verification test')
45+
46+
parser.add_argument('-threshold', type=int, default=15,
47+
help='number of decimal places of similarity required for test to pass')
48+
49+
args = parser.parse_args()
50+
51+
verification_parser(**vars(args))

0 commit comments

Comments
 (0)