-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
38 lines (27 loc) · 1.05 KB
/
test.py
File metadata and controls
38 lines (27 loc) · 1.05 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
import os
import sys
from cidr_freeze_parser import parse_args_and_process_files
def run_tests():
overwrite = len(sys.argv) > 1 and sys.argv[1] == "--overwrite"
for f in os.listdir('testdata'):
if f.endswith('.gold') or f.endswith('.out'):
continue
file_name = 'testdata/' + f
gold_name = file_name + ".gold"
out_name = file_name + ".out"
if os.path.exists(out_name):
os.remove(out_name)
with open(gold_name) as gold_file:
result = parse_args_and_process_files([file_name])
gold = gold_file.readlines()
if "".join(result).strip() != prepare_gold(gold):
with open(out_name, "w") as out_file:
out_file.writelines(result)
print(f + " failed")
if overwrite:
print("Overwriting...")
os.rename(out_name, gold_name)
def prepare_gold(gold):
return "".join(filter(lambda g: g != "\n", gold)).strip()
if __name__ == '__main__':
run_tests()