Ejemplo n.º 1
0
def cases(runnable):
    """Build a `list` of :class:`TestCase` objects for specified runnable."""
    cases = []

    tests_path = _tests_path(runnable)
    if tests_path is None:
        if runnable.type == RunnableType.galaxy_tool:
            tool_source = get_tool_source(runnable.path)
            test_dicts = tool_source.parse_tests_to_dict()
            tool_id = tool_source.parse_id()
            tool_version = tool_source.parse_version()
            for i, test_dict in enumerate(test_dicts.get("tests", [])):
                cases.append(ExternalGalaxyToolTestCase(runnable, tool_id, tool_version, i, test_dict))
        return cases

    tests_directory = os.path.abspath(os.path.dirname(tests_path))

    def normalize_to_tests_path(path):
        if not os.path.isabs(path):
            absolute_path = os.path.join(tests_directory, path)
        else:
            absolute_path = path
        return os.path.normpath(absolute_path)

    with open(tests_path, "r") as f:
        tests_def = yaml.load(f)

    if not isinstance(tests_def, list):
        message = TEST_FILE_NOT_LIST_MESSAGE % tests_path
        raise Exception(message)

    for i, test_def in enumerate(tests_def):
        if "job" not in test_def:
            message = TEST_FIELD_MISSING_MESSAGE % (
                i + 1, tests_path, "job"
            )
            raise Exception(message)
        job_def = test_def["job"]
        if isinstance(job_def, dict):
            job_path = None
            job = job_def
        else:
            job_path = normalize_to_tests_path(job_def)
            job = None

        doc = test_def.get("doc", None)
        output_expectations = test_def.get("outputs", {})
        case = TestCase(
            runnable=runnable,
            tests_directory=tests_directory,
            output_expectations=output_expectations,
            index=i,
            job_path=job_path,
            job=job,
            doc=doc,
        )
        cases.append(case)

    return cases
Ejemplo n.º 2
0
def cases(runnable):
    """Build a `list` of :class:`TestCase` objects for specified runnable."""
    cases = []

    tests_path = _tests_path(runnable)
    if tests_path is None:
        if runnable.type == RunnableType.galaxy_tool:
            tool_source = get_tool_source(runnable.path)
            test_dicts = tool_source.parse_tests_to_dict()
            tool_id = tool_source.parse_id()
            tool_version = tool_source.parse_version()
            for i, test_dict in enumerate(test_dicts.get("tests", [])):
                cases.append(
                    ExternalGalaxyToolTestCase(runnable, tool_id, tool_version,
                                               i, test_dict))
        return cases

    tests_directory = os.path.abspath(os.path.dirname(tests_path))

    def normalize_to_tests_path(path):
        if not os.path.isabs(path):
            absolute_path = os.path.join(tests_directory, path)
        else:
            absolute_path = path
        return os.path.normpath(absolute_path)

    with open(tests_path, "r") as f:
        tests_def = yaml.safe_load(f)

    if not isinstance(tests_def, list):
        message = TEST_FILE_NOT_LIST_MESSAGE % tests_path
        raise Exception(message)

    for i, test_def in enumerate(tests_def):
        if "job" not in test_def:
            message = TEST_FIELD_MISSING_MESSAGE % (i + 1, tests_path, "job")
            raise Exception(message)
        job_def = test_def["job"]
        if isinstance(job_def, dict):
            job_path = None
            job = job_def
        else:
            job_path = normalize_to_tests_path(job_def)
            job = None

        doc = test_def.get("doc", None)
        output_expectations = test_def.get("outputs", {})
        case = TestCase(
            runnable=runnable,
            tests_directory=tests_directory,
            output_expectations=output_expectations,
            index=i,
            job_path=job_path,
            job=job,
            doc=doc,
        )
        cases.append(case)

    return cases
Ejemplo n.º 3
0
 def _test_id(self):
     if self.runnable.type in [
             RunnableType.cwl_tool,
             RunnableType.galaxy_tool,
     ]:
         return get_tool_source(self.runnable.path).parse_id()
     else:
         return os.path.basename(self.runnable.path)
Ejemplo n.º 4
0
 def _test_id(self):
     if self.runnable.type in [
         RunnableType.cwl_tool,
         RunnableType.galaxy_tool,
     ]:
         return get_tool_source(self.runnable.path).parse_id()
     else:
         return os.path.basename(self.runnable.path)
Ejemplo n.º 5
0
 def __setup_tool(self):
     tool_source = get_tool_source(self.tool_file)
     try:
         self.tool = create_tool_from_source(self.app, tool_source, config_file=self.tool_file)
     except Exception:
         self.tool = None
     if getattr(self, "tool_action", None and self.tool):
         self.tool.tool_action = self.tool_action
     return self.tool
Ejemplo n.º 6
0
 def __setup_tool(self):
     tool_source = get_tool_source(self.tool_file)
     try:
         self.tool = create_tool_from_source(self.app,
                                             tool_source,
                                             config_file=self.tool_file)
     except Exception:
         self.tool = None
     if getattr(self, "tool_action", None and self.tool):
         self.tool.tool_action = self.tool_action
     return self.tool
Ejemplo n.º 7
0
def get_outputs(path):
    tool_or_workflow = guess_artifact_type(path)
    if tool_or_workflow == "tool":
        from galaxy.tools.parser import get_tool_source
        tool_source = get_tool_source(path)
        output_datasets, _ = tool_source.parse_outputs(None)
        outputs = [ToolOutput(o) for o in output_datasets.values()]
        return outputs
    else:
        workflow = workflow_proxy(path, strict_cwl_validation=False)
        return [CwlWorkflowOutput(label) for label in workflow.output_labels]
Ejemplo n.º 8
0
def main(argv=None):
    """Main entry-point for the CLI tool."""
    parser = arg_parser(argv, globals())
    add_build_arguments(parser)
    add_single_image_arguments(parser)
    parser.add_argument('command', metavar='COMMAND', help='Command (build-and-test, build, all)')
    parser.add_argument('tool', metavar="TOOL", default=None, help="Path to tool to build mulled image for.")
    args = parser.parse_args()
    tool_source = get_tool_source(args.tool)
    requirements, _ = tool_source.parse_requirements_and_containers()
    targets = requirements_to_mulled_targets(requirements)
    mull_targets(targets, **args_to_mull_targets_kwds(args))
Ejemplo n.º 9
0
def get_outputs(runnable):
    """Return a list of :class:`RunnableOutput` objects for this runnable."""
    if not runnable.is_single_artifact:
        raise NotImplementedError("Cannot generate outputs for a directory.")
    if runnable.type in [RunnableType.galaxy_tool, RunnableType.cwl_tool]:
        tool_source = get_tool_source(runnable.path)
        # TODO: do something with collections at some point
        output_datasets, _ = tool_source.parse_outputs(None)
        return [ToolOutput(o) for o in output_datasets.values()]
    elif runnable.type == RunnableType.galaxy_workflow:
        workflow_outputs = describe_outputs(runnable.path)
        return [GalaxyWorkflowOutput(o) for o in workflow_outputs]
    else:
        raise NotImplementedError("Getting outputs for this artifact type is not yet supported.")
Ejemplo n.º 10
0
def get_outputs(runnable):
    """Return a list of :class:`RunnableOutput` objects for this runnable."""
    if not runnable.is_single_artifact:
        raise NotImplementedError("Cannot generate outputs for a directory.")
    if runnable.type in [RunnableType.galaxy_tool, RunnableType.cwl_tool]:
        tool_source = get_tool_source(runnable.path)
        # TODO: do something with collections at some point
        output_datasets, _ = tool_source.parse_outputs(None)
        return [ToolOutput(o) for o in output_datasets.values()]
    elif runnable.type == RunnableType.galaxy_workflow:
        workflow_outputs = describe_outputs(runnable.path)
        return [GalaxyWorkflowOutput(o) for o in workflow_outputs]
    else:
        raise NotImplementedError("Getting outputs for this artifact type is not yet supported.")
Ejemplo n.º 11
0
def main(argv=None):
    """Main entry-point for the CLI tool."""
    parser = arg_parser(argv, globals())
    add_build_arguments(parser)
    add_single_image_arguments(parser)
    parser.add_argument('command',
                        metavar='COMMAND',
                        help='Command (build-and-test, build, all)')
    parser.add_argument('tool',
                        metavar="TOOL",
                        default=None,
                        help="Path to tool to build mulled image for.")
    args = parser.parse_args()
    tool_source = get_tool_source(args.tool)
    requirements, _ = tool_source.parse_requirements_and_containers()
    targets = requirements_to_mulled_targets(requirements)
    mull_targets(targets, **args_to_mull_targets_kwds(args))
Ejemplo n.º 12
0
 def __setup_tool( self ):
     tool_source = get_tool_source( self.tool_file )
     self.tool = Tool( self.tool_file, tool_source, self.app )
     if getattr( self, "tool_action", None ):
         self.tool.tool_action = self.tool_action
     return self.tool
Ejemplo n.º 13
0
def _tool_id(tool_path):
    tool_source = get_tool_source(tool_path)
    return tool_source.parse_id()
Ejemplo n.º 14
0
def _tool_id(tool_path):
    tool_source = get_tool_source(tool_path)
    return tool_source.parse_id()
Ejemplo n.º 15
0
 def __setup_tool(self):
     tool_source = get_tool_source(self.tool_file)
     self.tool = Tool(self.tool_file, tool_source, self.app)
     if getattr(self, "tool_action", None):
         self.tool.tool_action = self.tool_action
     return self.tool