-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest.py
executable file
·63 lines (50 loc) · 1.97 KB
/
test.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
#!/usr/bin/python3
from os import listdir, path
import sys
from functions.GenKeyBySerialNum import *
from functions.GenKeyBySerialNum_CBT import *
from functions.GenKeyBySerialNumConfigLength import *
from functions.GenKeyBySerialNumConfigLengthOld import *
from functions.GenKeyBySerialNumMethod2 import *
from functions.GenKeyBySerialNumMethod3 import *
from functions.IsApplyRandomAdminPasswordNewAlgorithm import *
currentDir = path.dirname(path.realpath(__file__))
testDir = path.join(currentDir, "tests")
anyFailed = False
for testFile in listdir(testDir):
serialNumber = testFile[0:-4]
testFile = path.join(testDir, testFile)
contents = open(testFile, "r").read()
print(serialNumber)
for line in contents.split("\n"):
if (len(line) == 0): continue
expectedSeperator = line.index(": ")
params = "\"" + serialNumber + "\""
extraParams = ""
function = ""
if (not "(" in line[:expectedSeperator]):
function = line[:expectedSeperator]
else:
paramsStart = line.index("(") + 1
paramsEnd = line.index(")")
function = line[:paramsStart - 1]
extraParams = line[paramsStart: paramsEnd]
params = params + ", " + extraParams
expected = line[expectedSeperator + 2:]
trimmedFunctionName = function[12:]
try:
result = eval(function + "(" + params + ")")
lastParam = extraParams[-1] if len(extraParams) > 0 else ""
testName = trimmedFunctionName + "(" + lastParam + ")"
if (expected != result):
print(" \033[91mFail\033[0m: {:36}: expected \033[96m{:>8}\033[0m but got \033[96m{:>8}\033[0m".format(testName, expected, result))
anyFailed = True
else:
print(" \033[92mPass\033[0m: {}".format(testName))
except NameError:
continue
if (anyFailed):
exitCode = 1
else:
exitCode = 0
sys.exit(exitCode)