mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-13 17:52:22 +03:00
Merge branch 'main' into duru
This commit is contained in:
commit
bdd7bf1d87
53
.coveragerc
53
.coveragerc
|
@ -1,27 +1,26 @@
|
||||||
# .coveragerc to control coverage.py
|
# .coveragerc to control coverage.py
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
# Regexes for lines to exclude from consideration
|
# Regexes for lines to exclude from consideration
|
||||||
exclude_also =
|
exclude_also =
|
||||||
# Don't complain if non-runnable code isn't run
|
# Don't complain if non-runnable code isn't run
|
||||||
if 0:
|
if 0:
|
||||||
if __name__ == .__main__.:
|
if _name_ == ._main_.:
|
||||||
# Don't complain about debug code
|
# Don't complain about debug code
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
# Don't complain about compatibility code for missing optional dependencies
|
# Don't complain about compatibility code for missing optional dependencies
|
||||||
except ImportError
|
except ImportError
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
# Empty bodies in protocols or abstract methods
|
# Empty bodies in protocols or abstract methods
|
||||||
^\s*def [a-zA-Z0-9_]+\(.*\)(\s*->.*)?:\s*\.\.\.(\s*#.*)?$
|
^\s*def [a-zA-Z0-9_]+\(.\)(\s->.)?:\s\.\.\.(\s*#.*)?$
|
||||||
^\s*\.\.\.(\s*#.*)?$
|
^\s*\.\.\.(\s*#.*)?$
|
||||||
|
|
||||||
[run]
|
[run]
|
||||||
omit =
|
omit =
|
||||||
# Tests/32bit_segfault_check.py
|
# Tests/32bit_segfault_check.py
|
||||||
# Tests/bench_cffi_access.py
|
# Tests/bench_cffi_access.py
|
||||||
# Tests/check_*.py
|
# Tests/check_*.py
|
||||||
# Tests/createfontdatachunk.py
|
# Tests/createfontdatachunk.py
|
||||||
Tests/*
|
Tests/*
|
||||||
src/*
|
src/*
|
||||||
|
|
64
Tests/test_frombytes_image.py
Normal file
64
Tests/test_frombytes_image.py
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
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()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user