test_numpy_version.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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"(\.dev[0-9]+(\+git[0-9]+\.[0-9a-f]+)?)?"
  22. res = re.match(version_pattern + dev_suffix + '$', np.__version__)
  23. assert_(res is not None, np.__version__)
  24. def test_short_version():
  25. # Check numpy.short_version actually exists
  26. if np.version.release:
  27. assert_(np.__version__ == np.version.short_version,
  28. "short_version mismatch in release version")
  29. else:
  30. assert_(np.__version__.split("+")[0] == np.version.short_version,
  31. "short_version mismatch in development version")
  32. def test_version_module():
  33. contents = set([s for s in dir(np.version) if not s.startswith('_')])
  34. expected = set([
  35. 'full_version',
  36. 'git_revision',
  37. 'release',
  38. 'short_version',
  39. 'version',
  40. ])
  41. assert contents == expected