-
Notifications
You must be signed in to change notification settings - Fork 289
/
Copy pathtest_requirements.py
37 lines (26 loc) · 1.23 KB
/
test_requirements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from pathlib import Path
from typing import List, Set
import toml
def test_requirements_base__pyproject() -> None:
"""Check that all dependencies in requirements/base.txt are also in
pyproject.toml."""
missing_deps = _requirements("base") - _pyproject("dependencies")
assert not missing_deps
def test_requirements_base__openapi() -> None:
"""Check that all dependencies in requirements/openapi.txt are also in
requirements/base.txt."""
openapi = {
dep for dep in _requirements("openapi") if not dep.startswith("setuptools")
}
missing_deps = openapi - _requirements("base")
assert not missing_deps
def _pyproject(name: str) -> Set[str]:
"""Returns dependencies from pyproject.toml."""
return _normalize_dependencies(toml.load("pyproject.toml")["project"][name])
def _requirements(name: str) -> Set[str]:
"""Returns dependencies from requirements files."""
path = Path(__file__).parent.parent / "requirements" / f"{name}.txt"
return _normalize_dependencies(path.read_text().splitlines())
def _normalize_dependencies(deps: List[str]) -> Set[str]:
"""Remove spaces, empty lines, and comments."""
return {dep.replace(" ", "") for dep in deps if dep and not dep.startswith("#")}