@@ -38,49 +38,45 @@ def test_implicitron_from_bins(self) -> None:
3838 def test_implicitron_raise_value_error_bins_is_set_and_try_to_set_lengths (
3939 self ,
4040 ) -> None :
41- with self .assertRaises (ValueError ) as context :
42- ray_bundle = ImplicitronRayBundle (
43- origins = torch .rand (2 , 3 , 4 , 3 ),
44- directions = torch .rand (2 , 3 , 4 , 3 ),
45- lengths = None ,
46- xys = torch .rand (2 , 3 , 4 , 2 ),
47- bins = torch .rand (2 , 3 , 4 , 1 ),
48- )
41+ ray_bundle = ImplicitronRayBundle (
42+ origins = torch .rand (2 , 3 , 4 , 3 ),
43+ directions = torch .rand (2 , 3 , 4 , 3 ),
44+ lengths = None ,
45+ xys = torch .rand (2 , 3 , 4 , 2 ),
46+ bins = torch .rand (2 , 3 , 4 , 14 ),
47+ )
48+ with self .assertRaisesRegex (
49+ ValueError ,
50+ "If the bins attribute is not None you cannot set the lengths attribute." ,
51+ ):
4952 ray_bundle .lengths = torch .empty (2 )
50- self .assertEqual (
51- str (context .exception ),
52- "If the bins attribute is not None you cannot set the lengths attribute." ,
53- )
5453
5554 def test_implicitron_raise_value_error_if_bins_dim_equal_1 (self ) -> None :
56- with self .assertRaises (ValueError ) as context :
55+ with self .assertRaisesRegex (
56+ ValueError , "The last dim of bins must be at least superior or equal to 2."
57+ ):
5758 ImplicitronRayBundle (
5859 origins = torch .rand (2 , 3 , 4 , 3 ),
5960 directions = torch .rand (2 , 3 , 4 , 3 ),
6061 lengths = None ,
6162 xys = torch .rand (2 , 3 , 4 , 2 ),
6263 bins = torch .rand (2 , 3 , 4 , 1 ),
6364 )
64- self .assertEqual (
65- str (context .exception ),
66- "The last dim of bins must be at least superior or equal to 2." ,
67- )
6865
6966 def test_implicitron_raise_value_error_if_neither_bins_or_lengths_provided (
7067 self ,
7168 ) -> None :
72- with self .assertRaises (ValueError ) as context :
69+ with self .assertRaisesRegex (
70+ ValueError ,
71+ "Please set either bins or lengths to initialize an ImplicitronRayBundle." ,
72+ ):
7373 ImplicitronRayBundle (
7474 origins = torch .rand (2 , 3 , 4 , 3 ),
7575 directions = torch .rand (2 , 3 , 4 , 3 ),
7676 lengths = None ,
7777 xys = torch .rand (2 , 3 , 4 , 2 ),
7878 bins = None ,
7979 )
80- self .assertEqual (
81- str (context .exception ),
82- "Please set either bins or lengths to initialize an ImplicitronRayBundle." ,
83- )
8480
8581 def test_conical_frustum_to_gaussian (self ) -> None :
8682 origins = torch .zeros (3 , 3 , 3 )
@@ -266,8 +262,6 @@ def test_conical_frustum_to_gaussian_raise_valueerror(self) -> None:
266262 ray = ImplicitronRayBundle (
267263 origins = origins , directions = directions , lengths = lengths , xys = None
268264 )
269- with self .assertRaises (ValueError ) as context :
270- _ = conical_frustum_to_gaussian (ray )
271265
272266 expected_error_message = (
273267 "RayBundle pixel_radii_2d or bins have not been provided."
@@ -276,7 +270,8 @@ def test_conical_frustum_to_gaussian_raise_valueerror(self) -> None:
276270 "`cast_ray_bundle_as_cone` to True?"
277271 )
278272
279- self .assertEqual (expected_error_message , str (context .exception ))
273+ with self .assertRaisesRegex (ValueError , expected_error_message ):
274+ _ = conical_frustum_to_gaussian (ray )
280275
281276 # Ensure message is coherent with AbstractMaskRaySampler
282277 class FakeRaySampler (AbstractMaskRaySampler ):
0 commit comments