test_numpy_version.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """
  2. Check the numpy version is valid.
  3. Note that a development version is marked by the presence of 'dev0' or '+'
  4. in the version string, all else is treated as a release. The version string
  5. itself is set from the output of ``git describe`` which relies on tags.
  6. Examples
  7. --------
  8. Valid Development: 1.22.0.dev0 1.22.0.dev0+5-g7999db4df2 1.22.0+5-g7999db4df2
  9. Valid Release: 1.21.0.rc1, 1.21.0.b1, 1.21.0
  10. Invalid: 1.22.0.dev, 1.22.0.dev0-5-g7999db4dfB, 1.21.0.d1, 1.21.a
  11. Note that a release is determined by the version string, which in turn
  12. is controlled by the result of the ``git describe`` command.
  13. """
  14. import re
  15. import numpy as np
  16. from numpy.testing import assert_
  17. def test_valid_numpy_version():
  18. # Verify that the numpy version is a valid one (no .post suffix or other
  19. # nonsense). See gh-6431 for an issue caused by an invalid version.
  20. version_pattern = r"^[0-9]+\.[0-9]+\.[0-9]+(a[0-9]|b[0-9]|rc[0-9]|)"
  21. dev_suffix = r"(\.dev0|)(\+[0-9]*\.g[0-9a-f]+|)"
  22. if np.version.release:
  23. res = re.match(version_pattern + '$', np.__version__)
  24. else:
  25. res = re.match(version_pattern + dev_suffix + '$', np.__version__)
  26. assert_(res is not None, np.__version__)
  27. def test_short_version():
  28. # Check numpy.short_version actually exists
  29. if np.version.release:
  30. assert_(np.__version__ == np.version.short_version,
  31. "short_version mismatch in release version")
  32. else:
  33. assert_(np.__version__.split("+")[0] == np.version.short_version,
  34. "short_version mismatch in development version")