|
| 1 | +import ast |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +pytestmark = pytest.mark.architecture |
| 7 | + |
| 8 | + |
| 9 | +MODULE_PATH = Path("hyperbrowser/client/managers/job_request_utils.py") |
| 10 | + |
| 11 | +SYNC_WRAPPER_TO_MODEL_HELPER = { |
| 12 | + "start_job": "post_model_request(", |
| 13 | + "get_job_status": "get_model_request(", |
| 14 | + "get_job": "get_model_request(", |
| 15 | + "put_job_action": "put_model_request(", |
| 16 | +} |
| 17 | + |
| 18 | +ASYNC_WRAPPER_TO_MODEL_HELPER = { |
| 19 | + "start_job_async": "post_model_request_async(", |
| 20 | + "get_job_status_async": "get_model_request_async(", |
| 21 | + "get_job_async": "get_model_request_async(", |
| 22 | + "put_job_action_async": "put_model_request_async(", |
| 23 | +} |
| 24 | + |
| 25 | + |
| 26 | +def _collect_function_sources() -> dict[str, str]: |
| 27 | + module_text = MODULE_PATH.read_text(encoding="utf-8") |
| 28 | + module_ast = ast.parse(module_text) |
| 29 | + function_sources: dict[str, str] = {} |
| 30 | + for node in module_ast.body: |
| 31 | + if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): |
| 32 | + function_source = ast.get_source_segment(module_text, node) |
| 33 | + if function_source is not None: |
| 34 | + function_sources[node.name] = function_source |
| 35 | + return function_sources |
| 36 | + |
| 37 | + |
| 38 | +def test_sync_job_request_wrappers_delegate_to_model_helpers(): |
| 39 | + function_sources = _collect_function_sources() |
| 40 | + for wrapper_name, helper_call in SYNC_WRAPPER_TO_MODEL_HELPER.items(): |
| 41 | + wrapper_source = function_sources[wrapper_name] |
| 42 | + assert helper_call in wrapper_source |
| 43 | + assert "client.transport." not in wrapper_source |
| 44 | + assert "parse_response_model(" not in wrapper_source |
| 45 | + |
| 46 | + |
| 47 | +def test_async_job_request_wrappers_delegate_to_model_helpers(): |
| 48 | + function_sources = _collect_function_sources() |
| 49 | + for wrapper_name, helper_call in ASYNC_WRAPPER_TO_MODEL_HELPER.items(): |
| 50 | + wrapper_source = function_sources[wrapper_name] |
| 51 | + assert helper_call in wrapper_source |
| 52 | + assert "client.transport." not in wrapper_source |
| 53 | + assert "parse_response_model(" not in wrapper_source |
0 commit comments