From 26f5f51c0f850e4deda2af94c393c1a77bc3245d Mon Sep 17 00:00:00 2001 From: John Chilton Date: Sun, 18 Feb 2024 09:44:21 -0500 Subject: [PATCH] Progress? --- lib/galaxy/tool_util/verify/interactor.py | 69 ++++++++++++++++--- lib/galaxy/tool_util/verify/script.py | 4 +- lib/galaxy/webapps/galaxy/api/histories.py | 2 +- lib/galaxy/webapps/galaxy/api/jobs.py | 2 +- .../webapps/galaxy/services/histories.py | 2 +- lib/galaxy/webapps/galaxy/services/jobs.py | 2 +- 6 files changed, 65 insertions(+), 16 deletions(-) diff --git a/lib/galaxy/tool_util/verify/interactor.py b/lib/galaxy/tool_util/verify/interactor.py index 6d1d7754d5e9..3ac3c97a384a 100644 --- a/lib/galaxy/tool_util/verify/interactor.py +++ b/lib/galaxy/tool_util/verify/interactor.py @@ -249,7 +249,7 @@ def get_tool_tests_model(self, tool_id: str, tool_version: Optional[str] = None) assert response.status_code == 200, f"Non 200 response from tool test API. [{response.content}]" return ToolTestCaseList(root=[ToolTestCase(**t) for t in response.json()]) - def get_tool_tests(self, tool_id: str, tool_version: Optional[str] = None) -> ToolTestDictsT: + def get_tool_tests(self, tool_id: str, tool_version: Optional[str] = None) -> List["ToolTestDescriptionDict"]: return [test_case_to_dict(m) for m in self.get_tool_tests_model(tool_id, tool_version).root] def verify_output_collection( @@ -1423,18 +1423,14 @@ def verify_tool( client_test_config: Optional[TestConfig] = None, skip_with_reference_data: bool = False, skip_on_dynamic_param_errors: bool = False, - _tool_test_dicts: Optional[ToolTestDictsT] = None, # extension point only for tests + _tool_test_dicts: Optional[List["ToolTestDescriptionDict"]] = None, # extension point only for tests ): if resource_parameters is None: resource_parameters = {} if client_test_config is None: client_test_config = NullClientTestConfig() tool_test_dicts = _tool_test_dicts or galaxy_interactor.get_tool_tests(tool_id, tool_version=tool_version) - tool_test_dict = tool_test_dicts[test_index] - if "test_index" not in tool_test_dict: - tool_test_dict["test_index"] = test_index - if "tool_id" not in tool_test_dict: - tool_test_dict["tool_id"] = tool_id + tool_test_dict: ToolTestDescriptionDict = tool_test_dicts[test_index] if tool_version is None and "tool_version" in tool_test_dict: tool_version = tool_test_dict.get("tool_version") @@ -1467,7 +1463,12 @@ def verify_tool( if not use_legacy_api: structured_inputs = galaxy_interactor.get_tool_inputs(tool_id, tool_version=tool_version) assert structured_inputs - testdef = ToolTestDescription(cast(ToolTestDict, tool_test_dict)) + testdef = ToolTestDescription.from_dict( + tool_test_dict, + tool_id, + test_index, + maxseconds + ) _handle_def_errors(testdef) created_history = False @@ -1764,6 +1765,7 @@ class ToolTestDescriptionDict(TypedDict): tool_version: Optional[str] test_index: int exception: Optional[str] + maxseconds: Optional[int] class Assertion(BaseModel): @@ -1824,6 +1826,53 @@ class ToolTestDescription: expect_test_failure: bool exception: Optional[str] + @staticmethod + def from_dict(raw_dict: ToolTestDescriptionDict, tool_id: str, test_index: int, maxseconds: int): + error = raw_dict["error"] + processed_test_dict: ToolTestDict + tool_version = raw_dict["tool_version"] + assert tool_version + if error: + exception = raw_dict["exception"] + assert exception is not None + processed_test_dict = InvalidToolTestDict( + error=True, + tool_id=raw_dict.get("tool_id") or tool_id, + tool_version=tool_version, + test_index=raw_dict.get("test_index") or test_index, + inputs=raw_dict["inputs"], + exception=exception, + maxseconds=maxseconds + ) + else: + processed_test_dict = ValidToolTestDict( + error=False, + tool_id=raw_dict.get("tool_id") or tool_id, + tool_version=tool_version, + test_index=raw_dict.get("test_index") or test_index, + inputs=raw_dict["inputs"], + outputs=raw_dict["outputs"], + output_collections=raw_dict["output_collections"], + stdout=raw_dict["stdout"], + stderr=raw_dict["stderr"], + expect_failure=raw_dict["expect_failure"], + expect_test_failure=raw_dict["expect_test_failure"], + command_line=raw_dict["command_line"], + command_version=raw_dict["command_version"], + required_files=raw_dict["required_files"], + required_data_tables=raw_dict["required_data_tables"], + required_loc_files=raw_dict["required_loc_files"], + maxseconds=maxseconds, + ) + expect_exit_code = raw_dict["expect_exit_code"] + if expect_exit_code is not None: + processed_test_dict["expect_exit_code"] = expect_exit_code + num_outputs = raw_dict["num_outputs"] + if num_outputs is not None: + processed_test_dict["num_outputs"] = num_outputs + + return ToolTestDescription(processed_test_dict) + def __init__(self, processed_test_dict: ToolTestDict): assert ( "test_index" in processed_test_dict @@ -1920,8 +1969,8 @@ def to_dict(self) -> ToolTestDescriptionDict: return test_case_to_dict(self.to_model()) -def test_case_to_dict(model: ToolTestCase) -> ToolTestDict: - return cast(ToolTestDict, model.dict()) +def test_case_to_dict(model: ToolTestCase) -> ToolTestDescriptionDict: + return cast(ToolTestDescriptionDict, model.model_dump()) def test_data_iter(required_files): diff --git a/lib/galaxy/tool_util/verify/script.py b/lib/galaxy/tool_util/verify/script.py index ae9e13575d7d..dc1717a65005 100644 --- a/lib/galaxy/tool_util/verify/script.py +++ b/lib/galaxy/tool_util/verify/script.py @@ -26,7 +26,7 @@ from galaxy.tool_util.verify.interactor import ( DictClientTestConfig, GalaxyInteractorApi, - ToolTestDictsT, + ToolTestDescriptionDict, verify_tool, ) @@ -341,7 +341,7 @@ def build_case_references( test_references.append(test_reference) else: assert tool_id - tool_test_dicts: ToolTestDictsT = galaxy_interactor.get_tool_tests(tool_id, tool_version=tool_version) + tool_test_dicts: List[ToolTestDescriptionDict] = galaxy_interactor.get_tool_tests(tool_id, tool_version=tool_version) for i, tool_test_dict in enumerate(tool_test_dicts): this_tool_version = tool_test_dict.get("tool_version") or tool_version this_test_index = i diff --git a/lib/galaxy/webapps/galaxy/api/histories.py b/lib/galaxy/webapps/galaxy/api/histories.py index 42d7b4f48469..6163a4ce996c 100644 --- a/lib/galaxy/webapps/galaxy/api/histories.py +++ b/lib/galaxy/webapps/galaxy/api/histories.py @@ -349,7 +349,7 @@ def citations( ) def tool_requests( self, - history_id: DecodedDatabaseIdField = HistoryIDPathParam, + history_id: HistoryIDPathParam, trans: ProvidesHistoryContext = DependsOnTrans, ) -> List[ToolRequestModel]: return self.service.tool_requests(trans, history_id) diff --git a/lib/galaxy/webapps/galaxy/api/jobs.py b/lib/galaxy/webapps/galaxy/api/jobs.py index 5dfbf134a6c7..0a0dc6d35e8a 100644 --- a/lib/galaxy/webapps/galaxy/api/jobs.py +++ b/lib/galaxy/webapps/galaxy/api/jobs.py @@ -383,7 +383,7 @@ def outputs( ) -> List[Union[JobOutputAssociation, JobOutputCollectionAssociation]]: job = self.service.get_job(trans=trans, job_id=job_id) associations = self.service.dictify_associations(trans, job.output_datasets, job.output_library_datasets) - output_associations = [] + output_associations: List[Union[JobOutputAssociation, JobOutputCollectionAssociation]] = [] for association in associations: output_associations.append(JobOutputAssociation(name=association.name, dataset=association.dataset)) diff --git a/lib/galaxy/webapps/galaxy/services/histories.py b/lib/galaxy/webapps/galaxy/services/histories.py index 14c1677f7aa4..20dea792a5d8 100644 --- a/lib/galaxy/webapps/galaxy/services/histories.py +++ b/lib/galaxy/webapps/galaxy/services/histories.py @@ -548,7 +548,7 @@ def tool_requests( def to_model(tool_request: ToolRequest) -> ToolRequestModel: as_dict = { - "id": Security.secure.encode_id(tool_request.id), + "id": Security.security.encode_id(tool_request.id), "request": tool_request.request, "state": tool_request.state, "state_message": tool_request.state_message, diff --git a/lib/galaxy/webapps/galaxy/services/jobs.py b/lib/galaxy/webapps/galaxy/services/jobs.py index 968220b1d60c..cdba60541d66 100644 --- a/lib/galaxy/webapps/galaxy/services/jobs.py +++ b/lib/galaxy/webapps/galaxy/services/jobs.py @@ -255,7 +255,7 @@ def create(self, trans: ProvidesHistoryContext, job_request: JobRequest) -> JobC result = queue_jobs.delay(request=task_request) return JobCreateResponse( **{ - "tool_request_id": Security.security.encode(tool_request_id), + "tool_request_id": Security.security.encode_id(tool_request_id), "task_result": async_task_summary(result), } )