test_version.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import re
  2. import pathlib
  3. import subprocess
  4. import sys
  5. import pytest
  6. import freesurfer_surface
  7. _VERSION_MODULE_PATH = pathlib.Path(__file__).parent.parent.joinpath(
  8. "freesurfer_surface", "version.py"
  9. )
  10. def test_version():
  11. if not _VERSION_MODULE_PATH.exists():
  12. pytest.skip("package is not installed")
  13. assert re.match(r"^\d+\.\d+\.\d+", freesurfer_surface.__version__)
  14. def test_version_missing(tmp_path):
  15. temp_module_path = tmp_path.joinpath("version.py")
  16. if _VERSION_MODULE_PATH.exists():
  17. _VERSION_MODULE_PATH.rename(temp_module_path)
  18. try:
  19. assert (
  20. subprocess.run(
  21. [
  22. sys.executable,
  23. "-c",
  24. "import freesurfer_surface; print(freesurfer_surface.__version__)",
  25. ],
  26. check=True,
  27. stdout=subprocess.PIPE,
  28. ).stdout.rstrip()
  29. == b"None"
  30. )
  31. finally:
  32. if temp_module_path.exists():
  33. temp_module_path.rename(_VERSION_MODULE_PATH)