-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
executable file
·116 lines (92 loc) · 2.07 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python3
import glob
import sys
import os
import os.path
import shutil
import subprocess
import hashlib
BOOMAGAMERGER="./boomagamerger"
OUT_DIR="out"
def sha256Sum(filename, block_size=65536):
sha256 = hashlib.sha256()
with open(filename, 'rb') as f:
for block in iter(lambda: f.read(block_size), b''):
sha256.update(block)
return sha256.hexdigest()
class CheckError(BaseException):
pass
def testFile(pdfFile):
name=os.path.splitext(os.path.basename(pdfFile))[0]
outDir = OUT_DIR + "/" + name
resultFile = "%s/result.pdf" % outDir
try:
os.makedirs(outDir)
except FileExistsError:
pass
myEnv = os.environ.copy()
myEnv["BOOMAGAMERGER_DEBUGPAGES"] = "YES"
FNULL = open(os.devnull, 'w')
subprocess.check_call([
BOOMAGAMERGER,
pdfFile,
"0", "0",
resultFile
],
stdout=FNULL,
env=myEnv)
subprocess.check_call([
"gs",
"-q",
"-sDEVICE=png16m",
"-o", ("%s/%%03d_expected.png" % outDir),
#"-r144",
pdfFile
])
subprocess.check_call([
"gs",
"-q",
"-sDEVICE=png16m",
"-o", ("%s/%%03d_result.png" % outDir),
#"-r144",
resultFile
])
for expected in glob.glob("%s/*_expected.png" % outDir):
#if sha256Sum(expected)
result = expected[:-13] + "_result.png"
if sha256Sum(expected) != sha256Sum(result):
print("Compared files are not the same:")
print(" expected: ", expected)
print(" result: ", result)
raise CheckError
def main():
if not os.path.isfile(BOOMAGAMERGER):
print("Error: boomagamerger not foud, please copy boomagamerger into this directory.")
sys.exit(1)
files = []
if len(sys.argv) > 1:
files = sys.argv[1:]
else:
files = glob.glob('*.pdf')
files.sort()
try:
shutil.rmtree(OUT_DIR)
except FileNotFoundError:
pass
okCnt=0
errCnt=0
for inFile in files:
print(inFile)
try:
testFile(inFile)
except CheckError as e:
print(" FAIL!")
errCnt+=1
else:
print(" PASS")
okCnt+=1
print("")
print("-----------------------------------------------")
print("Totals: %d passed, %d failed" % (okCnt, errCnt))
if __name__ == "__main__":
main()