-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_cqa.py
More file actions
68 lines (55 loc) · 1.69 KB
/
test_cqa.py
File metadata and controls
68 lines (55 loc) · 1.69 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""Code quality assurance tests using pytest."""
import pathlib
import subprocess
import sys
import pytest
@pytest.fixture(scope="module")
def project_root() -> pathlib.Path:
"""Get the project root directory."""
return pathlib.Path(__file__).parent.parent
def test_cqa_ruff_check(project_root):
"""Test that code passes ruff linting checks."""
result = subprocess.run(
[sys.executable, "-m", "ruff", "check", "."],
capture_output=True,
text=True,
cwd=project_root,
)
if result.returncode != 0:
pytest.fail(
f"ruff check failed:\n{result.stdout}\n{result.stderr}",
pytrace=False,
)
def test_cqa_ruff_format_check(project_root):
"""Test that code is properly formatted according to ruff."""
result = subprocess.run(
[sys.executable, "-m", "ruff", "format", "--check", "."],
capture_output=True,
text=True,
cwd=project_root,
)
if result.returncode != 0:
pytest.fail(
f"ruff format check failed:\n{result.stdout}\n{result.stderr}",
pytrace=False,
)
def test_cqa_mypy(project_root):
"""Test that typemap/ passes mypy type checking."""
result = subprocess.run(
[
sys.executable,
"-m",
"mypy",
"--config-file",
project_root / "pyproject.toml",
"typemap",
],
capture_output=True,
text=True,
cwd=project_root,
)
if result.returncode != 0:
output = result.stdout
if result.stderr:
output += "\n\n" + result.stderr
pytest.fail(f"mypy validation failed:\n{output}", pytrace=False)