forked from Inria-Empenn/narps_open_pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REFAC][DOC] Creators at interface level instead of nodes
- Loading branch information
Showing
5 changed files
with
149 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/python | ||
# coding: utf-8 | ||
|
||
""" Generate useful and recurrent interfaces to write pipelines """ | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
from nipype.interfaces.base.core import Interface | ||
from nipype.interfaces.utility import Function | ||
|
||
from narps_open.core.common import remove_directory, remove_parent_directory, remove_file | ||
|
||
class InterfaceCreator(ABC): | ||
""" An abstract class to shape what interface creators must provide """ | ||
|
||
@staticmethod | ||
@abstractmethod | ||
def create_interface() -> Interface: | ||
""" Return a new interface (to be defined by specialized classes) """ | ||
|
||
class RemoveParentDirectoryInterfaceCreator(InterfaceCreator): | ||
""" An interface creator that provides an interface allowing to remove a directory, | ||
given one of its child's file name. | ||
""" | ||
|
||
@staticmethod | ||
def create_interface() -> Function: | ||
return Function( | ||
function = remove_parent_directory, | ||
input_names = ['_', 'file_name'], | ||
output_names = [] | ||
) | ||
|
||
class RemoveDirectoryInterfaceCreator(InterfaceCreator): | ||
""" An interface creator that provides an interface allowing to remove a directory """ | ||
|
||
@staticmethod | ||
def create_interface() -> Function: | ||
return Function( | ||
function = remove_directory, | ||
input_names = ['_', 'directory_name'], | ||
output_names = [] | ||
) | ||
|
||
class RemoveFileInterfaceCreator(InterfaceCreator): | ||
""" An interface creator that provides an interface allowing to remove a file """ | ||
|
||
@staticmethod | ||
def create_interface() -> Function: | ||
return Function( | ||
function = remove_file, | ||
input_names = ['_', 'file_name'], | ||
output_names = [] | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/usr/bin/python | ||
# coding: utf-8 | ||
|
||
""" Tests of the 'narps_open.core.interfaces' module. | ||
Launch this test with PyTest | ||
Usage: | ||
====== | ||
pytest -q test_interfaces.py | ||
pytest -q test_interfaces.py -k <selected_test> | ||
""" | ||
|
||
from pytest import mark | ||
|
||
from nipype.interfaces.base.core import Interface | ||
from nipype.interfaces.utility import Select, Function | ||
|
||
from narps_open.core import interfaces | ||
|
||
class ValidNC(interfaces.InterfaceCreator): | ||
""" A valid implementation of a InterfaceCreator, for test purposes """ | ||
|
||
@staticmethod | ||
def create_interface() -> Interface: | ||
""" Return a Interface, as expected """ | ||
return Select() | ||
|
||
class TestInterfaceCreator: | ||
""" A class that contains all the unit tests for the InterfaceCreator class.""" | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_create_interface(): | ||
""" Test the create_interface method """ | ||
|
||
test_node = ValidNC.create_interface() | ||
assert isinstance(test_node, Select) | ||
|
||
class TestRemoveParentDirectoryInterfaceCreator: | ||
""" A class that contains all the unit tests for the | ||
RemoveParentDirectoryInterfaceCreator class. | ||
""" | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_create_interface(): | ||
""" Test the create_interface method """ | ||
|
||
test_node = interfaces.RemoveParentDirectoryInterfaceCreator.create_interface() | ||
assert isinstance(test_node, Function) | ||
inputs = str(test_node.inputs) | ||
assert '_ = <undefined>' in inputs | ||
assert 'file_name = <undefined>' in inputs | ||
assert 'function_str = def remove_parent_directory(_, file_name: str) -> None:' in inputs | ||
|
||
class TestRemoveDirectoryInterfaceCreator: | ||
""" A class that contains all the unit tests for the RemoveDirectoryInterfaceCreator class.""" | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_create_interface(): | ||
""" Test the create_interface method """ | ||
|
||
test_node = interfaces.RemoveDirectoryInterfaceCreator.create_interface() | ||
assert isinstance(test_node, Function) | ||
inputs = str(test_node.inputs) | ||
assert '_ = <undefined>' in inputs | ||
assert 'directory_name = <undefined>' in inputs | ||
assert 'function_str = def remove_directory(_, directory_name: str) -> None:' in inputs | ||
|
||
class TestRemoveFileInterfaceCreator: | ||
""" A class that contains all the unit tests for the RemoveFileInterfaceCreator class.""" | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_create_interface(): | ||
""" Test the create_interface method """ | ||
|
||
test_node = interfaces.RemoveFileInterfaceCreator.create_interface() | ||
assert isinstance(test_node, Function) | ||
inputs = str(test_node.inputs) | ||
assert '_ = <undefined>' in inputs | ||
assert 'file_name = <undefined>' in inputs | ||
assert 'function_str = def remove_file(_, file_name: str) -> None:' in inputs |
This file was deleted.
Oops, something went wrong.