test_version.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # freesurfer-surface - Read and Write Surface Files in Freesurfer’s TriangularSurface Format
  2. #
  3. # Copyright (C) 2020 Fabian Peter Hammerle <fabian@hammerle.me>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import re
  18. import pathlib
  19. import subprocess
  20. import sys
  21. import pytest
  22. import freesurfer_surface
  23. _VERSION_MODULE_PATH = pathlib.Path(__file__).parent.parent.joinpath(
  24. "freesurfer_surface", "version.py"
  25. )
  26. def test_version():
  27. if not _VERSION_MODULE_PATH.exists():
  28. pytest.skip("package is not installed")
  29. assert re.match(r"^\d+\.\d+\.\S+", freesurfer_surface.__version__)
  30. def test_version_missing(tmp_path):
  31. temp_module_path = tmp_path.joinpath("version.py")
  32. if _VERSION_MODULE_PATH.exists():
  33. _VERSION_MODULE_PATH.rename(temp_module_path)
  34. try:
  35. assert (
  36. subprocess.run(
  37. [
  38. sys.executable,
  39. "-c",
  40. "import freesurfer_surface; print(freesurfer_surface.__version__)",
  41. ],
  42. check=True,
  43. stdout=subprocess.PIPE,
  44. ).stdout.rstrip()
  45. == b"None"
  46. )
  47. finally:
  48. if temp_module_path.exists():
  49. temp_module_path.rename(_VERSION_MODULE_PATH)