Download tests/test_postprocess.py from nvikou/vitrina: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/spaces/nvikou/vitrina/resolve/main/tests/test_postprocess.py
- Command line
-
hf download hf://spaces/nvikou/vitrina/tests/test_postprocess.py
-
curl -L -o test_postprocess.py https://huggingface.co/spaces/nvikou/vitrina/resolve/main/tests/test_postprocess.py
1.8 kB
| from PIL import Image | |
| from src.postprocess import SIZE_PRESETS, add_badge, add_watermark, fit_canvas | |
| from src.providers.openai_client import orientation_for, resolve_size | |
| def _img(w=1024, h=1536, color="#888888"): | |
| return Image.new("RGB", (w, h), color) | |
| def test_fit_canvas_cover_exact_size(): | |
| out = fit_canvas(_img(), (900, 1200), "Обрезать по краям") | |
| assert out.size == (900, 1200) | |
| def test_fit_canvas_contain_pads_with_background(): | |
| out = fit_canvas(_img(1024, 1024), (1920, 1080), "Вписать целиком", "#FFFFFF") | |
| assert out.size == (1920, 1080) | |
| assert out.getpixel((5, 5)) == (255, 255, 255) # поле залито | |
| def test_fit_canvas_passthrough(): | |
| src = _img(512, 512) | |
| assert fit_canvas(src, None).size == (512, 512) | |
| def test_badge_keeps_size_and_changes_pixels(): | |
| src = _img(900, 1200, "#FFFFFF") | |
| out = add_badge(src, "Держит тепло 12 часов", position="Слева сверху", fill="#E4287C") | |
| assert out.size == src.size | |
| assert out.tobytes() != src.tobytes() | |
| def test_empty_badge_is_noop(): | |
| src = _img(200, 200) | |
| assert add_badge(src, " ") is src | |
| def test_watermark_keeps_size(): | |
| src = _img(600, 800) | |
| assert add_watermark(src, "черновик").size == (600, 800) | |
| def test_orientation_and_size_matrix(): | |
| assert orientation_for(900, 1200) == "portrait" | |
| assert orientation_for(1920, 1080) == "landscape" | |
| assert orientation_for(1000, 1000) == "square" | |
| assert resolve_size("gpt-image-1", "portrait") == "1024x1536" | |
| assert resolve_size("dall-e-3", "landscape") == "1792x1024" | |
| def test_all_presets_are_valid(): | |
| for name, value in SIZE_PRESETS.items(): | |
| assert value is None or (len(value) == 2 and all(v > 0 for v in value)), name | |