Spaces:
Sleeping
Sleeping
Download code/tests/test_thumbnails.py from acra-thesis/acra-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/acra-thesis/acra-backend/resolve/main/code/tests/test_thumbnails.py
- Command line
-
hf download hf://spaces/acra-thesis/acra-backend/code/tests/test_thumbnails.py
-
curl -L -o test_thumbnails.py https://huggingface.co/spaces/acra-thesis/acra-backend/resolve/main/code/tests/test_thumbnails.py
1.1 kB
| """Storage cards load a small thumbnail instead of the full corrected image.""" | |
| import numpy as np | |
| from main import THUMB_MAX_SIDE, _thumb_url, _thumbnail | |
| def test_thumb_url_sits_beside_the_corrected_image(): | |
| url = "https://x.supabase.co/storage/v1/object/public/acra-images/jobs/abc/corrected.jpg" | |
| assert _thumb_url(url) == url.replace("/corrected.jpg", "/thumb.jpg") | |
| def test_no_thumb_url_when_there_is_nothing_to_derive_it_from(): | |
| # A missing or unexpected URL must give None, so the frontend uses the full | |
| # image instead of requesting an address that cannot exist. | |
| assert _thumb_url(None) is None | |
| assert _thumb_url("") is None | |
| assert _thumb_url("https://x/other.png") is None | |
| def test_thumbnail_keeps_aspect_ratio_and_caps_the_long_side(): | |
| img = np.zeros((1536, 1152, 3), dtype=np.uint8) | |
| h, w = _thumbnail(img).shape[:2] | |
| assert max(h, w) == THUMB_MAX_SIDE | |
| assert abs(w / h - 1152 / 1536) < 0.01 | |
| def test_small_images_are_never_enlarged(): | |
| img = np.zeros((200, 300, 3), dtype=np.uint8) | |
| assert _thumbnail(img).shape[:2] == (200, 300) | |