@@ -80,15 +80,12 @@ def test_lut(op: str) -> None:
80
80
def test_no_operator_loaded () -> None :
81
81
im = Image .new ("L" , (1 , 1 ))
82
82
mop = ImageMorph .MorphOp ()
83
- with pytest .raises (Exception ) as e :
83
+ with pytest .raises (Exception , match = "No operator loaded" ) :
84
84
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" ):
87
86
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" ):
90
88
mop .save_lut ("" )
91
- assert str (e .value ) == "No operator loaded"
92
89
93
90
94
91
# Test the named patterns
@@ -238,15 +235,12 @@ def test_incorrect_mode() -> None:
238
235
im = hopper ("RGB" )
239
236
mop = ImageMorph .MorphOp (op_name = "erosion8" )
240
237
241
- with pytest .raises (ValueError ) as e :
238
+ with pytest .raises (ValueError , match = "Image mode must be L" ) :
242
239
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" ):
245
241
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" ):
248
243
mop .get_on_pixels (im )
249
- assert str (e .value ) == "Image mode must be L"
250
244
251
245
252
246
def test_add_patterns () -> None :
@@ -279,9 +273,10 @@ def test_pattern_syntax_error() -> None:
279
273
lb .add_patterns (new_patterns )
280
274
281
275
# 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
+ ):
283
279
lb .build_lut ()
284
- assert str (e .value ) == 'Syntax error in pattern "a pattern with a syntax error"'
285
280
286
281
287
282
def test_load_invalid_mrl () -> None :
@@ -290,9 +285,8 @@ def test_load_invalid_mrl() -> None:
290
285
mop = ImageMorph .MorphOp ()
291
286
292
287
# Act / Assert
293
- with pytest .raises (Exception ) as e :
288
+ with pytest .raises (Exception , match = "Wrong size operator file!" ) :
294
289
mop .load_lut (invalid_mrl )
295
- assert str (e .value ) == "Wrong size operator file!"
296
290
297
291
298
292
def test_roundtrip_mrl (tmp_path : Path ) -> None :
0 commit comments