| 1 |
"""Direct coverage for package-level version fallback wiring.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
import runpy |
| 6 |
from importlib.metadata import PackageNotFoundError |
| 7 |
from pathlib import Path |
| 8 |
from unittest.mock import patch |
| 9 |
|
| 10 |
_INIT_PATH = Path(__file__).resolve().parents[2] / "src" / "dlm" / "__init__.py" |
| 11 |
|
| 12 |
|
| 13 |
def test_package_init_reads_installed_version() -> None: |
| 14 |
with patch("importlib.metadata.version", return_value="1.2.3"): |
| 15 |
module_globals = runpy.run_path(str(_INIT_PATH)) |
| 16 |
|
| 17 |
assert module_globals["__version__"] == "1.2.3" |
| 18 |
|
| 19 |
|
| 20 |
def test_package_init_falls_back_when_package_metadata_is_missing() -> None: |
| 21 |
with patch("importlib.metadata.version", side_effect=PackageNotFoundError): |
| 22 |
module_globals = runpy.run_path(str(_INIT_PATH)) |
| 23 |
|
| 24 |
assert module_globals["__version__"] == "0.0.0+unknown" |