"""Guards on the package's own metadata. The distribution is ``informix-driver``; the import module is ``informix_db``. That mismatch is a live trap: ``importlib.metadata`` needs the *distribution* name, so the string can't be derived from ``__name__``, and getting it wrong fails silently — ``__version__`` degrades to the ``0.0.0+local`` sentinel instead of raising. That is exactly what shipped between the 2026-05-08 rename and 2026.08.27: ``__init__`` still asked for ``informix-db``, so anyone who installed the renamed package saw ``0.0.0+local``. It went unnoticed because a stale ``informix-db`` distribution lingered in the dev environment and answered the query. """ from __future__ import annotations from pathlib import Path import pytest import tomllib import informix_db PYPROJECT = Path(__file__).resolve().parent.parent / "pyproject.toml" @pytest.fixture(scope="module") def pyproject() -> dict: if not PYPROJECT.is_file(): pytest.skip("pyproject.toml not present (installed-package test run)") with PYPROJECT.open("rb") as handle: return tomllib.load(handle) def test_version_is_not_the_unresolved_sentinel() -> None: """If this fails, the distribution name in ``__init__`` no longer matches ``[project].name`` and every user sees a bogus version.""" assert informix_db.__version__ != "0.0.0+local", ( "__version__ fell back to its sentinel — the distribution name " "looked up in informix_db/__init__.py does not match the installed " "package. Check [project].name in pyproject.toml." ) def test_version_matches_pyproject(pyproject: dict) -> None: declared = pyproject["project"]["version"] # PEP 440 normalisation drops leading zeros: 2026.08.27 -> 2026.8.27. normalised = ".".join( str(int(part)) if part.isdigit() else part for part in declared.split(".") ) assert informix_db.__version__ in {declared, normalised} def test_init_looks_up_the_declared_distribution_name(pyproject: dict) -> None: """Catch the rename trap directly: the name passed to ``importlib.metadata.version()`` must equal ``[project].name``.""" source = ( Path(informix_db.__file__).resolve().parent / "__init__.py" ).read_text(encoding="utf-8") declared_name = pyproject["project"]["name"] assert f'version("{declared_name}")' in source, ( f"informix_db/__init__.py should call version({declared_name!r}) to " "match [project].name in pyproject.toml" ) def test_version_is_importable_and_stringy() -> None: assert isinstance(informix_db.__version__, str) assert informix_db.__version__ def test_public_surface_is_exported() -> None: for name in informix_db.__all__: assert hasattr(informix_db, name), f"{name} in __all__ but not defined"