mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	Merge pull request #6370 from LostBenjamin/patch-1
Fix wrong operator bug in PyCMSError exception message
This commit is contained in:
		
						commit
						8de74b9fab
					
				| 
						 | 
				
			
			@ -174,19 +174,24 @@ def test_exceptions():
 | 
			
		|||
    psRGB = ImageCms.createProfile("sRGB")
 | 
			
		||||
    pLab = ImageCms.createProfile("LAB")
 | 
			
		||||
    t = ImageCms.buildTransform(pLab, psRGB, "LAB", "RGB")
 | 
			
		||||
    with pytest.raises(ValueError):
 | 
			
		||||
    with pytest.raises(ValueError, match="mode mismatch"):
 | 
			
		||||
        t.apply_in_place(hopper("RGBA"))
 | 
			
		||||
 | 
			
		||||
    # the procedural pyCMS API uses PyCMSError for all sorts of errors
 | 
			
		||||
    with hopper() as im:
 | 
			
		||||
        with pytest.raises(ImageCms.PyCMSError):
 | 
			
		||||
        with pytest.raises(ImageCms.PyCMSError, match="cannot open profile file"):
 | 
			
		||||
            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")
 | 
			
		||||
    with pytest.raises(ImageCms.PyCMSError):
 | 
			
		||||
 | 
			
		||||
    with pytest.raises(ImageCms.PyCMSError, match="Invalid type for Profile"):
 | 
			
		||||
        ImageCms.getProfileName(None)
 | 
			
		||||
    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)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -201,15 +206,32 @@ def test_lab_color_profile():
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
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")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@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():
 | 
			
		||||
    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
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    with pytest.raises(TypeError):
 | 
			
		||||
    with pytest.raises(TypeError, match="Invalid type for Profile"):
 | 
			
		||||
        ImageCms.ImageCmsProfile(0).tobytes()
 | 
			
		||||
    with pytest.raises(TypeError):
 | 
			
		||||
    with pytest.raises(TypeError, match="Invalid type for Profile"):
 | 
			
		||||
        ImageCms.ImageCmsProfile(1).tobytes()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -377,7 +377,7 @@ def profileToProfile(
 | 
			
		|||
        raise PyCMSError("renderingIntent must be an integer between 0 and 3")
 | 
			
		||||
 | 
			
		||||
    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:
 | 
			
		||||
        if not isinstance(inputProfile, ImageCmsProfile):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user