2.9 KiB
Tests for ki18n
The suite uses pytest with
pytest-asyncio. The Textual dialogs are
operated through Textual's Pilot (clicks and key presses in the headless test
driver App.run_test).
Every test runs in temporary directories (installed and user resources;
XDG_DATA_HOME and LOCALAPPDATA are redirected), so real user data is never
read. The Ki18n singleton is reset before and after every test.
uv sync # installs the dev dependency group (pytest, pytest-asyncio)
uv run pytest # or: python3 -m pytest
uv run pytest -k plural # run a subset
Configuration lives in pyproject.toml ([tool.pytest.ini_options]):
testpaths, pythonpath = ["src"] (no installation needed) and
asyncio_mode = "auto".
Layout
| File | Contents |
|---|---|
conftest.py |
Fixtures: env, installed, manager, log_warnings, singleton reset |
support.py |
Example data (EN, DE, dialog keys) and the Env helper class |
test_normalize.py |
Language ID normalization, fallback chains |
test_paths.py |
ki18n.paths: frozen detection, bundle_root() independent of where ki18n lives |
test_construction.py |
Constructor, singleton, project_root/local_root, data directories |
test_discovery.py |
get_available_languages(), user and installed resources |
test_loading.py |
Validation and merging of strings.json, regional layers |
test_set_language.py |
set_language(), error cases, listeners |
test_translate.py |
t(): fallback order, formatting |
test_plural.py |
p(): categories, #count/{count}, fallbacks |
test_help.py |
get_help(): regions, user files, English fallback |
test_locale.py |
Ki18n.get_locale(): POSIX environment, macOS defaults, Windows API (all simulated on any host) |
test_lazy_handle.py |
Module handle i18n, alias names |
test_public_api.py |
Public API as documented in the README (package-level exports) |
test_shipped_resources.py |
Consistency of the shipped i18n/ files |
test_screens.py |
HelpScreen / LanguageSelectScreen driven with Pilot, plus a small integration app |
Fixtures
env- isolatedEnv:env.install(lang, strings, help),env.user(...),env.make()/env.remake(), directoriesapp_dir,user_dir,data_home.installed-envwith the example languagesenanddeinstalled, no manager yet.manager-installedplus a constructedKi18ninstance.log_warnings- callable returning the library's WARNING messages so far.
Known deviations between documentation and code
None at the moment. If a test is added for documented behavior that the code
does not fulfil yet, mark it xfail(strict=True): it is reported as xfailed
until the code is fixed and then turns into a failure (XPASS(strict)), which
is the signal to remove the marker.