|
| 1 | +import ast |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +pytestmark = pytest.mark.architecture |
| 7 | + |
| 8 | + |
| 9 | +EXPECTED_AST_FUNCTION_SOURCE_IMPORTER_MODULES = ( |
| 10 | + "tests/test_agent_request_wrapper_internal_reuse.py", |
| 11 | + "tests/test_ast_function_source_utils.py", |
| 12 | + "tests/test_extension_request_function_parse_boundary.py", |
| 13 | + "tests/test_job_request_route_builder_internal_reuse.py", |
| 14 | + "tests/test_job_request_wrapper_internal_reuse.py", |
| 15 | + "tests/test_model_request_function_parse_boundary.py", |
| 16 | + "tests/test_model_request_function_transport_boundary.py", |
| 17 | + "tests/test_model_request_wrapper_internal_reuse.py", |
| 18 | + "tests/test_request_wrapper_internal_reuse.py", |
| 19 | + "tests/test_session_recordings_follow_redirects_boundary.py", |
| 20 | + "tests/test_session_request_function_parse_boundary.py", |
| 21 | + "tests/test_session_request_wrapper_internal_reuse.py", |
| 22 | + "tests/test_session_resource_wrapper_internal_reuse.py", |
| 23 | + "tests/test_web_request_wrapper_internal_reuse.py", |
| 24 | +) |
| 25 | + |
| 26 | +def _imports_collect_function_sources(module_text: str) -> bool: |
| 27 | + module_ast = ast.parse(module_text) |
| 28 | + for node in module_ast.body: |
| 29 | + if not isinstance(node, ast.ImportFrom): |
| 30 | + continue |
| 31 | + if node.module != "tests.ast_function_source_utils": |
| 32 | + continue |
| 33 | + if any(alias.name == "collect_function_sources" for alias in node.names): |
| 34 | + return True |
| 35 | + return False |
| 36 | + |
| 37 | + |
| 38 | +def test_ast_function_source_helper_imports_are_centralized(): |
| 39 | + discovered_modules: list[str] = [] |
| 40 | + for module_path in sorted(Path("tests").glob("test_*.py")): |
| 41 | + module_text = module_path.read_text(encoding="utf-8") |
| 42 | + if not _imports_collect_function_sources(module_text): |
| 43 | + continue |
| 44 | + discovered_modules.append(module_path.as_posix()) |
| 45 | + |
| 46 | + assert discovered_modules == list(EXPECTED_AST_FUNCTION_SOURCE_IMPORTER_MODULES) |
0 commit comments