Skip to content

Commit

Permalink
Merge pull request #1303 from mvdbeek/restore_testing_against_directory
Browse files Browse the repository at this point in the history
Restore running tool tests against directory
  • Loading branch information
nsoranzo committed Oct 31, 2022
2 parents a4d3b79 + 52fc229 commit 4a45596
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions planemo/engine/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class GalaxyEngine(BaseEngine, metaclass=abc.ABCMeta):
RunnableType.galaxy_workflow,
RunnableType.galaxy_tool,
RunnableType.galaxy_datamanager,
RunnableType.directory,
]

def _run(self, runnables, job_paths):
Expand Down
13 changes: 12 additions & 1 deletion planemo/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
check_output,
for_collections,
)
from planemo.tools import yield_tool_sources_on_paths

TEST_SUFFIXES = ["-tests", "_tests", "-test", "_test"]
TEST_EXTENSIONS = [".yml", ".yaml", ".json"]
Expand Down Expand Up @@ -211,6 +212,16 @@ def workflow_dir_runnables(path: str, return_all: bool = False) -> Optional[Unio
return None


def tool_dir_runnables(path: str, temp_path: Optional[str]) -> Optional[List[Runnable]]:
tool_sources = [p for p in yield_tool_sources_on_paths(ctx=None, paths=[path])]
if tool_sources:
if temp_path:
path = _copy_runnable_tree(path, RunnableType.directory, temp_path)
tool_sources = [p for p in yield_tool_sources_on_paths(ctx=None, paths=[path])]
return [for_path(p) for (p, _) in tool_sources]
return None


@overload
def for_path(path: str, temp_path: Optional[str] = None, return_all: Literal[False] = False) -> Runnable:
...
Expand All @@ -225,7 +236,7 @@ def for_path(path: str, temp_path: Optional[str] = None, return_all: bool = Fals
"""Produce a class:`Runnable` for supplied path."""
runnable_type = None
if os.path.isdir(path):
runnable = workflow_dir_runnables(path, return_all=return_all)
runnable = workflow_dir_runnables(path, return_all=return_all) or tool_dir_runnables(path, temp_path)
if runnable:
return runnable
runnable_type = RunnableType.directory
Expand Down
9 changes: 5 additions & 4 deletions planemo/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Iterable,
Iterator,
List,
Optional,
Tuple,
TYPE_CHECKING,
Union,
Expand Down Expand Up @@ -47,7 +48,7 @@ def uris_to_paths(ctx, uris):


def yield_tool_sources_on_paths(
ctx: "PlanemoCliContext",
ctx: Optional["PlanemoCliContext"],
paths: Iterable[str],
recursive: bool = False,
yield_load_errors: bool = True,
Expand All @@ -62,7 +63,7 @@ def yield_tool_sources_on_paths(


def yield_tool_sources(
ctx: "PlanemoCliContext", path: str, recursive: bool = False, yield_load_errors: bool = True
ctx: Optional["PlanemoCliContext"], path: str, recursive: bool = False, yield_load_errors: bool = True
) -> Iterator[Tuple[str, Union[ToolSource, object]]]:
"""Walk single path and yield ToolSource objects discovered."""
tools = load_tool_sources_from_path(
Expand Down Expand Up @@ -100,13 +101,13 @@ def _load_exception_handler(path, exc_info):
traceback.print_exception(*exc_info, limit=1, file=sys.stderr)


def _is_tool_source(ctx: "PlanemoCliContext", tool_path: str, tool_source: "ToolSource") -> bool:
def _is_tool_source(ctx: Optional["PlanemoCliContext"], tool_path: str, tool_source: "ToolSource") -> bool:
if os.path.basename(tool_path) in SHED_FILES:
return False
root = getattr(tool_source, "root", None)
if root is not None:
if root.tag != "tool":
if ctx.verbose:
if ctx and ctx.verbose:
info(SKIP_XML_MESSAGE % tool_path)
return False
return True
Expand Down
2 changes: 1 addition & 1 deletion tests/data/tools/ok_test_assert_command.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<tool id="copy" name="Copy Dataset" version="1.0">
<description>copies a dataset</description>
<command>
cp $input $output
cp '$input1' '$output'
</command>
<inputs>
<param name="input1" type="data" format="txt" label="Concatenate Dataset"/>
Expand Down
15 changes: 14 additions & 1 deletion tests/test_cmd_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""Module contains :class:`CmdTestTestCase` - integration tests for the ``test`` command."""
import json
import os
from tempfile import NamedTemporaryFile
import shutil
from tempfile import (
NamedTemporaryFile,
TemporaryDirectory,
)

from .test_utils import (
assert_exists,
Expand Down Expand Up @@ -30,6 +34,15 @@ def test_startup_timeout(self):
)
self._check_exit_code(test_command, exit_code=1)

@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS")
def test_tool_in_directory(self):
"""Test with (single) tool in directory."""
with self._isolate(), TemporaryDirectory() as tempdir:
test_artifact = os.path.join(TEST_DATA_DIR, "tools", "ok_test_assert_command.xml")
shutil.copy(test_artifact, tempdir)
test_command = self._test_command(tempdir, "--no_dependency_resolution")
self._check_exit_code(test_command, exit_code=0)

@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS")
def test_data_manager(self):
"""Test testing a data manager test."""
Expand Down

0 comments on commit 4a45596

Please sign in to comment.