codekingpro/portable-devtools
115k
1"""
2Check the numpy version is valid.
3
4Note that a development version is marked by the presence of 'dev0' or '+'
5in the version string, all else is treated as a release. The version string
6itself is set from the output of ``git describe`` which relies on tags.
7
8Examples
9--------
10
11Valid Development: 1.22.0.dev0 1.22.0.dev0+5-g7999db4df2 1.22.0+5-g7999db4df2
12Valid Release: 1.21.0.rc1, 1.21.0.b1, 1.21.0
13Invalid: 1.22.0.dev, 1.22.0.dev0-5-g7999db4dfB, 1.21.0.d1, 1.21.a
14
15Note that a release is determined by the version string, which in turn
16is controlled by the result of the ``git describe`` command.
17"""
18import re
19
20import numpy as np
21from numpy.testing import assert_
22
23
24def test_valid_numpy_version():
25 # Verify that the numpy version is a valid one (no .post suffix or other
26 # nonsense). See gh-6431 for an issue caused by an invalid version.
27 version_pattern = r"^[0-9]+\.[0-9]+\.[0-9]+(a[0-9]|b[0-9]|rc[0-9])?"
28 dev_suffix = r"(\.dev[0-9]+(\+git[0-9]+\.[0-9a-f]+)?)?"
29 res = re.match(version_pattern + dev_suffix + '$', np.__version__)
30
31 assert_(res is not None, np.__version__)
32
33
34def test_short_version():
35 # Check numpy.short_version actually exists
36 if np.version.release:
37 assert_(np.__version__ == np.version.short_version,
38 "short_version mismatch in release version")
39 else:
40 assert_(np.__version__.split("+")[0] == np.version.short_version,
41 "short_version mismatch in development version")
42
43
44def test_version_module():
45 contents = {s for s in dir(np.version) if not s.startswith('_')}
46 expected = {
47 'full_version',
48 'git_revision',
49 'release',
50 'short_version',
51 'version',
52 }
53
54 assert contents == expected
55 