@@ -80,15 +80,12 @@ def test_lut(op: str) -> None:
8080def test_no_operator_loaded () -> None :
8181 im = Image .new ("L" , (1 , 1 ))
8282 mop = ImageMorph .MorphOp ()
83- with pytest .raises (Exception ) as e :
83+ with pytest .raises (Exception , match = "No operator loaded" ) :
8484 mop .apply (im )
85- assert str (e .value ) == "No operator loaded"
86- with pytest .raises (Exception ) as e :
85+ with pytest .raises (Exception , match = "No operator loaded" ):
8786 mop .match (im )
88- assert str (e .value ) == "No operator loaded"
89- with pytest .raises (Exception ) as e :
87+ with pytest .raises (Exception , match = "No operator loaded" ):
9088 mop .save_lut ("" )
91- assert str (e .value ) == "No operator loaded"
9289
9390
9491# Test the named patterns
@@ -238,15 +235,12 @@ def test_incorrect_mode() -> None:
238235 im = hopper ("RGB" )
239236 mop = ImageMorph .MorphOp (op_name = "erosion8" )
240237
241- with pytest .raises (ValueError ) as e :
238+ with pytest .raises (ValueError , match = "Image mode must be L" ) :
242239 mop .apply (im )
243- assert str (e .value ) == "Image mode must be L"
244- with pytest .raises (ValueError ) as e :
240+ with pytest .raises (ValueError , match = "Image mode must be L" ):
245241 mop .match (im )
246- assert str (e .value ) == "Image mode must be L"
247- with pytest .raises (ValueError ) as e :
242+ with pytest .raises (ValueError , match = "Image mode must be L" ):
248243 mop .get_on_pixels (im )
249- assert str (e .value ) == "Image mode must be L"
250244
251245
252246def test_add_patterns () -> None :
@@ -279,9 +273,10 @@ def test_pattern_syntax_error() -> None:
279273 lb .add_patterns (new_patterns )
280274
281275 # Act / Assert
282- with pytest .raises (Exception ) as e :
276+ with pytest .raises (
277+ Exception , match = 'Syntax error in pattern "a pattern with a syntax error"'
278+ ):
283279 lb .build_lut ()
284- assert str (e .value ) == 'Syntax error in pattern "a pattern with a syntax error"'
285280
286281
287282def test_load_invalid_mrl () -> None :
@@ -290,9 +285,8 @@ def test_load_invalid_mrl() -> None:
290285 mop = ImageMorph .MorphOp ()
291286
292287 # Act / Assert
293- with pytest .raises (Exception ) as e :
288+ with pytest .raises (Exception , match = "Wrong size operator file!" ) :
294289 mop .load_lut (invalid_mrl )
295- assert str (e .value ) == "Wrong size operator file!"
296290
297291
298292def test_roundtrip_mrl (tmp_path : Path ) -> None :
0 commit comments