61 lines
3.0 KiB
Markdown
61 lines
3.0 KiB
Markdown
# Tests for ki18n
|
|
|
|
The suite uses [pytest](https://docs.pytest.org/) with
|
|
[pytest-asyncio](https://pytest-asyncio.readthedocs.io/). 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.
|
|
|
|
```sh
|
|
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` (PyInstaller / source checkout) |
|
|
| `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_lazy_handle.py` | Module handle `i18n`, alias names |
|
|
| `test_public_api.py` | Public API as documented in the README |
|
|
| `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` - isolated `Env`: `env.install(lang, strings, help)`, `env.user(...)`,
|
|
`env.make()` / `env.remake()`, directories `app_dir`, `user_dir`, `data_home`.
|
|
- `installed` - `env` with the example languages `en` and `de` installed, no manager yet.
|
|
- `manager` - `installed` plus a constructed `Ki18n` instance.
|
|
- `log_warnings` - callable returning the library's WARNING messages so far.
|
|
|
|
## Known deviations between documentation and code
|
|
|
|
Cases that describe documented behavior the code does not currently fulfil are
|
|
marked `xfail(strict=True)`. They are reported as `xfailed` now and turn into
|
|
failures (`XPASS(strict)`) once the code is fixed - remove the marker then.
|
|
|
|
- `test_public_api.py::test_package_exports_documented_names` -
|
|
`from ki18n import Ki18n, i18n, I18n`: `__init__.py` is empty.
|
|
- `test_translate.py::test_other_formatting_errors_return_unformatted_text` -
|
|
`_format()` only catches `KeyError`, `IndexError` and `ValueError`, so
|
|
`{name.attr}` / `{name[x]}` raise `AttributeError` / `TypeError`.
|