MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_version_matches

Function test_version_matches

tests/extra_python_package/test_files.py:355–385  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

353
354
355def test_version_matches():
356 header = MAIN_DIR / "include/pybind11/detail/common.h"
357 text = header.read_text()
358
359 # Extract the relevant macro values
360 regex_prefix = r"#\s*define\s+PYBIND11_VERSION_"
361 micro = re.search(rf"{regex_prefix}MICRO\s+(\d+)\b", text).group(1)
362 release_level = re.search(rf"{regex_prefix}RELEASE_LEVEL\s+(\w+)\b", text).group(1)
363 release_serial = re.search(
364 rf"{regex_prefix}RELEASE_SERIAL\s+(\d+)\b",
365 text,
366 ).group(1)
367 patch = re.search(rf"{regex_prefix}PATCH\s+([\w.-]+)\b", text).group(1)
368
369 # Map release level macro to string
370 level_map = {
371 "PY_RELEASE_LEVEL_ALPHA": "a",
372 "PY_RELEASE_LEVEL_BETA": "b",
373 "PY_RELEASE_LEVEL_GAMMA": "rc",
374 "PY_RELEASE_LEVEL_FINAL": "",
375 }
376 level_str = level_map[release_level]
377
378 if release_level == "PY_RELEASE_LEVEL_FINAL":
379 assert level_str == ""
380 assert release_serial == "0"
381 expected_patch = micro
382 else:
383 expected_patch = f"{micro}{level_str}{release_serial}"
384
385 assert patch == expected_patch

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected