1
1
"""Tests to ensure that the dependency declarations are sane.
2
2
"""
3
3
4
- import configparser
5
4
import pprint
6
- from functools import lru_cache
7
- from pathlib import Path
8
- from typing import List
9
5
10
6
import pytest
11
7
from packaging .requirements import Requirement
12
8
13
- SETUP_CFG_FILE = Path (__file__ ).parent .parent / "setup.cfg"
14
-
15
9
16
10
def is_pinned (requirement : Requirement ) -> bool :
17
11
return "==" in str (requirement .specifier )
18
12
19
13
20
- @lru_cache (maxsize = None )
21
- def get_package_dependencies () -> List [Requirement ]:
22
- """A cached reader for getting dependencies of this package."""
23
- parser = configparser .ConfigParser ()
24
- parser .read (SETUP_CFG_FILE )
25
-
26
- return [
27
- Requirement (line )
28
- for line in parser .get ("options" , "install_requires" ).splitlines ()
29
- if line
30
- ]
31
-
32
-
33
14
# The ordering of these markers is important, and is used in test names.
34
15
# The tests, when run, look like: PyPy-3.6-Linux-aarch64` (bottom-first)
35
16
@pytest .mark .parametrize ("platform_machine" , ["x86" , "x86_64" , "aarch64" , "ppc64le" , "s390x" , "arm64" , "loongarch64" ])
@@ -41,6 +22,7 @@ def test_has_at_most_one_pinned_dependency(
41
22
platform_system ,
42
23
python_version ,
43
24
platform_python_implementation ,
25
+ cfg_requirements ,
44
26
):
45
27
# These are known to be platforms that are not valid / possible at this time.
46
28
# due the the sheer variety, the default assumption is that a given combination
@@ -84,7 +66,7 @@ def test_has_at_most_one_pinned_dependency(
84
66
}
85
67
86
68
filtered_requirements = []
87
- for req in get_package_dependencies () :
69
+ for req in cfg_requirements :
88
70
assert req .marker
89
71
if not req .marker .evaluate (environment ):
90
72
continue
@@ -131,9 +113,9 @@ def test_has_at_most_one_pinned_dependency(
131
113
), f"{ log_msg } .\n { pprint .pformat (environment )} "
132
114
133
115
134
- def test_valid_numpy_is_installed ():
116
+ def test_valid_numpy_is_installed (cfg_requirements ):
135
117
filtered_requirements = []
136
- for req in get_package_dependencies () :
118
+ for req in cfg_requirements :
137
119
if req .marker .evaluate ():
138
120
filtered_requirements .append (req )
139
121
0 commit comments