Skip to content

Commit 399e49f

Browse files
committed
restore original languages in fixtures
1 parent 8101c56 commit 399e49f

4 files changed

Lines changed: 30 additions & 5 deletions

File tree

backend/src/cms_backend/mill/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
def update_language_codes():
88
for code in MillContext.disallowed_language_codes:
99
try:
10-
pycountry.languages.remove_entry(alpha_3=code)
10+
pycountry.languages.remove_entry(alpha_3=code) # pyright: ignore[reportUnknownMemberType]
1111
except Exception as exc:
1212
logger.warning(f"failed to remove language code '{code}': {exc}")
1313

1414
for code in MillContext.custom_language_codes:
15-
pycountry.languages.add_entry(alpha_3=code)
15+
pycountry.languages.add_entry(alpha_3=code) # pyright: ignore[reportUnknownMemberType]
1616

1717

1818
update_language_codes()

backend/src/cms_backend/mill/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _parse_custom_language_codes(language_code: str | None) -> list[str]:
2323

2424
def _validate_language_codes(language_codes: list[str]) -> list[str]:
2525
for code in language_codes:
26-
if pycountry.languages.get(alpha_3=code) is None:
26+
if pycountry.languages.get(alpha_3=code) is None: # pyright: ignore[reportUnknownMemberType]
2727
raise ValueError(f"Code '{code}' is not a valid ISO 639-3 code.")
2828
return language_codes
2929

backend/src/cms_backend/mill/processors/book.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def check_book_zim_spec(book: Book) -> bool:
4848
return False
4949

5050
language_code = book.zim_metadata["Language"]
51-
if pycountry.languages.get(alpha_3=language_code) is None:
51+
if pycountry.languages.get(alpha_3=language_code) is None: # pyright: ignore[reportUnknownMemberType]
5252
book.events.append(
5353
f"{getnow()}: book has unknown language code {language_code}"
5454
)

backend/tests/mill/processors/test_zimfarm_notification.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
from collections.abc import Callable
99
from pathlib import Path
10+
from typing import Any
1011
from uuid import UUID
1112

13+
import pycountry
14+
import pytest
1215
from pytest import MonkeyPatch
1316
from sqlalchemy.orm import Session as OrmSession
1417

@@ -24,7 +27,7 @@
2427
from cms_backend.mill import update_language_codes
2528
from cms_backend.mill.processors.zimfarm_notification import process_notification
2629

27-
VALID_NOTIFICATION_CONTENT = {
30+
VALID_NOTIFICATION_CONTENT: dict[str, Any] = {
2831
"article_count": 1000,
2932
"media_count": 500,
3033
"size": 1000000,
@@ -48,6 +51,28 @@
4851
}
4952

5053

54+
@pytest.fixture(autouse=True)
55+
def restore_language_codes():
56+
"""Fixture to restore pycountry language codes after test modifications."""
57+
original_entries = list(pycountry.languages) # pyright: ignore[reportUnknownVariableType]
58+
yield
59+
current_entries = list(pycountry.languages) # pyright: ignore[reportUnknownVariableType]
60+
for entry in current_entries: # pyright: ignore[reportUnknownVariableType]
61+
try:
62+
pycountry.languages.remove_entry(alpha_3=entry.alpha_3) # pyright: ignore[reportUnknownMemberType,reportUnknownArgumentType]
63+
except Exception: # noqa: S110
64+
pass
65+
66+
for entry in original_entries: # pyright: ignore[reportUnknownVariableType]
67+
try:
68+
pycountry.languages.add_entry( # pyright: ignore[reportUnknownMemberType]
69+
alpha_3=entry.alpha_3, # pyright: ignore[reportUnknownMemberType,reportUnknownArgumentType]
70+
name=entry.name, # pyright: ignore[reportUnknownMemberType,reportUnknownArgumentType]
71+
)
72+
except Exception: # noqa: S110
73+
pass
74+
75+
5176
class TestBadNotifications:
5277
"""Test notifications that fail validation and are marked as bad_notification."""
5378

0 commit comments

Comments
 (0)