Merge pull request #6370 from LostBenjamin/patch-1

Fix wrong operator bug in PyCMSError exception message
This commit is contained in:
mergify[bot] 2022-06-19 13:21:43 +00:00 committed by GitHub
commit 8de74b9fab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 10 deletions

View File

@ -174,19 +174,24 @@ def test_exceptions():
psRGB = ImageCms.createProfile("sRGB") psRGB = ImageCms.createProfile("sRGB")
pLab = ImageCms.createProfile("LAB") pLab = ImageCms.createProfile("LAB")
t = ImageCms.buildTransform(pLab, psRGB, "LAB", "RGB") t = ImageCms.buildTransform(pLab, psRGB, "LAB", "RGB")
with pytest.raises(ValueError): with pytest.raises(ValueError, match="mode mismatch"):
t.apply_in_place(hopper("RGBA")) t.apply_in_place(hopper("RGBA"))
# the procedural pyCMS API uses PyCMSError for all sorts of errors # the procedural pyCMS API uses PyCMSError for all sorts of errors
with hopper() as im: with hopper() as im:
with pytest.raises(ImageCms.PyCMSError): with pytest.raises(ImageCms.PyCMSError, match="cannot open profile file"):
ImageCms.profileToProfile(im, "foo", "bar") ImageCms.profileToProfile(im, "foo", "bar")
with pytest.raises(ImageCms.PyCMSError):
with pytest.raises(ImageCms.PyCMSError, match="cannot open profile file"):
ImageCms.buildTransform("foo", "bar", "RGB", "RGB") ImageCms.buildTransform("foo", "bar", "RGB", "RGB")
with pytest.raises(ImageCms.PyCMSError):
with pytest.raises(ImageCms.PyCMSError, match="Invalid type for Profile"):
ImageCms.getProfileName(None) ImageCms.getProfileName(None)
skip_missing() skip_missing()
with pytest.raises(ImageCms.PyCMSError):
# Python <= 3.9: "an integer is required (got type NoneType)"
# Python > 3.9: "'NoneType' object cannot be interpreted as an integer"
with pytest.raises(ImageCms.PyCMSError, match="integer"):
ImageCms.isIntentSupported(SRGB, None, None) ImageCms.isIntentSupported(SRGB, None, None)
@ -201,15 +206,32 @@ def test_lab_color_profile():
def test_unsupported_color_space(): def test_unsupported_color_space():
with pytest.raises(ImageCms.PyCMSError): with pytest.raises(
ImageCms.PyCMSError,
match=re.escape(
"Color space not supported for on-the-fly profile creation (unsupported)"
),
):
ImageCms.createProfile("unsupported") ImageCms.createProfile("unsupported")
def test_invalid_color_temperature(): def test_invalid_color_temperature():
with pytest.raises(ImageCms.PyCMSError): with pytest.raises(
ImageCms.PyCMSError,
match='Color temperature must be numeric, "invalid" not valid',
):
ImageCms.createProfile("LAB", "invalid") ImageCms.createProfile("LAB", "invalid")
@pytest.mark.parametrize("flag", ("my string", -1))
def test_invalid_flag(flag):
with hopper() as im:
with pytest.raises(
ImageCms.PyCMSError, match="flags must be an integer between 0 and "
):
ImageCms.profileToProfile(im, "foo", "bar", flags=flag)
def test_simple_lab(): def test_simple_lab():
i = Image.new("RGB", (10, 10), (128, 128, 128)) i = Image.new("RGB", (10, 10), (128, 128, 128))
@ -461,9 +483,9 @@ def test_profile_typesafety():
prepatch, these would segfault, postpatch they should emit a typeerror prepatch, these would segfault, postpatch they should emit a typeerror
""" """
with pytest.raises(TypeError): with pytest.raises(TypeError, match="Invalid type for Profile"):
ImageCms.ImageCmsProfile(0).tobytes() ImageCms.ImageCmsProfile(0).tobytes()
with pytest.raises(TypeError): with pytest.raises(TypeError, match="Invalid type for Profile"):
ImageCms.ImageCmsProfile(1).tobytes() ImageCms.ImageCmsProfile(1).tobytes()

View File

@ -377,7 +377,7 @@ def profileToProfile(
raise PyCMSError("renderingIntent must be an integer between 0 and 3") raise PyCMSError("renderingIntent must be an integer between 0 and 3")
if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG): if not isinstance(flags, int) or not (0 <= flags <= _MAX_FLAG):
raise PyCMSError("flags must be an integer between 0 and %s" + _MAX_FLAG) raise PyCMSError(f"flags must be an integer between 0 and {_MAX_FLAG}")
try: try:
if not isinstance(inputProfile, ImageCmsProfile): if not isinstance(inputProfile, ImageCmsProfile):