mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-20 17:22:00 +03:00
last minute clean ups
This commit is contained in:
parent
8d623b9fd1
commit
aad549687a
|
@ -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()
|
||||
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user