# SPDX-FileCopyrightText: 2025 Marco Ricci <software@the13thletter.info>
#
# SPDX-License-Identifier: Zlib
"""Test the localization machinery."""
from __future__ import annotations
import contextlib
import errno
import gettext
import os
import string
from typing import TYPE_CHECKING, cast
import hypothesis
import pytest
from hypothesis import strategies
from derivepassphrase import _cli_msg as msg
if TYPE_CHECKING:
from collections.abc import Iterator
all_translatable_strings_dict: dict[
msg.TranslatableString,
msg.MsgTemplate,
] = {}
for enum_class in msg.MSG_TEMPLATE_CLASSES:
all_translatable_strings_dict.update({
cast('msg.TranslatableString', v.value): v for v in enum_class
})
all_translatable_strings_enum_values = tuple(
sorted(all_translatable_strings_dict.values(), key=str)
)
all_translatable_strings = [
cast('msg.TranslatableString', v.value)
for v in all_translatable_strings_enum_values
]
@pytest.fixture(scope='class')
def use_debug_translations() -> Iterator[None]:
with pytest.MonkeyPatch.context() as monkeypatch:
monkeypatch.setattr(msg, 'translation', msg.DebugTranslations())
yield
@contextlib.contextmanager
def monkeypatched_null_translations() -> Iterator[None]: