-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_test.py
More file actions
70 lines (57 loc) · 2.22 KB
/
run_test.py
File metadata and controls
70 lines (57 loc) · 2.22 KB
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
'''
Created on Sep 27, 2014
@author: scobb
'''
import os
import subprocess
from find_mwmcm import main
def rename(dir, files, results_dir, tag):
out_tag = 'test_out'
for file in files:
if 'out' in file:
new_filename = tag + file.replace('file','').replace('out', out_tag)
else:
new_filename = tag + file.replace('file', '')
subprocess.call(['cp', os.path.join(dir, file),
os.path.join(results_dir, new_filename)])
def check(dir):
outputs = []
correct_outputs = []
for f in os.listdir(dir):
if '.out' in f:
outputs.append(os.path.join(dir, f))
elif '.test_out' in f:
correct_outputs.append(os.path.join(dir, f))
outputs.sort()
correct_outputs.sort()
for i in range(len(outputs)):
print ('checking %s against %s' % (outputs[i], correct_outputs[i]))
process = subprocess.Popen(['diff', outputs[i], correct_outputs[i]], stdout=subprocess.PIPE)
out, err = process.communicate()
if out:
print ('Failed diff:\nours: %s\ntheirs: %s\ndiff: %s\n' %(outputs[i],
correct_outputs[i],
out))
return
print( "Check returned successful.")
def cleanup(res_dir):
for f in os.listdir(res_dir):
os.remove(os.path.join(res_dir, f))
if __name__ == '__main__':
script_dir = os.getcwd()
test_dir = os.path.join(script_dir, 'test_dir')
small_dir = os.path.join(test_dir, 'small')
med_dir = os.path.join(test_dir, 'medium')
large_dir = os.path.join(test_dir, 'large')
results_dir = os.path.join(test_dir, 'results')
small_files = os.listdir(small_dir)
med_files = os.listdir(med_dir)
large_files = os.listdir(large_dir)
rename(small_dir, small_files, results_dir, 'small')
rename(med_dir, med_files, results_dir, 'med')
rename(large_dir, large_files, results_dir, 'large')
for in_file in os.listdir(results_dir):
if '.in' in in_file:
main(os.path.join(results_dir, in_file))
check(results_dir)
cleanup(results_dir)