Skip to content

Commit a994627

Browse files
put the checksums in a python file, added more checks for animation files
cleaned up some lint
1 parent 3910efe commit a994627

7 files changed

Lines changed: 147 additions & 119 deletions

File tree

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ exclude =
1313
conf.py
1414
build
1515
dist
16+
./build_gd.py
17+
checksums.py

build_gd.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
look in the "if __name__" clause at the bottom:
1212
you can turn on and off different libs, and different parts of the process
1313
14-
1514
"""
1615

1716
import os
@@ -24,7 +23,7 @@
2423
# use this if you want the full install of hdf and netcdf available on your system
2524
# prefix = "/usr/local"
2625

27-
print "Installing libs to:", prefix
26+
print("Installing libs to:", prefix)
2827

2928
if not os.path.exists(prefix):
3029
os.mkdir(prefix)
@@ -37,7 +36,7 @@ def download(name):
3736

3837
# see if it's already there:
3938
if os.path.isfile(name):
40-
print "%s already there -- not downloading again"%name
39+
print("%s already there -- not downloading again"%name)
4140
return
4241

4342
## note: bitbucket does not seem t o support direct download links liek this
@@ -53,18 +52,18 @@ def download(name):
5352
cmd = 'curl -L --output {0} http://sourceforge.net/projects/libpng/files/libpng16/1.6.3/libpng-1.6.3.tar.gz'.format(name)
5453
else:
5554
raise Exception("I don't know how to download: %s"%name)
56-
print "downloading:", name
57-
print cmd
55+
print("downloading:", name)
56+
print(cmd)
5857

5958
os.system(cmd)
6059

6160
def unpack(lib):
6261
if os.path.isdir(lib):
63-
print "%s already unpacked, not unpacking again"%lib
62+
print("%s already unpacked, not unpacking again"%lib)
6463
return
6564
lib = lib +'.tar.gz'
6665
cmd = "tar -xvf "+lib
67-
print "Unpacking:", cmd
66+
print("Unpacking:", cmd)
6867
os.system( cmd )
6968

7069
def configure(lib):
@@ -83,7 +82,7 @@ def configure(lib):
8382
conf = './configure ' + ' '.join(flags)
8483

8584
os.chdir(lib)
86-
print conf
85+
print(conf)
8786
os.system("make clean")
8887
if os.system(conf):
8988
os.chdir(cwd)

py_gd/test/build_checksums.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
images_dir = "test_images_output"
1616
checksums = {}
1717
for name in os.listdir("test_images_output"):
18+
if ".DS_Store" in name:
19+
continue
1820
n = os.path.join("test_images_output", name)
1921
checksums[name] = hashlib.md5(open(n, 'rb').read()).hexdigest()
2022

21-
pprint(checksums)
23+
with open("checksums.py", 'w', encoding='utf-8') as outfile:
24+
outfile.write("checksums = ")
25+
pprint(checksums, stream=outfile)

py_gd/test/checksums.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
checksums = {'file—name_with_unicode.png': '30eb0faa2123ae24cdffb0d98714b834',
2+
'image_clip.bmp': '6adb4af2332bedec46815f86ac462b9f',
3+
'image_copy.bmp': 'a0e7ffb4ecada86965fcfc60a032cad4',
4+
'image_copy_middle1.bmp': '0ac48cdf5e2652999a33efa6c558a9b7',
5+
'image_copy_middle2.bmp': '09be326e5940e58dfdfa492e03d7e818',
6+
'image_copy_trans.png': '8939012bbd494ec19c8afa639eedafb8',
7+
'image_copy_upper_left.bmp': '24f96fb535350df3cdcdc25bcb95a25a',
8+
'nothing.gif': 'fa2e02f338a8ab98c5c1f3cd280ca505',
9+
'one_frame_delete.gif': '35d46c172f95bf79fa66eb0c4f114ada',
10+
'sample_BW.png': 'a211aaa9093b345bc2c7944aaef76899',
11+
'sample_cividis.png': '5b6af4aa252d0a84969dfe93cdb489ae',
12+
'sample_css4.png': 'b1281b61e5ae0fcf8b4df6a668b6755e',
13+
'sample_inferno.png': '850806ac80c706bf510d38443d3b145a',
14+
'sample_magma.png': '0ebdc1856554e2ed441cf94883a59bf9',
15+
'sample_plasma.png': 'd1e954be4f07b5b4b2bd712022525425',
16+
'sample_tableau.png': '8572a2ff7b7a888238f5d51564ea5cee',
17+
'sample_transparent.png': 'a60406f4c35294111ab6a1eda9eeb63a',
18+
'sample_turbo.png': 'c19b0b0c474ba425c3f5015a086aa8c8',
19+
'sample_twilight.png': 'ef008e3ca66132b49e7ff11d96ac0ba7',
20+
'sample_viridis.png': '8fe4956a7c00136e132ade927b433982',
21+
'sample_web.png': '5d5a8f1de03282ea675cf591eb32b815',
22+
'sample_xkcd.png': '83dd36fb952930d99ac4e68f23045906',
23+
'test_animation.gif': '3abc5d1963116b1a05701978b048ac8a',
24+
'test_animation_multi_colors.gif': 'cd2bd56019572503e31aee6f000f10b4',
25+
'test_animation_reset1.gif': 'a53e5aaebcf441f002927b913c12f213',
26+
'test_animation_reset2.gif': 'ec5961189acd876f73f8132707f13c82',
27+
'test_animation_reset_same.gif': 'ec5961189acd876f73f8132707f13c82',
28+
'test_animation_reuse.gif': 'a45117a3d17f1093d5e395fcc20e69e1',
29+
'test_animation_reuse_not_close.gif': '7587576ac36cd0e2e8bcd8ee4ff52b82',
30+
'test_animation_static.gif': '4639911d250a50f9a76a24bb23031921',
31+
'test_control_points.png': '0d4600278f63c502b4ceafe376148011',
32+
'test_draw_dots_multi_color_indices.png': '415db687d254a58eb6d4cabc4be22ea8',
33+
'test_draw_dots_multi_named_colors.png': 'ca7a67f726517e341b55366a7b08b48e',
34+
'test_image_arc.bmp': 'c0a3c29d49922cac32e4a6fae5c9ac4e',
35+
'test_image_array1.bmp': 'e268130b61eaecdc9d809b771909f7b6',
36+
'test_image_array2.bmp': 'e268130b61eaecdc9d809b771909f7b6',
37+
'test_image_circle.bmp': 'bc3e62938f64c5c084d176b99e7e156a',
38+
'test_image_clear_after.png': 'b6825be7e699ea19bd2571c3b4864dac',
39+
'test_image_clear_after2.png': '30bc477928a84571e60925fd61013a94',
40+
'test_image_clear_before.png': 'd34a1e3576b2732321f32c4ee1117730',
41+
'test_image_clear_before2.png': 'd34a1e3576b2732321f32c4ee1117730',
42+
'test_image_dot.png': '275c79433ded774c5cfebaf45fc8c9fb',
43+
'test_image_dots_large.png': '6eb04cc1e853e29aad7abf0f50fe1e3e',
44+
'test_image_dots_lots.png': 'fa0e7397e03adf2be1f262e4f0134d4f',
45+
'test_image_ellipse.bmp': '543ec0befeb67d131f4df23eeb21e590',
46+
'test_image_grey.bmp': '46f3b8773ac4d552944a2eb378ba27e8',
47+
'test_image_line.bmp': 'd279707389a3bac62c4413839919b962',
48+
'test_image_line_clip.bmp': 'fe6e5505f60428d47a64124cbb86c68d',
49+
'test_image_pixel.bmp': '1bf9f74b1122d8b3cc4a955c7216feb7',
50+
'test_image_points.png': 'd16cb5b8b309f570940db8c17bccd9a1',
51+
'test_image_points3.png': '984de9e7f1ec017db9c26a19c8e05c14',
52+
'test_image_poly1.bmp': 'd4654eb592716d5fe73c0661b39b39a7',
53+
'test_image_poly2.bmp': '066f46e0363d1c04b002ea1d6716a07f',
54+
'test_image_poly3.bmp': '4fa4411acb4aee16a1c6a2e15df44cc5',
55+
'test_image_polygon_clip.bmp': 'fb8037129941fd6c9e2686f0c109496b',
56+
'test_image_polyline.bmp': '01d7d25972d69796af9fefc67a1e17af',
57+
'test_image_rectangle.bmp': 'f0eff1deadc678b78e26bd1a4cd88810',
58+
'test_image_save.bmp': '1facb71e1f6d0e21abfb8b07ae900a49',
59+
'test_image_save.gif': '50f1d8d494edba646813b7e7ab830e64',
60+
'test_image_save.jpg': 'e6d5a45b093988240cbe3d0365c0675a',
61+
'test_image_save.png': '3067832d58ce76285b7e32d3f42e2659',
62+
'test_image_spline_polygon.png': 'f71ff8d679ed1860a0b032e71a473dc1',
63+
'test_image_spline_polyline.png': 'af9c837b42d5ab88e175416edd7b0ce7',
64+
'test_image_text.bmp': 'a7b1fe64f4da978706d857c39ce5c026',
65+
'test_image_with_colorramp.png': '5089e9a03e0a7c594462d77676341bd8',
66+
'test_image_x_large.png': 'e57caa7c4304f3806eb3f327ff717076',
67+
'test_image_x_lots.png': '4a5d3d96f286b39f795a4422196947bb',
68+
'test_polyline_from_ctrl_points.png': 'cc0ca4db098d7c8e54e0d2bdca0482e9',
69+
'test_smooth_poly.png': '49da823dd438bb9d3ae23781c535f870',
70+
'test_smooth_polyline.png': 'cc0ca4db098d7c8e54e0d2bdca0482e9',
71+
'test_spline_1.png': '3c89b4aa7dfd1eda601d7016925a7b60',
72+
'test_spline_2.png': '16ed4f5f857d57288d23b632e1839fa1',
73+
'test_spline_flat.png': 'bd75cdd52bfdec87648f3a894f8e83b6',
74+
'test_spline_single_ctrl_pt.png': 'f9d3414d24c0a282cb5b5af17c7b12c2',
75+
'test_text_align.bmp': '3151fe59ab1177fe6fde144dedae1082',
76+
'test_text_background.bmp': 'da827b0d1bba63eba680d7328153c82d'}

py_gd/test/test_animation.py

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
designed to be run with pytest:
66
"""
77

8-
import hashlib
98
from pathlib import Path
9+
1010
import numpy as np
1111

1212

1313
from py_gd import Image, Animation # noqa: F821
1414
from py_gd.color_ramp import ColorRamp
1515

16+
from .test_gd import check_file
17+
1618
HERE = Path(__file__).parent
1719

1820

@@ -24,31 +26,31 @@ def outfile(file_name):
2426
return output_dir / file_name
2527

2628

27-
def check_file(name):
28-
"""
29-
checks if the checksum of the passed in filename is the same as it was
30-
the last time the checksums were generated...
31-
"""
32-
# checksums of all the images generated.
33-
# rebuild with the build_checksums.py script
34-
# you may need to do that with a new libjpeg version, for instance
35-
# it would be nice if all images were checked, but only a few are now...
36-
checksums = {
37-
'test_animation.gif': '3abc5d1963116b1a05701978b048ac8a',
38-
'test_animation_reset1.gif': 'a53e5aaebcf441f002927b913c12f213',
39-
'test_animation_reset2.gif': 'ec5961189acd876f73f8132707f13c82',
40-
'test_animation_reset_same.gif': 'ec5961189acd876f73f8132707f13c82',
41-
'test_animation_reuse.gif': 'a45117a3d17f1093d5e395fcc20e69e1',
42-
'test_animation_reuse_not_close.gif': '7587576ac36cd0e2e8bcd8ee4ff52b82',
43-
'test_animation_static.gif': '4639911d250a50f9a76a24bb23031921',
44-
}
45-
46-
cs = hashlib.md5(open(outfile(name), 'rb').read()).hexdigest()
47-
if checksums[name] == cs:
48-
return True
49-
else:
50-
print("Checksum did not match for file:", name)
51-
return False
29+
# def check_file(name):
30+
# """
31+
# checks if the checksum of the passed in filename is the same as it was
32+
# the last time the checksums were generated...
33+
# """
34+
# # checksums of all the images generated.
35+
# # rebuild with the build_checksums.py script
36+
# # you may need to do that with a new libjpeg version, for instance
37+
# # it would be nice if all images were checked, but only a few are now...
38+
# checksums = {
39+
# 'test_animation.gif': '3abc5d1963116b1a05701978b048ac8a',
40+
# 'test_animation_reset1.gif': 'a53e5aaebcf441f002927b913c12f213',
41+
# 'test_animation_reset2.gif': 'ec5961189acd876f73f8132707f13c82',
42+
# 'test_animation_reset_same.gif': 'ec5961189acd876f73f8132707f13c82',
43+
# 'test_animation_reuse.gif': 'a45117a3d17f1093d5e395fcc20e69e1',
44+
# 'test_animation_reuse_not_close.gif': '7587576ac36cd0e2e8bcd8ee4ff52b82',
45+
# 'test_animation_static.gif': '4639911d250a50f9a76a24bb23031921',
46+
# }
47+
48+
# cs = hashlib.md5(open(outfile(name), 'rb').read()).hexdigest()
49+
# if checksums[name] == cs:
50+
# return True
51+
# else:
52+
# print("Checksum did not match for file:", name)
53+
# return False
5254

5355

5456
def rotating_line(size=200):
@@ -93,7 +95,6 @@ def test_animation():
9395
print(f"{anim.frames_written} frames were written")
9496
assert anim.frames_written == 22
9597

96-
# should check checksum!
9798
assert check_file(fname)
9899

99100

@@ -125,7 +126,8 @@ def test_animation_multi_images_colors():
125126
# animation. Otherwise the global palette is assumed and the user must
126127
# make sure the palettes match. Use gdImagePaletteCopy to do that.
127128

128-
anim = Animation(outfile("test_animation_multi_colors.gif"),
129+
outfilename = "test_animation_multi_colors.gif"
130+
anim = Animation(outfile(outfilename),
129131
delay=20,
130132
global_colormap=0)
131133

@@ -154,7 +156,7 @@ def test_animation_multi_images_colors():
154156
print(f"{anim.frames_written} frames were written")
155157
assert anim.frames_written == count
156158

157-
# should check the checksum
159+
assert check_file(outfilename)
158160

159161

160162
def test_static_animation():
@@ -186,6 +188,8 @@ def test_static_animation():
186188
# duplicate images should have added to delay, rather than adding an image
187189
assert anim.frames_written == 21
188190

191+
assert check_file("test_animation_static.gif")
192+
189193

190194
def test_animation_reuse_filename():
191195
"""
@@ -211,6 +215,8 @@ def test_animation_reuse_filename():
211215
print(f"{anim.frames_written} frames were written")
212216
assert anim.frames_written == 21
213217

218+
assert check_file("test_animation_reuse.gif")
219+
214220

215221
def test_animation_reuse_filename_not_close():
216222
"""
@@ -236,6 +242,11 @@ def test_animation_reuse_filename_not_close():
236242
print(f"{anim.frames_written} frames were written")
237243
assert anim.frames_written == 21
238244

245+
# this should run the __dealloc__
246+
del anim
247+
248+
assert check_file("test_animation_reuse_not_close.gif")
249+
239250

240251
def test_animation_reset_new_filename():
241252
"""
@@ -268,6 +279,8 @@ def test_animation_reset_new_filename():
268279
print(f"{anim.frames_written} frames were written")
269280
assert anim.frames_written == 21
270281

282+
assert check_file("test_animation_reset2.gif")
283+
271284

272285
def test_animation_reset_same_filename():
273286
"""
@@ -301,6 +314,8 @@ def test_animation_reset_same_filename():
301314
print(f"{anim.frames_written} frames were written")
302315
assert anim.frames_written == 21
303316

317+
assert check_file("test_animation_reset_same.gif")
318+
304319

305320
def test_animation_delete_before_use():
306321
"""
@@ -324,10 +339,13 @@ def test_animation_delete_before_use():
324339
del anim
325340
assert filename.exists()
326341

342+
assert check_file("nothing.gif")
343+
327344

328345
def test_animation_delete_one_frame():
329346
"""
330347
make sure the dealloc creates a valid gif with only one frame added
348+
(so two frames -- the first and one more added )
331349
"""
332350
filename = outfile("one_frame_delete.gif")
333351
anim = Animation(filename)
@@ -338,3 +356,5 @@ def test_animation_delete_one_frame():
338356
del anim
339357

340358
assert filename.exists()
359+
360+
assert check_file("one_frame_delete.gif")

0 commit comments

Comments
 (0)