55
66from .helper import (
77 assert_image_equal ,
8- assert_image_similar ,
8+ assert_image_similar_tofile ,
99 hopper ,
1010 skip_unless_feature ,
1111)
@@ -71,7 +71,7 @@ def helper_arc(bbox, start, end):
7171 draw .arc (bbox , start , end )
7272
7373 # Assert
74- assert_image_similar (im , Image . open ( "Tests/images/imagedraw_arc.png" ) , 1 )
74+ assert_image_similar_tofile (im , "Tests/images/imagedraw_arc.png" , 1 )
7575
7676
7777def test_arc1 ():
@@ -110,47 +110,44 @@ def test_arc_no_loops():
110110 draw .arc (BBOX1 , start = start , end = end )
111111
112112 # Assert
113- assert_image_similar (im , Image . open ( "Tests/images/imagedraw_arc_no_loops.png" ) , 1 )
113+ assert_image_similar_tofile (im , "Tests/images/imagedraw_arc_no_loops.png" , 1 )
114114
115115
116116def test_arc_width ():
117117 # Arrange
118118 im = Image .new ("RGB" , (W , H ))
119119 draw = ImageDraw .Draw (im )
120- expected = "Tests/images/imagedraw_arc_width.png"
121120
122121 # Act
123122 draw .arc (BBOX1 , 10 , 260 , width = 5 )
124123
125124 # Assert
126- assert_image_similar (im , Image . open ( expected ) , 1 )
125+ assert_image_similar_tofile (im , "Tests/images/imagedraw_arc_width.png" , 1 )
127126
128127
129128def test_arc_width_pieslice_large ():
130129 # Tests an arc with a large enough width that it is a pieslice
131130 # Arrange
132131 im = Image .new ("RGB" , (W , H ))
133132 draw = ImageDraw .Draw (im )
134- expected = "Tests/images/imagedraw_arc_width_pieslice.png"
135133
136134 # Act
137135 draw .arc (BBOX1 , 10 , 260 , fill = "yellow" , width = 100 )
138136
139137 # Assert
140- assert_image_similar (im , Image . open ( expected ) , 1 )
138+ assert_image_similar_tofile (im , "Tests/images/imagedraw_arc_width_pieslice.png" , 1 )
141139
142140
143141def test_arc_width_fill ():
144142 # Arrange
145143 im = Image .new ("RGB" , (W , H ))
146144 draw = ImageDraw .Draw (im )
147- expected = "Tests/images/imagedraw_arc_width_fill.png"
148145
149146 # Act
150147 draw .arc (BBOX1 , 10 , 260 , fill = "yellow" , width = 5 )
151148
152149 # Assert
153- assert_image_similar (im , Image . open ( expected ) , 1 )
150+ assert_image_similar_tofile (im , "Tests/images/imagedraw_arc_width_fill.png" , 1 )
154151
155152
156153def test_arc_width_non_whole_angle ():
@@ -163,7 +160,7 @@ def test_arc_width_non_whole_angle():
163160 draw .arc (BBOX1 , 10 , 259.5 , width = 5 )
164161
165162 # Assert
166- assert_image_similar (im , Image . open ( expected ) , 1 )
163+ assert_image_similar_tofile (im , expected , 1 )
167164
168165
169166def test_bitmap ():
@@ -190,7 +187,7 @@ def helper_chord(mode, bbox, start, end):
190187 draw .chord (bbox , start , end , fill = "red" , outline = "yellow" )
191188
192189 # Assert
193- assert_image_similar (im , Image . open ( expected ) , 1 )
190+ assert_image_similar_tofile (im , expected , 1 )
194191
195192
196193def test_chord1 ():
@@ -209,26 +206,24 @@ def test_chord_width():
209206 # Arrange
210207 im = Image .new ("RGB" , (W , H ))
211208 draw = ImageDraw .Draw (im )
212- expected = "Tests/images/imagedraw_chord_width.png"
213209
214210 # Act
215211 draw .chord (BBOX1 , 10 , 260 , outline = "yellow" , width = 5 )
216212
217213 # Assert
218- assert_image_similar (im , Image . open ( expected ) , 1 )
214+ assert_image_similar_tofile (im , "Tests/images/imagedraw_chord_width.png" , 1 )
219215
220216
221217def test_chord_width_fill ():
222218 # Arrange
223219 im = Image .new ("RGB" , (W , H ))
224220 draw = ImageDraw .Draw (im )
225- expected = "Tests/images/imagedraw_chord_width_fill.png"
226221
227222 # Act
228223 draw .chord (BBOX1 , 10 , 260 , fill = "red" , outline = "yellow" , width = 5 )
229224
230225 # Assert
231- assert_image_similar (im , Image . open ( expected ) , 1 )
226+ assert_image_similar_tofile (im , "Tests/images/imagedraw_chord_width_fill.png" , 1 )
232227
233228
234229def test_chord_zero_width ():
@@ -254,7 +249,7 @@ def helper_ellipse(mode, bbox):
254249 draw .ellipse (bbox , fill = "green" , outline = "blue" )
255250
256251 # Assert
257- assert_image_similar (im , Image . open ( expected ) , 1 )
252+ assert_image_similar_tofile (im , expected , 1 )
258253
259254
260255def test_ellipse1 ():
@@ -276,8 +271,8 @@ def test_ellipse_translucent():
276271 draw .ellipse (BBOX1 , fill = (0 , 255 , 0 , 127 ))
277272
278273 # Assert
279- expected = Image . open ( "Tests/images/imagedraw_ellipse_translucent.png" )
280- assert_image_similar (im , expected , 1 )
274+ expected = "Tests/images/imagedraw_ellipse_translucent.png"
275+ assert_image_similar_tofile (im , expected , 1 )
281276
282277
283278def test_ellipse_edge ():
@@ -289,7 +284,7 @@ def test_ellipse_edge():
289284 draw .ellipse (((0 , 0 ), (W - 1 , H )), fill = "white" )
290285
291286 # Assert
292- assert_image_similar (im , Image . open ( "Tests/images/imagedraw_ellipse_edge.png" ) , 1 )
287+ assert_image_similar_tofile (im , "Tests/images/imagedraw_ellipse_edge.png" , 1 )
293288
294289
295290def test_ellipse_symmetric ():
@@ -304,39 +299,36 @@ def test_ellipse_width():
304299 # Arrange
305300 im = Image .new ("RGB" , (W , H ))
306301 draw = ImageDraw .Draw (im )
307- expected = "Tests/images/imagedraw_ellipse_width.png"
308302
309303 # Act
310304 draw .ellipse (BBOX1 , outline = "blue" , width = 5 )
311305
312306 # Assert
313- assert_image_similar (im , Image . open ( expected ) , 1 )
307+ assert_image_similar_tofile (im , "Tests/images/imagedraw_ellipse_width.png" , 1 )
314308
315309
316310def test_ellipse_width_large ():
317311 # Arrange
318312 im = Image .new ("RGB" , (500 , 500 ))
319313 draw = ImageDraw .Draw (im )
320- expected = "Tests/images/imagedraw_ellipse_width_large.png"
321314
322315 # Act
323316 draw .ellipse ((25 , 25 , 475 , 475 ), outline = "blue" , width = 75 )
324317
325318 # Assert
326- assert_image_similar (im , Image . open ( expected ) , 1 )
319+ assert_image_similar_tofile (im , "Tests/images/imagedraw_ellipse_width_large.png" , 1 )
327320
328321
329322def test_ellipse_width_fill ():
330323 # Arrange
331324 im = Image .new ("RGB" , (W , H ))
332325 draw = ImageDraw .Draw (im )
333- expected = "Tests/images/imagedraw_ellipse_width_fill.png"
334326
335327 # Act
336328 draw .ellipse (BBOX1 , fill = "green" , outline = "blue" , width = 5 )
337329
338330 # Assert
339- assert_image_similar (im , Image . open ( expected ) , 1 )
331+ assert_image_similar_tofile (im , "Tests/images/imagedraw_ellipse_width_fill.png" , 1 )
340332
341333
342334def test_ellipse_zero_width ():
@@ -423,7 +415,7 @@ def helper_pieslice(bbox, start, end):
423415 draw .pieslice (bbox , start , end , fill = "white" , outline = "blue" )
424416
425417 # Assert
426- assert_image_similar (im , Image . open ( "Tests/images/imagedraw_pieslice.png" ) , 1 )
418+ assert_image_similar_tofile (im , "Tests/images/imagedraw_pieslice.png" , 1 )
427419
428420
429421def test_pieslice1 ():
@@ -440,13 +432,12 @@ def test_pieslice_width():
440432 # Arrange
441433 im = Image .new ("RGB" , (W , H ))
442434 draw = ImageDraw .Draw (im )
443- expected = "Tests/images/imagedraw_pieslice_width.png"
444435
445436 # Act
446437 draw .pieslice (BBOX1 , 10 , 260 , outline = "blue" , width = 5 )
447438
448439 # Assert
449- assert_image_similar (im , Image . open ( expected ) , 1 )
440+ assert_image_similar_tofile (im , "Tests/images/imagedraw_pieslice_width.png" , 1 )
450441
451442
452443def test_pieslice_width_fill ():
@@ -459,7 +450,7 @@ def test_pieslice_width_fill():
459450 draw .pieslice (BBOX1 , 10 , 260 , fill = "white" , outline = "blue" , width = 5 )
460451
461452 # Assert
462- assert_image_similar (im , Image . open ( expected ) , 1 )
453+ assert_image_similar_tofile (im , expected , 1 )
463454
464455
465456def test_pieslice_zero_width ():
@@ -571,13 +562,12 @@ def test_big_rectangle():
571562 im = Image .new ("RGB" , (W , H ))
572563 bbox = [(- 1 , - 1 ), (W + 1 , H + 1 )]
573564 draw = ImageDraw .Draw (im )
574- expected = "Tests/images/imagedraw_big_rectangle.png"
575565
576566 # Act
577567 draw .rectangle (bbox , fill = "orange" )
578568
579569 # Assert
580- assert_image_similar (im , Image . open ( expected ) , 1 )
570+ assert_image_similar_tofile (im , "Tests/images/imagedraw_big_rectangle.png" , 1 )
581571
582572
583573def test_rectangle_width ():
@@ -878,13 +868,25 @@ def test_wide_line_dot():
878868 # Arrange
879869 im = Image .new ("RGB" , (W , H ))
880870 draw = ImageDraw .Draw (im )
881- expected = "Tests/images/imagedraw_wide_line_dot.png"
882871
883872 # Act
884873 draw .line ([(50 , 50 ), (50 , 50 )], width = 3 )
885874
886875 # Assert
887- assert_image_similar (im , Image .open (expected ), 1 )
876+ assert_image_similar_tofile (im , "Tests/images/imagedraw_wide_line_dot.png" , 1 )
877+
878+
879+ def test_wide_line_larger_than_int ():
880+ # Arrange
881+ im = Image .new ("RGB" , (W , H ))
882+ draw = ImageDraw .Draw (im )
883+ expected = "Tests/images/imagedraw_wide_line_larger_than_int.png"
884+
885+ # Act
886+ draw .line ([(0 , 0 ), (32768 , 32768 )], width = 3 )
887+
888+ # Assert
889+ assert_image_similar_tofile (im , expected , 1 )
888890
889891
890892@pytest .mark .parametrize (
@@ -971,13 +973,12 @@ def test_wide_line_dot():
971973def test_line_joint (xy ):
972974 im = Image .new ("RGB" , (500 , 325 ))
973975 draw = ImageDraw .Draw (im )
974- expected = "Tests/images/imagedraw_line_joint_curve.png"
975976
976977 # Act
977978 draw .line (xy , GRAY , 50 , "curve" )
978979
979980 # Assert
980- assert_image_similar (im , Image . open ( expected ) , 3 )
981+ assert_image_similar_tofile (im , "Tests/images/imagedraw_line_joint_curve.png" , 3 )
981982
982983
983984def test_textsize_empty_string ():
@@ -1018,8 +1019,8 @@ def test_stroke():
10181019 draw .text ((10 , 10 ), "A" , "#f00" , font , stroke_width = 2 , stroke_fill = stroke_fill )
10191020
10201021 # Assert
1021- assert_image_similar (
1022- im , Image . open ( "Tests/images/imagedraw_stroke_" + suffix + ".png" ) , 3.1
1022+ assert_image_similar_tofile (
1023+ im , "Tests/images/imagedraw_stroke_" + suffix + ".png" , 3.1
10231024 )
10241025
10251026
@@ -1034,9 +1035,7 @@ def test_stroke_descender():
10341035 draw .text ((10 , 0 ), "y" , "#f00" , font , stroke_width = 2 , stroke_fill = "#0f0" )
10351036
10361037 # Assert
1037- assert_image_similar (
1038- im , Image .open ("Tests/images/imagedraw_stroke_descender.png" ), 6.76
1039- )
1038+ assert_image_similar_tofile (im , "Tests/images/imagedraw_stroke_descender.png" , 6.76 )
10401039
10411040
10421041@skip_unless_feature ("freetype2" )
@@ -1052,9 +1051,7 @@ def test_stroke_multiline():
10521051 )
10531052
10541053 # Assert
1055- assert_image_similar (
1056- im , Image .open ("Tests/images/imagedraw_stroke_multiline.png" ), 3.3
1057- )
1054+ assert_image_similar_tofile (im , "Tests/images/imagedraw_stroke_multiline.png" , 3.3 )
10581055
10591056
10601057def test_same_color_outline ():
@@ -1093,4 +1090,4 @@ def test_same_color_outline():
10931090 expected = "Tests/images/imagedraw_outline_{}_{}.png" .format (
10941091 operation , mode
10951092 )
1096- assert_image_similar (im , Image . open ( expected ) , 1 )
1093+ assert_image_similar_tofile (im , expected , 1 )
0 commit comments