-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
runtests.py
86 lines (65 loc) · 2.39 KB
/
runtests.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
76
77
78
79
80
81
82
83
84
85
86
from pkg_resources import require
import requests, json, argparse, os, subprocess, xmltodict
envDict = {}
ignoreFiles = [".gitignore",".gitattributes","LICENSE"]
ignoreExt = [".md",".txt",".json",".ps1",".py"]
def findBinaries(basefolder):
testBinaries = []
fileidBinaries = []
for root, dirs, files in os.walk(basefolder):
for file in files:
if file.endswith("_test.exe") or file.endswith("_test"):
testBinaries.append(os.path.join(root,file))
elif file == "fileid.exe" or file == "fid" or file == "fileid":
fileidBinaries.append(os.path.join(root,file))
return fileidBinaries,testBinaries
def runTestBinary(file):
print("Running Test: " + file)
process = subprocess.Popen(file, shell=True, env=envDict)
process.wait()
return process.returncode == 0
def testfiles(fidbin, folder):
allgood = True
for root, dirs, files in os.walk(folder):
if ".git" in dirs:
dirs.remove('.git')
for file in files:
fullpath = os.path.join(root, file)
file_name, file_ext = os.path.splitext(file)
if not file_name in ignoreFiles and not file_ext in ignoreExt:
allgood &= testfile(fidbin, fullpath)
return allgood
def testfile(fid, file, format = "json"):
outputStr = subprocess.check_output([fid, file, format])
output = {}
if format == "json":
output = json.loads(outputStr)
elif format == "xml":
output = xmltodict.parse(outputStr)
actual_ext = [extension["extension"].lower() for extension in output["extensions"]]
filename, expected_ext = os.path.splitext(file)
if "_" in expected_ext:
expected_ext = expected_ext.replace(".","").replace("_",".").lower()
else:
expected_ext = expected_ext.replace(".","").lower()
if expected_ext not in actual_ext:
print("FAIL! (" + expected_ext + "!=" + ",".join(actual_ext) +") " + file)
return False
return True
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run FILEID tests")
parser.add_argument("--build", required=True, help="path to build output")
parser.add_argument("--files", required=True, help="path to directory containing test files")
args = parser.parse_args()
fileids, testbins = findBinaries(args.build)
envDict = dict(os.environ)
envDict["TESTFOLDER"] = args.files
allgood = True
## Run Unit Tests
for testBin in testbins:
allgood &= runTestBinary(testBin)
## Run Test Files
for fid in fileids:
allgood &= testfiles(fid, args.files)
if not allgood:
exit(-10)