-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.py
68 lines (65 loc) · 1.68 KB
/
tests.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
from __future__ import print_function
def quitwith(s):
print(s)
raise Exception
print("importing jpeg")
import jpeg
print("loading a jpeg with a number")
try:
a = jpeg.Jpeg(0)
quitwith("this should have failed!")
except Exception as e:
print(e)
print("loading a jpeg with a nonsense filename")
try:
a = jpeg.Jpeg("")
quitwith("this should have failed!")
except Exception as e:
print(e)
print("loading a jpeg with a non-jpeg file")
try:
a = jpeg.Jpeg(".")
quitwith("this should have failed!")
except Exception as e:
print(e)
print("loading a file with jpeg magic")
try:
with open("magic", "wb") as magic:
magic.write("ffd8".decode("hex"))
a = jpeg.Jpeg("magic")
quitwith("this should have failed!")
except Exception as e:
print(e)
print("loading a real jpeg")
a = jpeg.Jpeg("out.jpg")
print("getting block")
block = a.getblock(0,0,0)
print("setting block with itself")
a.setblock(0,0,0,block)
print("setting block with too-small buffer")
try:
a.setblock(0,0,0,block[:1])
quitwith("this should have failed!")
except Exception as e:
print(e)
print("setting block with None")
try:
a.setblock(0,0,0,None)
quitwith("this should have failed!")
except Exception as e:
print(e)
print("writing jpeg")
a.write("out2.jpg")
def testblocks(a,b):
err = False
for comp in range(a.component_count):
xmax, ymax = a.getcomponentdimensions(comp)
for y in range(ymax):
for x in range(xmax):
if a.getblock(x,y,comp) != b.getblock(x,y,comp):
print("block at {},{} in component {} doesn't match original".format(x,y,comp))
err = True
return err
b = jpeg.Jpeg("out2.jpg")
if not testblocks(a,b):
print("all blocks from written jpeg match original")