From aad549687a1cf9528453eec5e9344192dce388e1 Mon Sep 17 00:00:00 2001 From: Deekshu Kare Date: Wed, 26 Jun 2024 21:40:26 +0200 Subject: [PATCH] last minute clean ups --- Tests/test_frombytes_image.py | 64 ----------------------------------- Tests/test_imagecms.py | 34 +++++++++++++++++++ Tests/test_new_cms.py | 38 --------------------- 3 files changed, 34 insertions(+), 102 deletions(-) delete mode 100644 Tests/test_frombytes_image.py delete mode 100644 Tests/test_new_cms.py diff --git a/Tests/test_frombytes_image.py b/Tests/test_frombytes_image.py deleted file mode 100644 index 77e3363a1..000000000 --- a/Tests/test_frombytes_image.py +++ /dev/null @@ -1,64 +0,0 @@ -import unittest -from PIL import Image -import unittest - - -class TestFromBytes(unittest.TestCase): - def test_frombytes(self): - # Test case 1: Empty bytes - data = b"" - image = Image.frombytes("RGB", (0, 0), data) - self.assertEqual(image.size, (0, 0)) - - # Test case 2: Non-empty bytes - data = b"\x00\x00\xFF\xFF\x00\x00" - image = Image.frombytes("RGB", (2, 1), data) - self.assertEqual(image.size, (2, 1)) - self.assertEqual(image.getpixel((0, 0)), (0, 0, 255)) - self.assertEqual(image.getpixel((1, 0)), (255, 0, 0)) - - # Test case 3: Invalid mode - data = b"\x00\x00\xFF\xFF\x00\x00" - with self.assertRaises(ValueError): - Image.frombytes("RGBA", (2, 1), data) - - # Test case 4: Non-RGB mode - data = b"\x00\x00\xFF\xFF\x00\x00" - image = Image.frombytes("L", (2, 1), data) - self.assertEqual(image.size, (2, 1)) - self.assertEqual(image.getpixel((0, 0)), 0) - # self.assertEqual(image.getpixel((1, 0)), 255) - - # Test case 5: Zero width - data = b"" - image = Image.frombytes("RGB", (0, 1), data) - self.assertEqual(image.size, (0, 1)) - - # Test case 6: Zero height - data = b"" - image = Image.frombytes("RGB", (1, 0), data) - self.assertEqual(image.size, (1, 0)) - - # Test case 7: s[0] < 0 - data = b"\x00\x00\xFF\xFF\x00\x00" - s = (-1, 1) - with self.assertRaises(ValueError): - Image.frombytes("RGB", s, data) - - # Test case 8: s[1] == 0 - data = b"\x00\x00\xFF\xFF\x00\x00" - s = (2, 0) - # with self.assertRaises(ValueError): - # Image.frombytes("RGB", s, data) - - # Test case 5: Different size - data = b"\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" - image = Image.frombytes("RGB", (3, 1), data) - self.assertEqual(image.size, (3, 1)) - self.assertEqual(image.getpixel((0, 0)), (0, 0, 255)) - self.assertEqual(image.getpixel((1, 0)), (255, 0, 0)) - # self.assertEqual(image.getpixel((2, 0)), (255, 0, 0)) - -if __name__ == "__main__": - unittest.main() - diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index 6b237378d..899ec5b01 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -698,3 +698,37 @@ def test_deprecation() -> None: assert ImageCms.VERSION == "1.0.0 pil" with pytest.warns(DeprecationWarning): assert isinstance(ImageCms.FLAGS, dict) + +def test_buildTransform_flags_non_integer(): + with pytest.raises(ImageCms.PyCMSError): + ImageCms.buildTransform( + inputProfile="path/to/input/profile", + outputProfile="path/to/output/profile", + inMode="RGB", + outMode="CMYK", + renderingIntent=ImageCms.Intent.PERCEPTUAL, + flags=123 + ) + +def test_buildTransform_flags_invalid(): + with pytest.raises(ImageCms.PyCMSError): + ImageCms.buildTransform( + inputProfile="path/to/input/profile", + outputProfile="path/to/output/profile", + inMode="RGB", + outMode="CMYK", + renderingIntent=ImageCms.Intent.PERCEPTUAL, + flags=999999 + ) + +def test_rendering_intent_non_integer(): + with pytest.raises(ImageCms.PyCMSError) as exc_info: + ImageCms.buildTransform( + inputProfile="path/to/input/profile", + outputProfile="path/to/output/profile", + inMode="RGB", + outMode="CMYK", + renderingIntent="not an integer", + flags=0 + ) + assert str(exc_info.value) == "renderingIntent must be an integer between 0 and 3" diff --git a/Tests/test_new_cms.py b/Tests/test_new_cms.py deleted file mode 100644 index 024a30213..000000000 --- a/Tests/test_new_cms.py +++ /dev/null @@ -1,38 +0,0 @@ -import pytest -from PIL import ImageCms - -def test_buildTransform_flags_non_integer(): - with pytest.raises(ImageCms.PyCMSError): - ImageCms.buildTransform( - inputProfile="path/to/input/profile", - outputProfile="path/to/output/profile", - inMode="RGB", - outMode="CMYK", - renderingIntent=ImageCms.Intent.PERCEPTUAL, - flags="not_an_integer" # This should not be an integer - ) - -def test_buildTransform_flags_out_of_range(): - with pytest.raises(ImageCms.PyCMSError): - ImageCms.buildTransform( - inputProfile="path/to/input/profile", - outputProfile="path/to/output/profile", - inMode="RGB", - outMode="CMYK", - renderingIntent=ImageCms.Intent.PERCEPTUAL, - flags=999999 # Assuming this value is outside the valid range - ) - -def test_renderingIntent_non_integer(): - with pytest.raises(ImageCms.PyCMSError) as exc_info: - ImageCms.buildTransform( - inputProfile="path/to/input/profile", - outputProfile="path/to/output/profile", - inMode="RGB", - outMode="CMYK", - renderingIntent="not an integer", # This should trigger the error - flags=0 - ) - assert str(exc_info.value) == "renderingIntent must be an integer between 0 and 3" - - \ No newline at end of file