@@ -193,6 +193,21 @@ def test_draw_boxes_with_coloured_label_text_boxes():
193193 assert_equal (result , expected )
194194
195195
196+ @pytest .mark .skipif (PILLOW_VERSION < (10 , 1 ), reason = "The reference image is only valid for PIL >= 10.1" )
197+ @pytest .mark .parametrize ("font_size" , [None , 15 , 20 ])
198+ def test_draw_boxes_with_default_font_size (font_size ):
199+ img = torch .full ((3 , 100 , 100 ), 255 , dtype = torch .uint8 )
200+ labels = ["a" , "b" , "c" , "d" ]
201+ colors = ["green" , "#FF00FF" , (0 , 255 , 0 ), "red" ]
202+ result = utils .draw_bounding_boxes (img , boxes , labels = labels , colors = colors , fill = True , font_size = font_size )
203+
204+ path = os .path .join (
205+ os .path .dirname (os .path .abspath (__file__ )), "assets" , "fakedata" , f"draw_boxes_default_font_size{ font_size } .png"
206+ )
207+ expected = torch .as_tensor (np .array (Image .open (path ))).permute (2 , 0 , 1 )
208+ assert_equal (result , expected )
209+
210+
196211@pytest .mark .skipif (PILLOW_VERSION < (10 , 1 ), reason = "The reference image is only valid for PIL >= 10.1" )
197212def test_draw_rotated_boxes ():
198213 img = torch .full ((3 , 500 , 500 ), 255 , dtype = torch .uint8 )
@@ -289,10 +304,15 @@ def test_draw_invalid_boxes():
289304 utils .draw_bounding_boxes (img_correct , boxes_wrong )
290305
291306
307+ @pytest .mark .skipif (PILLOW_VERSION >= (10 , 1 ), reason = "The warning is only valid for PIL < 10.1" )
292308def test_draw_boxes_warning ():
293309 img = torch .full ((3 , 100 , 100 ), 255 , dtype = torch .uint8 )
294310
295- with pytest .warns (UserWarning , match = re .escape ("Argument 'font_size' will be ignored since 'font' is not set." )):
311+ warning_txt = (
312+ "Argument 'font_size' will be ignored since 'font' is not set. "
313+ "To use 'font_size' with the default font, please upgrade to Pillow >= 10.1."
314+ )
315+ with pytest .warns (UserWarning , match = re .escape (warning_txt )):
296316 utils .draw_bounding_boxes (img , boxes , font_size = 11 )
297317
298318
0 commit comments