From ade8a81717dcaa22507dc012dd53f28082f6ebd1 Mon Sep 17 00:00:00 2001 From: Deekshu Kare Date: Wed, 19 Jun 2024 16:56:51 +0200 Subject: [PATCH 1/3] test 1 --- Tests/test_frombytes_image.py | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Tests/test_frombytes_image.py diff --git a/Tests/test_frombytes_image.py b/Tests/test_frombytes_image.py new file mode 100644 index 000000000..68fd1a465 --- /dev/null +++ b/Tests/test_frombytes_image.py @@ -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() + From 9f8f8526316795b7d8ea43b6c24678f1919d433d Mon Sep 17 00:00:00 2001 From: Deekshu Kare Date: Thu, 20 Jun 2024 00:20:37 +0200 Subject: [PATCH 2/3] excluding tests in coverage --- .coveragerc | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/.coveragerc b/.coveragerc index 1d471aacb..8305bfc2f 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,27 +1,25 @@ -# .coveragerc to control coverage.py - -[report] -# Regexes for lines to exclude from consideration -exclude_also = - # Don't complain if non-runnable code isn't run - if 0: - if __name__ == .__main__.: - # Don't complain about debug code - if DEBUG: - # Don't complain about compatibility code for missing optional dependencies - except ImportError - if TYPE_CHECKING: - @abc.abstractmethod - # Empty bodies in protocols or abstract methods - ^\s*def [a-zA-Z0-9_]+\(.*\)(\s*->.*)?:\s*\.\.\.(\s*#.*)?$ - ^\s*\.\.\.(\s*#.*)?$ - -[run] -omit = - # Tests/32bit_segfault_check.py - # Tests/bench_cffi_access.py - # Tests/check_*.py - # Tests/createfontdatachunk.py - Tests/* - src/* - +# .coveragerc to control coverage.py + +[report] +# Regexes for lines to exclude from consideration +exclude_also = + # Don't complain if non-runnable code isn't run + if 0: + if _name_ == ._main_.: + # Don't complain about debug code + if DEBUG: + # Don't complain about compatibility code for missing optional dependencies + except ImportError + if TYPE_CHECKING: + @abc.abstractmethod + # Empty bodies in protocols or abstract methods + ^\s*def [a-zA-Z0-9_]+\(.\)(\s->.)?:\s\.\.\.(\s*#.*)?$ + ^\s*\.\.\.(\s*#.*)?$ + +[run] +omit = + # Tests/32bit_segfault_check.py + # Tests/bench_cffi_access.py + # Tests/check_*.py + # Tests/createfontdatachunk.py + Tests/* \ No newline at end of file From d4976933ccf32ae9d584e4849c9c4b1f4aaea2ce Mon Sep 17 00:00:00 2001 From: Deekshu Kare Date: Thu, 20 Jun 2024 00:25:00 +0200 Subject: [PATCH 3/3] excluding tests in coverage --- .coveragerc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.coveragerc b/.coveragerc index 8305bfc2f..1103cb3f3 100644 --- a/.coveragerc +++ b/.coveragerc @@ -22,4 +22,5 @@ omit = # Tests/bench_cffi_access.py # Tests/check_*.py # Tests/createfontdatachunk.py - Tests/* \ No newline at end of file + Tests/* + src/* \ No newline at end of file