@@ -5589,6 +5589,54 @@ def test_clamping_mode(self, rotated, constructor_clamping_mode, clamping_mode,
55895589 else :
55905590 assert_equal (out , expected_clamped_output )
55915591
5592+ class TestSetClampingMode :
5593+
5594+ @pytest .mark .parametrize ("format" , list (tv_tensors .BoundingBoxFormat ))
5595+ @pytest .mark .parametrize ("constructor_clamping_mode" , ("hard" , "none" )) # TODOBB add soft
5596+ @pytest .mark .parametrize ("desired_clamping_mode" , ("hard" , "none" )) # TODOBB add soft
5597+ def test_setter (self , format , constructor_clamping_mode , desired_clamping_mode ):
5598+
5599+ in_boxes = make_bounding_boxes (format = format , clamping_mode = constructor_clamping_mode )
5600+ out_boxes = transforms .SetClampingMode (clamping_mode = desired_clamping_mode )(in_boxes )
5601+
5602+ assert in_boxes .clamping_mode == constructor_clamping_mode # input is unchanged: no leak
5603+ assert out_boxes .clamping_mode == desired_clamping_mode
5604+
5605+ @pytest .mark .parametrize ("format" , list (tv_tensors .BoundingBoxFormat ))
5606+ @pytest .mark .parametrize ("constructor_clamping_mode" , ("hard" , "none" )) # TODOBB add soft
5607+ def test_pipeline_no_leak (self , format , constructor_clamping_mode ):
5608+
5609+ class AssertClampingMode (transforms .Transform ):
5610+ def __init__ (self , expected_clamping_mode ):
5611+ super ().__init__ ()
5612+ self .expected_clamping_mode = expected_clamping_mode
5613+
5614+ _transformed_types = (tv_tensors .BoundingBoxes ,)
5615+
5616+ def transform (self , inpt , _ ):
5617+ assert inpt .clamping_mode == self .expected_clamping_mode
5618+ return inpt
5619+
5620+ t = transforms .Compose (
5621+ [
5622+ transforms .SetClampingMode ("none" ),
5623+ AssertClampingMode ("none" ),
5624+ transforms .SetClampingMode ("hard" ),
5625+ AssertClampingMode ("hard" ),
5626+ transforms .SetClampingMode ("none" ),
5627+ AssertClampingMode ("none" ),
5628+ transforms .ClampBoundingBoxes ("hard" )
5629+ ]
5630+ )
5631+
5632+ in_boxes = make_bounding_boxes (format = format , clamping_mode = constructor_clamping_mode )
5633+ out_boxes = t (in_boxes )
5634+
5635+ assert in_boxes .clamping_mode == constructor_clamping_mode # input is unchanged: no leak
5636+
5637+ # assert that the output boxes clamping_mode is the one set by the last SetClampingMode.
5638+ # ClampBoundingBoxes doesn't set clamping_mode.
5639+ assert out_boxes .clamping_mode == "none"
55925640
55935641
55945642class TestClampKeyPoints :
@@ -7376,3 +7424,4 @@ def test_different_sizes(self, make_input1, make_input2, query):
73767424 def test_no_valid_input (self , query ):
73777425 with pytest .raises (TypeError , match = "No image" ):
73787426 query (["blah" ])
7427+
0 commit comments