From 80b6cef805329d4552c452bc25695fc6108e858f Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 6 Sep 2024 12:33:09 -0400 Subject: [PATCH] Test format... --- lib/galaxy/tool_util/models.py | 57 ++++++++++++++++++- test/unit/tool_util/test_test_format_model.py | 20 +++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 test/unit/tool_util/test_test_format_model.py diff --git a/lib/galaxy/tool_util/models.py b/lib/galaxy/tool_util/models.py index 05fab48515b3..8868764502de 100644 --- a/lib/galaxy/tool_util/models.py +++ b/lib/galaxy/tool_util/models.py @@ -5,11 +5,18 @@ """ from typing import ( + Any, + Dict, List, Optional, + Union, ) -from pydantic import BaseModel +from pydantic import ( + BaseModel, + ConfigDict, + RootModel, +) from .parameters import ( input_models_for_tool_source, @@ -73,3 +80,51 @@ def parse_tool(tool_source: ToolSource) -> ParsedTool: xrefs=xrefs, help=help, ) + + +class StrictModel(BaseModel): + + model_config = ConfigDict( + extra="forbid", + ) + + +class BaseTestOutputModel(StrictModel): + file: Optional[str] = None + compare: Optional[str] = None + checksum: Optional[str] = None + asserts: Optional[str] = None + + +class TestDataOutputAssertions(BaseTestOutputModel): + pass + + +class TestCollectionCollectionElementAssertions(StrictModel): + elements: Optional[Dict[str, "TestCollectionElementAssertion"]] = None + + +class TestCollectionDatasetElementAssertions(BaseTestOutputModel): + pass + + +TestCollectionElementAssertion = Union[ + TestCollectionDatasetElementAssertions, TestCollectionCollectionElementAssertions +] +TestCollectionCollectionElementAssertions.model_rebuild() + + +class TestCollectionOutputAssertions(StrictModel): + elements: Optional[Dict[str, TestCollectionElementAssertion]] = None + + +TestOutputAssertions = Union[TestCollectionOutputAssertions, TestDataOutputAssertions] + + +class TestJob(StrictModel): + doc: Optional[str] + job: Dict[str, Any] + outputs: Dict[str, TestOutputAssertions] + + +Tests = RootModel[List[TestJob]] diff --git a/test/unit/tool_util/test_test_format_model.py b/test/unit/tool_util/test_test_format_model.py new file mode 100644 index 000000000000..7884d73fd297 --- /dev/null +++ b/test/unit/tool_util/test_test_format_model.py @@ -0,0 +1,20 @@ +import os +from pathlib import Path + +import yaml + +from galaxy.tool_util.models import Tests +from galaxy.util import galaxy_directory + +TEST_WORKFLOW_DIRECTORY = os.path.join(galaxy_directory(), "lib", "galaxy_test", "workflow") + + +def test_validate_workflow_tests(): + path = Path(TEST_WORKFLOW_DIRECTORY) + test_files = path.glob("*.gxwf-tests.yml") + for test_file in test_files: + with open(test_file) as f: + json = yaml.safe_load(f) + Tests.model_validate(json) + print("All done") + assert False