forked from ChelseaKR/gtfs-scorecard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_i18n.py
More file actions
56 lines (41 loc) · 1.64 KB
/
Copy pathtest_i18n.py
File metadata and controls
56 lines (41 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Locale-catalog integrity tests."""
from __future__ import annotations
import pytest
from scorecard_pipeline.i18n import (
PSEUDOLOCALE,
SUPPORTED_LOCALES,
load_app_catalog,
load_catalog,
pseudolocalize_text,
validate_catalogs,
)
def test_locale_catalogs_have_matching_keys() -> None:
validate_catalogs()
english = set(load_catalog("en"))
assert english
assert all(set(load_catalog(locale)) == english for locale in SUPPORTED_LOCALES)
def test_unsupported_locale_fails_closed() -> None:
with pytest.raises(ValueError, match="unsupported locale"):
load_catalog("fr")
def test_unsupported_app_locale_fails_closed() -> None:
with pytest.raises(ValueError, match="unsupported locale"):
load_app_catalog("es")
def test_app_catalog_loads_and_is_non_empty() -> None:
catalog = load_app_catalog("en")
assert catalog
assert all(isinstance(value, str) and value.strip() for value in catalog.values())
def test_pseudolocale_expands_marks_and_keeps_placeholders() -> None:
text = "Could not load {path}{detail}."
pseudo = pseudolocalize_text(text)
assert pseudo.startswith("⟦")
assert pseudo.endswith("⟧")
assert "{path}" in pseudo
assert "{detail}" in pseudo
assert len(pseudo) >= len(text) * 1.4
# Deterministic: the derived catalog can never drift between renders.
assert pseudo == pseudolocalize_text(text)
def test_pseudolocale_catalog_mirrors_english_keys() -> None:
english = load_app_catalog("en")
pseudo = load_app_catalog(PSEUDOLOCALE)
assert set(pseudo) == set(english)
assert all(value.startswith("⟦") for value in pseudo.values())