Skip to content

Commit

Permalink
Progress?
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Feb 18, 2024
1 parent 0182b27 commit 26f5f51
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 16 deletions.
69 changes: 59 additions & 10 deletions lib/galaxy/tool_util/verify/interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1764,6 +1765,7 @@ class ToolTestDescriptionDict(TypedDict):
tool_version: Optional[str]
test_index: int
exception: Optional[str]
maxseconds: Optional[int]


class Assertion(BaseModel):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/tool_util/verify/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from galaxy.tool_util.verify.interactor import (
DictClientTestConfig,
GalaxyInteractorApi,
ToolTestDictsT,
ToolTestDescriptionDict,
verify_tool,
)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/galaxy/api/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/galaxy/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/galaxy/services/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/galaxy/services/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
)

0 comments on commit 26f5f51

Please sign in to comment.