Download tests/unit/shared/test_alias_dispatch.py from paisaly/backend: direct link, hf CLI and curl.
- Browser
- Download file 3.38 kB
-
https://huggingface.co/spaces/paisaly/backend/resolve/main/tests/unit/shared/test_alias_dispatch.py
- Command line
-
hf download hf://spaces/paisaly/backend/tests/unit/shared/test_alias_dispatch.py
-
curl -L -o test_alias_dispatch.py https://huggingface.co/spaces/paisaly/backend/resolve/main/tests/unit/shared/test_alias_dispatch.py
3.38 kB
| """Unit tests for shared/alias_dispatch.py — the resolution-order table. | |
| This order is a public contract shared by the redirect and the public | |
| preview endpoint; the table below is the single place it is spelled out. | |
| """ | |
| from __future__ import annotations | |
| import pytest | |
| from app.schemas.models.url import SchemaVersion | |
| from app.shared.alias_dispatch import ( | |
| emoji_lookup_candidates, | |
| is_emoji_shaped, | |
| resolution_order, | |
| v2_lookup_code, | |
| ) | |
| VS16 = "️" | |
| STAR = "⭐" | |
| ROCKET = "🚀" | |
| def test_resolution_order_table(short_code, expected): | |
| assert resolution_order(short_code) == expected | |
| class TestIsEmojiShaped: | |
| def test_emoji_shaped(self, code): | |
| assert is_emoji_shaped(code) is True | |
| def test_not_emoji_shaped(self, code): | |
| assert is_emoji_shaped(code) is False | |
| class TestV2LookupCode: | |
| def test_emoji_code_canonicalized(self): | |
| assert v2_lookup_code(STAR + VS16 + ROCKET) == STAR + ROCKET | |
| def test_percent_encoded_emoji_decoded(self): | |
| assert v2_lookup_code("%F0%9F%9A%80") == ROCKET | |
| def test_non_emoji_untouched(self): | |
| # Alphanumeric codes pass through byte-identical — even ones that | |
| # would decode differently (%41 stays literal for non-emoji). | |
| assert v2_lookup_code("abc123") == "abc123" | |
| assert v2_lookup_code("café") == "café" | |
| class TestEmojiLookupCandidates: | |
| def test_canonical_input_single_candidate(self): | |
| assert emoji_lookup_candidates(STAR + ROCKET) == (STAR + ROCKET,) | |
| def test_variant_input_raw_first_then_canonical(self): | |
| raw = STAR + VS16 + ROCKET | |
| assert emoji_lookup_candidates(raw) == (raw, STAR + ROCKET) | |