"""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") @pytest.mark.parametrize( ("name", "target"), [ ("Ki18n", "Ki18n"), ("i18n", "i18n"), ("I18n", "Ki18n"), ("SystemLocale", "SystemLocale"), ], ) def test_package_exports_documented_names(name, target): assert getattr(ki18n, name) is getattr(ki18n_module, target) def test_readme_import_statement_works(): from ki18n import Ki18n, i18n assert Ki18n is ki18n_module.Ki18n assert i18n is ki18n_module.i18n def test_all_lists_the_public_names(): assert set(ki18n.__all__) == {"Ki18n", "i18n", "I18n", "SystemLocale"} def test_package_attribute_ki18n_is_still_the_submodule(): # Re-exporting names must not shadow ``ki18n.ki18n`` (the module). assert ki18n.ki18n is ki18n_module def test_importing_the_package_does_not_import_textual_dialogs(): assert not hasattr(ki18n, "HelpScreen") assert not hasattr(ki18n, "LanguageSelectScreen") 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", "get_locale", "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))