From 7e4fd9d84591a220d142cbc4652b18250984cf41 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 18 Apr 2021 14:47:05 +1000 Subject: [PATCH] Changed incorrect mode errors to ValueError --- Tests/test_imagemorph.py | 14 +++++++------- src/PIL/ImageMorph.py | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Tests/test_imagemorph.py b/Tests/test_imagemorph.py index eb41d2d08..368c2bba1 100644 --- a/Tests/test_imagemorph.py +++ b/Tests/test_imagemorph.py @@ -235,19 +235,19 @@ def test_negate(): ) -def test_non_binary_images(): +def test_incorrect_mode(): im = hopper("RGB") mop = ImageMorph.MorphOp(op_name="erosion8") - with pytest.raises(Exception) as e: + with pytest.raises(ValueError) as e: mop.apply(im) - assert str(e.value) == "Image must be binary, meaning it must use mode L" - with pytest.raises(Exception) as e: + assert str(e.value) == "Image mode must be L" + with pytest.raises(ValueError) as e: mop.match(im) - assert str(e.value) == "Image must be binary, meaning it must use mode L" - with pytest.raises(Exception) as e: + assert str(e.value) == "Image mode must be L" + with pytest.raises(ValueError) as e: mop.get_on_pixels(im) - assert str(e.value) == "Image must be binary, meaning it must use mode L" + assert str(e.value) == "Image mode must be L" def test_add_patterns(): diff --git a/src/PIL/ImageMorph.py b/src/PIL/ImageMorph.py index b76dfa01f..fe0083754 100644 --- a/src/PIL/ImageMorph.py +++ b/src/PIL/ImageMorph.py @@ -196,7 +196,7 @@ class MorphOp: raise Exception("No operator loaded") if image.mode != "L": - raise Exception("Image must be binary, meaning it must use mode L") + raise ValueError("Image mode must be L") outimage = Image.new(image.mode, image.size, None) count = _imagingmorph.apply(bytes(self.lut), image.im.id, outimage.im.id) return count, outimage @@ -211,7 +211,7 @@ class MorphOp: raise Exception("No operator loaded") if image.mode != "L": - raise Exception("Image must be binary, meaning it must use mode L") + raise ValueError("Image mode must be L") return _imagingmorph.match(bytes(self.lut), image.im.id) def get_on_pixels(self, image): @@ -221,7 +221,7 @@ class MorphOp: of all matching pixels. See :ref:`coordinate-system`.""" if image.mode != "L": - raise Exception("Image must be binary, meaning it must use mode L") + raise ValueError("Image mode must be L") return _imagingmorph.get_on_pixels(image.im.id) def load_lut(self, filename):