Skip to content

Commit c97e489

Browse files
committed
debugging running tests
1 parent dc9fe56 commit c97e489

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

nipype2pydra/cli/convert.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ def convert(
6969
shutil.rmtree(package_dir / "auto")
7070
else:
7171
for fspath in package_dir.iterdir():
72-
if fspath == package_dir / "__init__.py":
72+
if fspath.parent == package_dir and fspath.name in (
73+
"_version.py",
74+
"__init__.py",
75+
):
7376
continue
7477
if fspath.is_dir():
7578
shutil.rmtree(fspath)

nipype2pydra/workflow.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class WorkflowInterfaceField:
7171
},
7272
)
7373
node_name: ty.Optional[str] = attrs.field(
74+
default=None,
7475
metadata={
7576
"help": "The name of the node that the input/output is connected to",
7677
},
@@ -130,7 +131,7 @@ def type_repr_(t):
130131
elif issubclass(t, Field):
131132
return t.primitive.__name__
132133
elif issubclass(t, FileSet):
133-
return t.__name__
134+
return t.type_name
134135
elif t.__module__ == "builtins":
135136
return t.__name__
136137
else:
@@ -764,7 +765,9 @@ def write(
764765
),
765766
converted_code=self.test_code,
766767
used=self.test_used,
767-
additional_imports=self.input_output_imports,
768+
additional_imports=(
769+
self.input_output_imports + parse_imports("import pytest")
770+
),
768771
)
769772

770773
conftest_fspath = test_module_fspath.parent / "conftest.py"
@@ -931,22 +934,51 @@ def parsed_statements(self):
931934
def test_code(self):
932935
args_str = ", ".join(f"{n}={v}" for n, v in self.test_inputs.items())
933936

934-
return f"""
937+
code_str = f"""
935938
936-
def test_{self.name}():
939+
940+
def test_{self.name}_build():
937941
workflow = {self.name}({args_str})
938942
assert isinstance(workflow, Workflow)
939943
"""
940944

945+
inputs_dict = {}
946+
for inpt in self.inputs.values():
947+
if issubclass(inpt.type, FileSet):
948+
inputs_dict[inpt.name] = inpt.type.type_name + ".sample()"
949+
elif inpt.name in self.test_inputs:
950+
inputs_dict[inpt.name] = self.test_inputs[inpt.name]
951+
args_str = ", ".join(f"{n}={v}" for n, v in inputs_dict.items())
952+
953+
code_str += f"""
954+
955+
@pytest.mark.skip(reason="Appropriate inputs for this workflow haven't been specified yet")
956+
def test_{self.name}_run():
957+
workflow = {self.name}({args_str})
958+
result = workflow(plugin='serial')
959+
print(result.out)
960+
"""
961+
return code_str
962+
941963
@property
942964
def test_used(self):
965+
nonstd_types = [
966+
i.type for i in self.inputs.values() if issubclass(i.type, FileSet)
967+
]
968+
nonstd_type_imports = []
969+
for tp in itertools.chain(*(unwrap_nested_type(t) for t in nonstd_types)):
970+
nonstd_type_imports.append(ImportStatement.from_object(tp))
971+
943972
return UsedSymbols(
944973
module_name=self.nipype_module.__name__,
945-
imports=parse_imports(
946-
[
947-
f"from {self.output_module} import {self.name}",
948-
"from pydra.engine import Workflow",
949-
]
974+
imports=(
975+
nonstd_type_imports
976+
+ parse_imports(
977+
[
978+
f"from {self.output_module} import {self.name}",
979+
"from pydra.engine import Workflow",
980+
]
981+
)
950982
),
951983
)
952984

0 commit comments

Comments
 (0)