This repository has been archived by the owner on May 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-images.py
98 lines (80 loc) · 2.51 KB
/
test-images.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
import functools
import traceback
import os
from lib import image
tests = {}
def failt(fn, reason):
i = 0
p = str(fn.__name__) +"-"+ str(i)
while p in tests.keys():
i += 1
p = str(fn.__name__) + "-" + str(i)
tests[p] = traceback.format_exc()
print('[FAIL] {}'.format(p))
print('\t{}'.format(reason))
def passt(fn):
i = 0
p = str(fn.__name__) + "-" + str(i)
while p in tests.keys():
i += 1
p = str(fn.__name__) + "-" + str(i)
tests[p] = "PASS"
print("[PASS] {}".format(p))
def test_output_file(method=None, output_file=None):
if not callable(method):
return functools.partial(test_output_file, output_file=output_file)
method.gw_method = output_file or method.__name__
def _decorate(funct):
@functools.wraps(funct)
def wrap(*args, **kwargs):
try:
os.remove(output_file)
except:
pass
try:
funct(*args, **kwargs)
passt(funct)
except:
failt(funct, traceback.format_exc())
finally:
if output_file and not os.path.exists(output_file):
failt(funct, "OUTPUT")
return wrap
return _decorate(method)
testimagejpg = "test-data/test.jpg"
testimagecr2 = "test-data/test.CR2"
@test_output_file(output_file="test-output-resize.jpg")
def test_resize():
image.resize(testimagejpg, "test-output-resize.jpg")
@test_output_file(output_file="test-output-resize.jpg")
def test_resize_vips():
image._resize_vips(testimagejpg, "test-output-resize.jpg")
@test_output_file(output_file="test-output-resize.jpg")
def test_resize_pil():
image._resize_pil(testimagejpg, "test-output-resize.jpg")
@test_output_file()
def test_rotate(angle):
image.rotate_inplace("test-output-resize.jpg", angle)
@test_output_file()
def test_rotate_pil(angle):
image._rotate_pil_inplace("test-output-resize.jpg", angle)
@test_output_file()
def test_rotate_vips(angle):
image._rotate_vips_inplace("test-output-resize.jpg", angle)
@test_output_file(output_file="test-output-resize.tif")
def test_pyramid():
image.pyramid(testimagejpg, "test-output-resize.tif")
if __name__ == "__main__":
test_resize()
test_resize_pil()
test_resize_vips()
test_rotate(0)
test_rotate(90)
test_rotate(270)
test_rotate_vips(0)
test_rotate_vips(90)
test_rotate_vips(270)
test_rotate_pil(0)
test_rotate_pil(90)
test_rotate_pil(270)
test_pyramid()