codex-python / tests /test_test_selector.py
tailot's picture
Upload folder using huggingface_hub
2a9dc4c verified
Raw History Blame
1.31 kB
"""Tests for import-aware Python test selection."""
from __future__ import annotations
from pathlib import Path
from lingologos_python.test_selector import discover_test_files, is_test_file, select_python_tests
def test_is_test_file_conventions() -> None:
assert is_test_file("tests/test_alpha.py")
assert is_test_file("pkg/alpha_test.py")
assert not is_test_file("src/alpha.py")
def test_discover_test_files_prefers_tests_dir(sample_pkg: Path) -> None:
found = discover_test_files(sample_pkg)
assert found == ["tests/test_mathops.py", "tests/test_textops.py"]
def test_select_python_tests_follows_cross_file_imports(sample_pkg: Path) -> None:
selected_math = select_python_tests(sample_pkg, ["src/mathops.py"])
assert selected_math == ["tests/test_mathops.py", "tests/test_textops.py"]
selected_text = select_python_tests(sample_pkg, ["src/textops.py"])
assert selected_text == ["tests/test_textops.py"]
def test_select_python_tests_returns_self_when_test_file_changed(sample_pkg: Path) -> None:
assert select_python_tests(sample_pkg, ["tests/test_textops.py"]) == ["tests/test_textops.py"]
def test_select_python_tests_returns_empty_for_unknown_file(sample_pkg: Path) -> None:
assert select_python_tests(sample_pkg, ["src/unrelated_missing.py"]) == []