Skip to content

Commit

Permalink
Test format...
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Sep 6, 2024
1 parent 8f927c2 commit 80b6cef
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
57 changes: 56 additions & 1 deletion lib/galaxy/tool_util/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]]
20 changes: 20 additions & 0 deletions test/unit/tool_util/test_test_format_model.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 80b6cef

Please sign in to comment.