Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions desloppify/languages/python/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
r"^\s*assert\s+",
r"self\.assert\w+\(",
r"pytest\.raises\(",
r"\b(?:np|numpy)\.testing\.assert_\w+\s*\(",
r"\.assert_called",
r"\.assert_not_called",
]
Expand Down
27 changes: 26 additions & 1 deletion desloppify/tests/detectors/coverage/test_test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,32 @@ def test_no_directly_tested(self):


class TestAnalyzeTestQuality:
@pytest.mark.parametrize("module", ["np", "numpy"])
def test_python_numpy_testing_assertions(self, tmp_path, module):
content = (
"def test_values():\n"
f" {module}.testing.assert_allclose(actual, expected)\n"
f" {module}.testing.assert_array_equal(actual, expected)\n"
"\n"
"def test_bounds():\n"
f" {module}.testing.assert_array_less(actual, upper_bound)\n"
)
tf = _write_file(tmp_path, "test_arrays.py", content)
result = analyze_test_quality({tf}, "python")
assert result[tf]["assertions"] == 3
assert result[tf]["test_functions"] == 2
assert result[tf]["quality"] not in {"assertion_free", "smoke"}

def test_python_numpy_assertion_references_and_comments_do_not_count(self, tmp_path):
content = (
"def test_values():\n"
" helper = np.testing.assert_allclose\n"
" # np.testing.assert_array_equal(actual, expected)\n"
)
tf = _write_file(tmp_path, "test_references.py", content)
result = analyze_test_quality({tf}, "python")
assert result[tf]["assertions"] == 0

# Python test function counting uses MULTILINE and should count all test defs.

def test_python_thorough(self, tmp_path):
Expand Down Expand Up @@ -971,4 +997,3 @@ def test_naming_convention_mapping(self, tmp_path):
if e["detail"]["kind"] in ("untested_module", "untested_critical")
]
assert untested == []