Coverage for tests/test_version.py: 92%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.1, created at 2026-07-15 09:33 +0000

1"""Version consistency between the Python package and the compiled C backend. 

2 

3The C version is single-sourced from pyproject at build time: scikit-build-core 

4sets ``SKBUILD_PROJECT_VERSION`` -> the ``EVUTILS_VERSION`` macro -> 

5``evutils_version()`` (see CMakeLists.txt). So a package built through the normal 

6wheel / editable path carries a native library stamped with the exact package 

7version; a mismatch means a stale or wrong native library got bundled -- exactly 

8what this guards against (e.g. an old build/ shared lib shadowing a new wheel). 

9 

10A standalone ``cmake`` build (scripts/coverage.sh, manual dev builds) cannot set 

11``SKBUILD_PROJECT_VERSION`` and falls back to a dev sentinel; there is nothing to 

12compare against then, so the check skips. That sentinel never appears in a 

13scikit-build wheel, so skipping on it cannot mask a real packaging mismatch. 

14""" 

15import pytest 

16 

17import evutils 

18 

19# Non-scikit-build sentinels: CMakeLists.txt fallback, and the csrc #ifndef 

20# default used only when compiled entirely without CMake. 

21_DEV_SENTINELS = {"0.0.0+dev", "0.0.1"} 

22 

23 

24def _native_version() -> str: 

25 from evutils.io._native_core import lib 

26 return lib().evutils_version().decode() 

27 

28 

29def test_native_backend_version_matches_package() -> None: 

30 native = _native_version() 

31 assert native, "evutils_version() returned an empty string" 

32 if native in _DEV_SENTINELS: 

33 pytest.skip( 

34 f"native lib not version-stamped (standalone-build sentinel {native!r}); " 

35 "built outside scikit-build-core" 

36 ) 

37 assert native == evutils.__version__, ( 

38 f"C backend version {native!r} != package version {evutils.__version__!r} -- " 

39 "stale or mismatched native library bundled" 

40 )