diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index 968667892..2dac43ee5 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -699,3 +699,5 @@ def test_deprecation() -> None: assert ImageCms.VERSION == "1.0.0 pil" with pytest.warns(DeprecationWarning): assert isinstance(ImageCms.FLAGS, dict) + + diff --git a/Tests/test_imagecms_init.py b/Tests/test_imagecms_init.py deleted file mode 100644 index 2f4fc8d00..000000000 --- a/Tests/test_imagecms_init.py +++ /dev/null @@ -1,46 +0,0 @@ -import pytest -from PIL import ImageCms -from PIL.ImageCms import ImageCmsProfile - -def test_ImageCmsProfile_init(): - # Test with a filename - profile_filename = "path/to/profile.icc" - profile = ImageCmsProfile(profile_filename) - assert profile.filename == profile_filename - - # Test with a file-like object - profile_file = open("path/to/profile.icc", "rb") - profile = ImageCmsProfile(profile_file) - assert profile.filename is None - - # Test with a low-level profile object - low_level_profile = core.profile_open(profile_filename) - profile = ImageCmsProfile(low_level_profile) - assert profile.filename is None - - # Test with an invalid type - with pytest.raises(TypeError): - ImageCmsProfile(123) - - - - -# def test_ImageCmsProfile_init_win32(): -# profile_path = "path/to/profile.icc" -# profile_bytes = b"ICC_PROFILE_DATA" - -# with open(profile_path, "rb") as f: -# profile_data = f.read() - -# with pytest.raises(TypeError): -# ImageCmsProfile(profile_path) - -# with pytest.raises(TypeError): -# ImageCmsProfile(profile_bytes) - -# profile = ImageCmsProfile(profile_data) - -# assert profile.filename is None -# assert profile.profile is not None -# assert profile.product_name is None -# assert profile.product_info is None \ No newline at end of file diff --git a/Tests/test_imagefile.py b/Tests/test_imagefile.py index 1863c20a9..d68cdfb0f 100644 --- a/Tests/test_imagefile.py +++ b/Tests/test_imagefile.py @@ -397,3 +397,12 @@ class TestPyEncoder(CodecsTest): def test_zero_height(self) -> None: with pytest.raises(UnidentifiedImageError): Image.open("Tests/images/zero_height.j2k") + + def test_encode_to_file_branches(self) -> None: + mock_file = BytesIO() + encoder = ImageFile.PyEncoder("RGB") + encoder.branches = {"1": False, "2": False} + errcode = encoder.encode_to_file(mock_file, 1024) + assert encoder.branches["1"] is True + assert encoder.branches["2"] is True + assert errcode == 0 diff --git a/src/PIL/test_ImageFile.py b/src/PIL/test_ImageFile.py new file mode 100644 index 000000000..1c43a38d6 --- /dev/null +++ b/src/PIL/test_ImageFile.py @@ -0,0 +1,25 @@ +from io import BytesIO +import pytest +from PIL import ImageFile + +def test_encode_to_file_branches(): + # Create a mock file object + mock_file = io.BytesIO() + + # Create a PyEncoder instance + encoder = ImageFile.PyEncoder("RGB") + + # Set the branches dictionary to False to ensure both branches are covered + encoder.branches = {"1": False, "2": False} + + # Call the encode_to_file method + errcode = encoder.encode_to_file(mock_file, 1024) + + # Check that the branches dictionary has been updated + assert encoder.branches["1"] is True + assert encoder.branches["2"] is True + + # Check that the error code is 0, indicating successful encoding + assert errcode == 0 + + mock_file = BytesIO() \ No newline at end of file