LibBotUniversal/tests/test_i18n_async.py

67 lines
1.8 KiB
Python
Raw Normal View History

2023-08-06 13:51:23 +03:00
from pathlib import Path
from typing import Any, List, Union
import pytest
from libbot import i18n
@pytest.mark.asyncio
@pytest.mark.parametrize(
"key, args, locale, expected",
[
("foo", [], None, "bar"),
("foo", [], "uk", "бар"),
("example", ["messages"], None, "okay"),
("example", ["messages"], "uk", "окей"),
("nested", ["callbacks", "default"], None, "sure"),
("nested", ["callbacks", "default"], "uk", "авжеж"),
],
)
async def test_i18n_get(
2023-08-06 20:11:16 +03:00
key: str,
args: List[str],
locale: Union[str, None],
expected: Any,
location_locale: Path,
2023-08-06 13:51:23 +03:00
):
assert (
2023-08-06 20:11:16 +03:00
await i18n._(key, *args, locale=locale, locales_root=location_locale)
2023-08-06 13:51:23 +03:00
if locale is not None
2023-08-06 20:11:16 +03:00
else await i18n._(key, *args, locales_root=location_locale)
2023-08-06 13:51:23 +03:00
) == expected
@pytest.mark.asyncio
@pytest.mark.parametrize(
"key, args, expected",
[
("foo", [], ["bar", "бар"]),
("example", ["messages"], ["okay", "окей"]),
("nested", ["callbacks", "default"], ["sure", "авжеж"]),
],
)
2023-08-06 20:11:16 +03:00
async def test_i18n_in_all_locales(
key: str, args: List[str], expected: Any, location_locale: Path
):
2023-08-06 13:51:23 +03:00
assert (
2023-08-06 20:11:16 +03:00
await i18n.in_all_locales(key, *args, locales_root=location_locale)
2023-08-06 13:51:23 +03:00
) == expected
@pytest.mark.asyncio
@pytest.mark.parametrize(
"key, args, expected",
[
("foo", [], {"en": "bar", "uk": "бар"}),
("example", ["messages"], {"en": "okay", "uk": "окей"}),
("nested", ["callbacks", "default"], {"en": "sure", "uk": "авжеж"}),
],
)
2023-08-06 20:11:16 +03:00
async def test_i18n_in_every_locale(
key: str, args: List[str], expected: Any, location_locale: Path
):
2023-08-06 13:51:23 +03:00
assert (
2023-08-06 20:11:16 +03:00
await i18n.in_every_locale(key, *args, locales_root=location_locale)
2023-08-06 13:51:23 +03:00
) == expected