Restore hardcoded region lists, sourced from iso_3166-1_alpha-2
Browse filesReplace fixture-based lookup with the same hardcoded SLAVIC_REGIONS /
SINOPHONE_REGIONS sets defined in cterdam/iso_3166-1_alpha-2
test/test_invariants.py, which is the authoritative source per the README.
- test/test_invariants.py +20 -8
test/test_invariants.py
CHANGED
|
@@ -24,12 +24,24 @@ import pytest
|
|
| 24 |
from collections import defaultdict
|
| 25 |
from datasets import load_dataset
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
@pytest.fixture(scope="session")
|
|
@@ -66,14 +78,14 @@ def test_name_matches_lang_field(dataset):
|
|
| 66 |
assert mismatches == [], f"Name/lang field mismatches: {mismatches}"
|
| 67 |
|
| 68 |
|
| 69 |
-
def test_lang_matches_region(dataset
|
| 70 |
-
"""lang field must match
|
| 71 |
mismatches = []
|
| 72 |
|
| 73 |
for i, entry in enumerate(dataset):
|
| 74 |
region = entry.get('region') or ''
|
| 75 |
lang = entry.get('lang')
|
| 76 |
-
expected =
|
| 77 |
|
| 78 |
if lang != expected:
|
| 79 |
mismatches.append((i, entry.get('code'), region, lang, expected))
|
|
|
|
| 24 |
from collections import defaultdict
|
| 25 |
from datasets import load_dataset
|
| 26 |
|
| 27 |
+
# Copied from cterdam/iso_3166-1_alpha-2 test/test_invariants.py — the
|
| 28 |
+
# authoritative definition of which regions use which primary language.
|
| 29 |
+
SLAVIC_REGIONS = {
|
| 30 |
+
'RU', 'UA', 'BY', 'KZ', 'UZ', 'TJ', 'KG', 'TM', 'GE', 'AZ', 'AM', 'MD',
|
| 31 |
+
'LT', 'LV', 'EE', 'RS', 'ME', 'BA', 'HR', 'SI', 'SK', 'CZ', 'PL', 'BG', 'MK', 'FI'
|
| 32 |
+
}
|
| 33 |
|
| 34 |
+
SINOPHONE_REGIONS = {
|
| 35 |
+
'CN', 'TW', 'HK', 'MO', 'JP', 'KR', 'KP', 'MN', 'SG', 'VN', 'LA', 'TH', 'MM', 'KH', 'MY', 'BN'
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def determine_expected_lang(region_code: str) -> str:
|
| 40 |
+
if region_code in SINOPHONE_REGIONS:
|
| 41 |
+
return 'zh'
|
| 42 |
+
if region_code in SLAVIC_REGIONS:
|
| 43 |
+
return 'ru'
|
| 44 |
+
return 'en'
|
| 45 |
|
| 46 |
|
| 47 |
@pytest.fixture(scope="session")
|
|
|
|
| 78 |
assert mismatches == [], f"Name/lang field mismatches: {mismatches}"
|
| 79 |
|
| 80 |
|
| 81 |
+
def test_lang_matches_region(dataset):
|
| 82 |
+
"""lang field must match the region's language rule."""
|
| 83 |
mismatches = []
|
| 84 |
|
| 85 |
for i, entry in enumerate(dataset):
|
| 86 |
region = entry.get('region') or ''
|
| 87 |
lang = entry.get('lang')
|
| 88 |
+
expected = determine_expected_lang(region)
|
| 89 |
|
| 90 |
if lang != expected:
|
| 91 |
mismatches.append((i, entry.get('code'), region, lang, expected))
|