"""Tests of the public API as described in the README.""" import importlib from pathlib import Path import pytest import ki18n ki18n_module = importlib.import_module("ki18n.ki18n") # The README shows ``from ki18n import Ki18n, i18n``. The package's # ``__init__.py`` is currently empty, so these cases are expected to fail until # the package re-exports the names (the demo scripts take the detour # ``from ki18n.ki18n import ...``). Remove the xfail marker once it does. # @pytest.mark.xfail(strict=True, raises=ImportError, # reason="ki18n/__init__.py does not re-export the public names") @pytest.mark.parametrize( ("name", "target"), [("Ki18n", "Ki18n"), ("i18n", "i18n"), ("I18n", "Ki18n")], ) def test_package_exports_documented_names(name, target): namespace: dict = {} exec(f"from ki18n import {name}", namespace) assert namespace[name] is getattr(ki18n_module, target) def test_py_typed_marker_is_shipped(): assert (Path(ki18n.__file__).parent / "py.typed").is_file() @pytest.mark.parametrize( "name", [ "get_language", "get_default_language", "get_available_languages", "set_language", "t", "p", "get_help", "add_language_change_listener", "remove_language_change_listener", "add_listener", "remove_listener", "_get_translations", ], ) def test_manager_provides_documented_methods(name): assert callable(getattr(ki18n_module.Ki18n, name))