返回 ViMax
test_image_orientation.py
根目录 / tests / test_image_orientation.py
1 import os
2 import unittest
3 from unittest.mock import patch
4
5 from PIL import Image
6
7 from tools.image_orientation import ensure_not_portrait, landscape_guard_requested
8
9
10 class ImageOrientationTests(unittest.TestCase):
11 def test_landscape_guard_requested_defaults_to_all_images(self):
12 self.assertTrue(landscape_guard_requested(size="1600x900"))
13 self.assertTrue(landscape_guard_requested(size="512x512"))
14 self.assertTrue(landscape_guard_requested(size=None))
15 self.assertTrue(landscape_guard_requested(aspect_ratio="16:9", enforce_landscape=False))
16 self.assertFalse(landscape_guard_requested(allow_portrait=True))
17
18 def test_portrait_detection_allows_slightly_tall_images(self):
19 ensure_not_portrait(Image.new("RGB", (1000, 1040)))
20 with self.assertRaises(ValueError):
21 ensure_not_portrait(Image.new("RGB", (1000, 1100)))
22
23 def test_portrait_tolerance_env_override(self):
24 with patch.dict(os.environ, {"VIMAX_IMAGE_PORTRAIT_RETRY_TOLERANCE": "1.20"}):
25 ensure_not_portrait(Image.new("RGB", (1000, 1100)))
26
27
28 if __name__ == "__main__":
29 unittest.main()
30
30 lines PYTHON