55designed to be run with pytest:
66"""
77
8- import hashlib
98from pathlib import Path
9+
1010import numpy as np
1111
1212
1313from py_gd import Image , Animation # noqa: F821
1414from py_gd .color_ramp import ColorRamp
1515
16+ from .test_gd import check_file
17+
1618HERE = 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
5456def 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
160162def 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
190194def 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
215221def 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
240251def 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
272285def 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
305320def 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
328345def 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