File indexing completed on 2021-04-16 05:12:41 UTC
view on githubraw file Latest commit b27f3400 on 2021-04-07 14:07:28 UTC
dcd2743bdb Ed D*0001 """Parse verification outputs."""
0002
0003 import re
0004 import glob
0005 import os
0006
ccfd6c9b7c Chri*0007 def verification_parser(filename, threshold, input_dir_pat):
dcd2743bdb Ed D*0008
0009
0010 (directory, _) = os.path.split(filename)
0011
ccfd6c9b7c Chri*0012 num_exps = len(glob.glob(directory+input_dir_pat))+1
dcd2743bdb Ed D*0013
0014
0015 if len(threshold) != num_exps:
0016
0017 if len(threshold)==1:
0018 error_message = '{0} value given for threshold, '.format(len(threshold))
0019 else:
0020 error_message = '{0} values given for threshold, '.format(len(threshold))
0021
0022 if num_exps==1:
0023 error_message = error_message + 'but {0} subtest found.'.format(num_exps)
0024 else:
0025 error_message = error_message + 'but {0} subtests found.'.format(num_exps)
0026
0027 raise ValueError(error_message)
0028
0029
0030 with open(filename) as f:
0031 lines = f.readlines()
0032
0033 first_match = True
0034
0035
0036 for i, line in enumerate(lines):
0037 if line[:5] == '2 d e':
0038 if first_match:
0039
0040
0041 first_match = False
0042 else:
0043
0044 output_line = i
0045 break
0046
0047
0048 for j in xrange(len(threshold)):
0049 test_results = lines[output_line+2+j]
0050
0051
0052
b27f340083 Oliv*0053 test_results = re.split('[ ><]+',test_results)
1f2be90d9e Ed D*0054
0055
0056 for status in test_results[:4]:
0057 assert status== 'Y'
0058
0059
0060
b27f340083 Oliv*0061 test_results = test_results[4:-2]
1f2be90d9e Ed D*0062
dcd2743bdb Ed D*0063
0064 dp_similarity = []
0065 for i, x in enumerate(test_results):
0066 try:
0067 dp_similarity.append(float(x))
0068 except ValueError:
0069 pass
0070
0071
b27f340083 Oliv*0072 if len(dp_similarity) == 3:
0073
0074
0075 del dp_similarity[2]
0076 elif len(dp_similarity) >= 17:
dcd2743bdb Ed D*0077
0078
0079
0080
0081 del dp_similarity[15]
0082 del dp_similarity[11]
0083
0084 assert all(elements >= threshold[j] for elements in dp_similarity)
0085
0086 if __name__ == '__main__':
0087
0088 import argparse
0089
0090 parser = argparse.ArgumentParser(description='Check that verification simulation passed the test.')
0091
0092 parser.add_argument('-filename', type=str,
0093 help='path to output file from the verification test')
0094
0095 parser.add_argument('-threshold',nargs='+', type=int, default=15,
0096 help='number of decimal places of similarity required for test to pass. Requires a value for each sub test. Separate values with a space.')
0097
ccfd6c9b7c Chri*0098 parser.add_argument('-input_dir_pat', type=str, default='/input.*',
c32b71a53d chri*0099 help='Directory pattern for searching for sub-experiments for base, oad, adm, tlm. Default /input.*')
0100
dcd2743bdb Ed D*0101 args = parser.parse_args()
0102
0103 verification_parser(**vars(args))