Skip to content

Commit

Permalink
got tests to load
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Dec 16, 2024
1 parent 70d0e06 commit 1daec25
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 319 deletions.
25 changes: 20 additions & 5 deletions pydra/design/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,13 @@ def make(
input_helps=input_helps,
output_helps=output_helps,
)
class_name = re.sub(r"[^\w]", "_", executable) if not name else name
if name:
class_name = name
else:
class_name = (
"_".join(executable) if isinstance(executable, list) else executable
)
class_name = re.sub(r"[^\w]", "_", class_name)
if class_name[0].isdigit():
class_name = f"_{class_name}"

Expand Down Expand Up @@ -457,10 +463,19 @@ def parse_command_line_template(
else:
assert outputs is None
outputs = {}
parts = template.split(maxsplit=1)
if len(parts) == 1:
return template, inputs, outputs
executable, args_str = parts
parts = template.split()
executable = []
for i, part in enumerate(parts, start=1):
if part.startswith("<") or part.startswith("-"):
break
executable.append(part)
if not executable:
raise ValueError(f"Found no executable in command line template: {template}")
if len(executable) == 1:
executable = executable[0]
if i == len(parts):
return executable, inputs, outputs
args_str = " ".join(parts[i:])
tokens = re.split(r"\s+", args_str.strip())
arg_pattern = r"<([:a-zA-Z0-9_,\|\-\.\/\+]+(?:\?|=[^>]+)?)>"
opt_pattern = r"--?[a-zA-Z0-9_]+"
Expand Down
88 changes: 32 additions & 56 deletions pydra/engine/tests/test_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
from ..task import ShellTask
from ..submitter import Submitter
from ..specs import (
ShellSpec,
SpecInfo,
File,
)
from pydra.design import shell
from .utils import no_win, need_docker, need_singularity

import attr
import pytest


Expand Down Expand Up @@ -176,33 +173,22 @@ def test_singularity_1_subm(tmp_path, plugin):

def create_shelly_inputfile(tempdir, filename, name, executable):
"""creating a task with a simple input_spec"""
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"file",
attr.ib(
type=File,
metadata={
"position": 1,
"help_string": "files",
"mandatory": True,
"argstr": "",
},
),
)
],
bases=(ShellSpec,),
)
inputs = [
shell.arg(
name="file",
type=File,
position=1,
help_string="files",
mandatory=True,
argstr="",
)
]

kwargs = {} if filename is None else {"file": filename}
shelly = ShellTask(
name=name,
executable=executable,
cache_dir=makedir(tempdir, name),
input_spec=my_input_spec,
**kwargs,
)
shelly = shell.define(
executable,
input=inputs,
)(**kwargs)
return shelly


Expand Down Expand Up @@ -363,35 +349,25 @@ def test_docker_fileinp_st(tmp_path):

def create_shelly_outputfile(tempdir, filename, name, executable="cp"):
"""creating a task with an input_spec that contains a template"""
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"file_orig",
attr.ib(
type=File,
metadata={"position": 2, "help_string": "new file", "argstr": ""},
),
),
(
"file_copy",
attr.ib(
type=str,
metadata={
"output_file_template": "{file_orig}_copy",
"help_string": "output file",
"argstr": "",
},
),
),
],
bases=(ShellSpec,),
)
my_input_spec = [
shell.arg(
name="file_orig",
type=File,
position=2,
help_string="new file",
argstr="",
),
shell.arg(
name="file_copy",
type=str,
output_file_template="{file_orig}_copy",
help_string="output file",
argstr="",
),
]

kwargs = {} if filename is None else {"file_orig": filename}
shelly = ShellTask(
name=name,
executable=executable,
shelly = shell.define(executable)(
cache_dir=makedir(tempdir, name),
input_spec=my_input_spec,
**kwargs,
Expand Down
2 changes: 0 additions & 2 deletions pydra/engine/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import platform
import typing as ty
import pytest
import attrs
import cloudpickle as cp
from unittest.mock import Mock
from fileformats.generic import Directory, File
Expand All @@ -20,7 +19,6 @@
parse_format_string,
)
from pydra.utils.hash import hash_function
from ..core import Workflow


def test_save(tmpdir):
Expand Down
2 changes: 1 addition & 1 deletion pydra/engine/tests/test_helpers_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from unittest.mock import Mock
import pytest
from fileformats.generic import File
from ..specs import SpecInfo, ShellSpec
from ..specs import ShellSpec
from ..task import ShellTask
from ..helpers_file import (
ensure_list,
Expand Down
80 changes: 30 additions & 50 deletions pydra/engine/tests/test_nipype1_convert.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,56 @@
import typing as ty
import pytest
from pathlib import Path
from pydra.engine.specs import ShellOutputs, ShellSpec
from fileformats.generic import File
from pydra.design import shell


from ..task import ShellTask
from ..specs import ShellOutputs, ShellSpec, SpecInfo, File
def find_txt(output_dir: Path) -> File:
files = list(output_dir.glob("*.txt"))
assert len(files) == 1
return files[0]

interf_input_spec = SpecInfo(
name="Input", fields=[("test", ty.Any, {"help_string": "test"})], bases=(ShellSpec,)
)
interf_output_spec = SpecInfo(
name="Output", fields=[("test_out", File, "*.txt")], bases=(ShellOutputs,)
)

interf_inputs = [shell.arg(name="test", type=ty.Any, help_string="test")]
interf_outputs = [shell.out(name="test_out", type=File, callable=find_txt)]

class Interf_1(ShellTask):
"""class with customized input/output specs"""

input_spec = interf_input_spec
output_spec = interf_output_spec
Interf_1 = shell.define(inputs=interf_inputs, outputs=interf_outputs)
Interf_2 = shell.define("testing command", inputs=interf_inputs, outputs=interf_outputs)


class Interf_2(ShellTask):
"""class with customized input/output specs and executables"""
@shell.define
class Interf_3(ShellSpec["Interf_3.Outputs"]):
"""class with customized input and executables"""

input_spec = interf_input_spec
output_spec = interf_output_spec
executable = "testing command"
executable = ["testing", "command"]

in_file: str = shell.arg(help_string="in_file", argstr="{in_file}")

class Interf_3(ShellTask):
"""class with customized input and executables"""
@shell.outputs
class Outputs(ShellOutputs):
pass

input_spec = SpecInfo(
name="Input",
fields=[
(
"in_file",
str,
{"help_string": "in_file", "argstr": "'{in_file}'"},
)
],
bases=(ShellSpec,),
)
executable = "testing command"


class TouchInterf(ShellTask):
@shell.define
class TouchInterf(ShellSpec["TouchInterf.Outputs"]):
"""class with customized input and executables"""

input_spec = SpecInfo(
name="Input",
fields=[
(
"new_file",
str,
{
"help_string": "new_file",
"argstr": "",
"output_file_template": "{new_file}",
},
)
],
bases=(ShellSpec,),
new_file: str = shell.outarg(
help_string="new_file", argstr="", path_template="{new_file}"
)
executable = "touch"

@shell.outputs
class Outputs(ShellOutputs):
pass


def test_interface_specs_1():
"""testing if class input/output spec are set properly"""
task = Interf_1(executable="ls")
assert task.input_spec == interf_input_spec
assert task.output_spec == interf_output_spec
task_spec = Interf_1(executable="ls")
assert task.Outputs == Interf_1.Outputs


def test_interface_specs_2():
Expand Down
2 changes: 1 addition & 1 deletion pydra/engine/tests/test_node_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)

from ..core import Task
from ..specs import StateArray
from pydra.utils.typing import StateArray
from ..submitter import Submitter


Expand Down
1 change: 0 additions & 1 deletion pydra/engine/tests/test_numpy_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


from ..submitter import Submitter
from ..core import Workflow
from pydra.mark import task, annotate
from .utils import identity
from pydra.utils.hash import hash_function
Expand Down
1 change: 0 additions & 1 deletion pydra/engine/tests/test_profiles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from ..core import Workflow
from ..helpers import load_task
from pydra import mark

Expand Down
11 changes: 6 additions & 5 deletions pydra/engine/tests/test_shelltask.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import attr
import typing as ty
import os, sys
import subprocess as sp
import os
import sys
import pytest
from pathlib import Path
import re
import stat

from ..task import ShellTask
from ..submitter import Submitter
from ..core import Workflow
from ..specs import (
ShellOutputs,
ShellSpec,
SpecInfo,
)
from fileformats.generic import (
File,
Directory,
MultiInputFile,
)
from pydra.utils.typing import (
MultiOutputFile,
MultiInputObj,
)
Expand Down
Loading

0 comments on commit 1daec25

Please sign in to comment.