mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 07:57:27 +03:00 
			
		
		
		
	test_imagefile.py improvement
This commit is contained in:
		
							parent
							
								
									8a11f09e71
								
							
						
					
					
						commit
						1bd1526ae6
					
				|  | @ -699,3 +699,5 @@ def test_deprecation() -> None: | |||
|         assert ImageCms.VERSION == "1.0.0 pil" | ||||
|     with pytest.warns(DeprecationWarning): | ||||
|         assert isinstance(ImageCms.FLAGS, dict) | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -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 | ||||
|  | @ -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 | ||||
|  |  | |||
							
								
								
									
										25
									
								
								src/PIL/test_ImageFile.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/PIL/test_ImageFile.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -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() | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user