88 assert_image_equal ,
99 assert_image_similar ,
1010 assert_image_similar_tofile ,
11- assert_tuple_approx_equal ,
1211 hopper ,
1312)
1413
@@ -291,33 +290,15 @@ def test_colorize_2color() -> None:
291290 im_test = ImageOps .colorize (im_l , "red" , "green" )
292291
293292 # Test output image (2-color)
294- left = (0 , 1 )
295- middle = (127 , 1 )
296- right = (255 , 1 )
297- value = im_test .getpixel (left )
298- assert isinstance (value , tuple )
299- assert_tuple_approx_equal (
300- value ,
301- (255 , 0 , 0 ),
302- threshold = 1 ,
303- msg = "black test pixel incorrect" ,
304- )
305- value = im_test .getpixel (middle )
306- assert isinstance (value , tuple )
307- assert_tuple_approx_equal (
308- value ,
309- (127 , 63 , 0 ),
310- threshold = 1 ,
311- msg = "mid test pixel incorrect" ,
312- )
313- value = im_test .getpixel (right )
314- assert isinstance (value , tuple )
315- assert_tuple_approx_equal (
316- value ,
317- (0 , 127 , 0 ),
318- threshold = 1 ,
319- msg = "white test pixel incorrect" ,
320- )
293+ assert im_test .getpixel ((0 , 1 )) == pytest .approx (
294+ (255 , 0 , 0 ), abs = 1
295+ ), "black test pixel incorrect"
296+ assert im_test .getpixel ((127 , 1 )) == pytest .approx (
297+ (127 , 63 , 0 ), abs = 1
298+ ), "mid test pixel incorrect"
299+ assert im_test .getpixel ((255 , 1 )) == pytest .approx (
300+ (0 , 127 , 0 ), abs = 1
301+ ), "white test pixel incorrect"
321302
322303
323304def test_colorize_2color_offset () -> None :
@@ -333,33 +314,15 @@ def test_colorize_2color_offset() -> None:
333314 )
334315
335316 # Test output image (2-color) with offsets
336- left = (25 , 1 )
337- middle = (75 , 1 )
338- right = (125 , 1 )
339- value = im_test .getpixel (left )
340- assert isinstance (value , tuple )
341- assert_tuple_approx_equal (
342- value ,
343- (255 , 0 , 0 ),
344- threshold = 1 ,
345- msg = "black test pixel incorrect" ,
346- )
347- value = im_test .getpixel (middle )
348- assert isinstance (value , tuple )
349- assert_tuple_approx_equal (
350- value ,
351- (127 , 63 , 0 ),
352- threshold = 1 ,
353- msg = "mid test pixel incorrect" ,
354- )
355- value = im_test .getpixel (right )
356- assert isinstance (value , tuple )
357- assert_tuple_approx_equal (
358- value ,
359- (0 , 127 , 0 ),
360- threshold = 1 ,
361- msg = "white test pixel incorrect" ,
362- )
317+ assert im_test .getpixel ((25 , 1 )) == pytest .approx (
318+ (255 , 0 , 0 ), abs = 1
319+ ), "black test pixel incorrect"
320+ assert im_test .getpixel ((75 , 1 )) == pytest .approx (
321+ (127 , 63 , 0 ), abs = 1
322+ ), "mid test pixel incorrect"
323+ assert im_test .getpixel ((125 , 1 )) == pytest .approx (
324+ (0 , 127 , 0 ), abs = 1
325+ ), "white test pixel incorrect"
363326
364327
365328def test_colorize_3color_offset () -> None :
@@ -381,46 +344,21 @@ def test_colorize_3color_offset() -> None:
381344 )
382345
383346 # Test output image (3-color) with offsets
384- left = (25 , 1 )
385- left_middle = (75 , 1 )
386- middle = (100 , 1 )
387- right_middle = (150 , 1 )
388- right = (225 , 1 )
389- value = im_test .getpixel (left )
390- assert isinstance (value , tuple )
391- assert_tuple_approx_equal (
392- value ,
393- (255 , 0 , 0 ),
394- threshold = 1 ,
395- msg = "black test pixel incorrect" ,
396- )
397- value = im_test .getpixel (left_middle )
398- assert isinstance (value , tuple )
399- assert_tuple_approx_equal (
400- value ,
401- (127 , 0 , 127 ),
402- threshold = 1 ,
403- msg = "low-mid test pixel incorrect" ,
404- )
405- value = im_test .getpixel (middle )
406- assert isinstance (value , tuple )
407- assert_tuple_approx_equal (value , (0 , 0 , 255 ), threshold = 1 , msg = "mid incorrect" )
408- value = im_test .getpixel (right_middle )
409- assert isinstance (value , tuple )
410- assert_tuple_approx_equal (
411- value ,
412- (0 , 63 , 127 ),
413- threshold = 1 ,
414- msg = "high-mid test pixel incorrect" ,
415- )
416- value = im_test .getpixel (right )
417- assert isinstance (value , tuple )
418- assert_tuple_approx_equal (
419- value ,
420- (0 , 127 , 0 ),
421- threshold = 1 ,
422- msg = "white test pixel incorrect" ,
423- )
347+ assert im_test .getpixel ((25 , 1 )) == pytest .approx (
348+ (255 , 0 , 0 ), abs = 1
349+ ), "black test pixel incorrect"
350+ assert im_test .getpixel ((75 , 1 )) == pytest .approx (
351+ (127 , 0 , 127 ), abs = 1
352+ ), "low-mid test pixel incorrect"
353+ assert im_test .getpixel ((100 , 1 )) == pytest .approx (
354+ (0 , 0 , 255 ), abs = 1
355+ ), "mid incorrect"
356+ assert im_test .getpixel ((150 , 1 )) == pytest .approx (
357+ (0 , 63 , 127 ), abs = 1
358+ ), "high-mid test pixel incorrect"
359+ assert im_test .getpixel ((225 , 1 )) == pytest .approx (
360+ (0 , 127 , 0 ), abs = 1
361+ ), "white test pixel incorrect"
424362
425363
426364def test_colorize_invalid_mode () -> None :
@@ -594,18 +532,12 @@ def test_autocontrast_mask_real_input() -> None:
594532 result_nomask = ImageOps .autocontrast (img )
595533
596534 assert result_nomask != result
597- assert_tuple_approx_equal (
598- ImageStat .Stat (result , mask = rect_mask ).median ,
599- (195 , 202 , 184 ),
600- threshold = 2 ,
601- msg = "autocontrast with mask pixel incorrect" ,
602- )
603- assert_tuple_approx_equal (
604- ImageStat .Stat (result_nomask ).median ,
605- (119 , 106 , 79 ),
606- threshold = 2 ,
607- msg = "autocontrast without mask pixel incorrect" ,
608- )
535+ assert ImageStat .Stat (result , mask = rect_mask ).median == pytest .approx (
536+ (195 , 202 , 184 ), abs = 2
537+ ), "autocontrast with mask pixel incorrect"
538+ assert ImageStat .Stat (result_nomask ).median == pytest .approx (
539+ (119 , 106 , 79 ), abs = 2
540+ ), "autocontrast without mask pixel incorrect"
609541
610542
611543def test_autocontrast_preserve_tone () -> None :
0 commit comments