Spaces:
Runtime error
Runtime error
Download test_image_preprocessing.py from Pulseb/insiders-generation-hub: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/Pulseb/insiders-generation-hub/resolve/main/test_image_preprocessing.py
- Command line
-
hf download hf://spaces/Pulseb/insiders-generation-hub/test_image_preprocessing.py
-
curl -L -o test_image_preprocessing.py https://huggingface.co/spaces/Pulseb/insiders-generation-hub/resolve/main/test_image_preprocessing.py
1.72 kB
| import tempfile | |
| import unittest | |
| from pathlib import Path | |
| from PIL import Image | |
| from image_preprocessing import load_standardized_image | |
| class LoadStandardizedImageTests(unittest.TestCase): | |
| def test_applies_exif_orientation_and_returns_rgb_without_metadata(self): | |
| with tempfile.TemporaryDirectory() as temp_dir: | |
| image_path = Path(temp_dir) / "rotated.jpg" | |
| image = Image.new("RGB", (4, 2), "red") | |
| exif = image.getexif() | |
| exif[274] = 6 # Rotate 90 degrees clockwise for display. | |
| image.save(image_path, exif=exif) | |
| standardized = load_standardized_image(image_path) | |
| self.assertEqual(standardized.size, (2, 4)) | |
| self.assertEqual(standardized.mode, "RGB") | |
| self.assertEqual(standardized.info, {}) | |
| self.assertNotIn(274, standardized.getexif()) | |
| def test_converts_non_rgb_images(self): | |
| with tempfile.TemporaryDirectory() as temp_dir: | |
| image_path = Path(temp_dir) / "grayscale.png" | |
| Image.new("L", (3, 5), 128).save(image_path) | |
| standardized = load_standardized_image(image_path) | |
| self.assertEqual(standardized.size, (3, 5)) | |
| self.assertEqual(standardized.mode, "RGB") | |
| def test_decodes_heic_images(self): | |
| with tempfile.TemporaryDirectory() as temp_dir: | |
| image_path = Path(temp_dir) / "iphone.heic" | |
| Image.new("RGB", (6, 4), "blue").save(image_path, format="HEIF") | |
| standardized = load_standardized_image(image_path) | |
| self.assertEqual(standardized.size, (6, 4)) | |
| self.assertEqual(standardized.mode, "RGB") | |
| if __name__ == "__main__": | |
| unittest.main() | |