1- import ast
2- from pathlib import Path
3-
41import pytest
52
3+ from tests .ast_function_source_utils import collect_function_sources
4+
65pytestmark = pytest .mark .architecture
76
87
9- MODULE_PATH = Path ( "hyperbrowser/client/managers/job_request_utils.py" )
8+ MODULE_PATH = "hyperbrowser/client/managers/job_request_utils.py"
109
1110SYNC_WRAPPER_TO_MODEL_HELPER = {
1211 "start_job" : "post_model_request(" ,
2221 "put_job_action_async" : "put_model_request_async(" ,
2322}
2423
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-
3824def test_sync_job_request_wrappers_delegate_to_model_helpers ():
39- function_sources = _collect_function_sources ( )
25+ function_sources = collect_function_sources ( MODULE_PATH )
4026 for wrapper_name , helper_call in SYNC_WRAPPER_TO_MODEL_HELPER .items ():
4127 wrapper_source = function_sources [wrapper_name ]
4228 assert helper_call in wrapper_source
@@ -45,7 +31,7 @@ def test_sync_job_request_wrappers_delegate_to_model_helpers():
4531
4632
4733def test_async_job_request_wrappers_delegate_to_model_helpers ():
48- function_sources = _collect_function_sources ( )
34+ function_sources = collect_function_sources ( MODULE_PATH )
4935 for wrapper_name , helper_call in ASYNC_WRAPPER_TO_MODEL_HELPER .items ():
5036 wrapper_source = function_sources [wrapper_name ]
5137 assert helper_call in wrapper_source
0 commit comments