-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [BUG] inside unit_tests workflow * [DOC] runner help * Creating entry-points for the project * [DOC] command line tools * [DOC] command line tools * Adding a tester command line tool * [DATALAD] change results url * Runner configuration * Remove dir func in * Runner always stops on first crash * [TEST][helpers] not failing test if correlation under threshold * [DOC] narps_open.core.common * [ENH][TEST] narps_open.core.nodes module * [ENH][DOC] node generators in core module * [PEP8][SPELL] node generators in core module * Add a remove parent dir node generator * [REFAC][DOC] Creators at interface level instead of nodes * Creating an interface factory * Remove node modules after merging
- Loading branch information
Showing
7 changed files
with
229 additions
and
120 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
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,74 @@ | ||
#!/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 = [] | ||
) | ||
|
||
class InterfaceFactory(): | ||
""" A class to generate interfaces from narps_open.core functions """ | ||
|
||
# A list of creators, one for each function | ||
creators = { | ||
'remove_directory' : RemoveDirectoryInterfaceCreator, | ||
'remove_parent_directory' : RemoveParentDirectoryInterfaceCreator, | ||
'remove_file' : RemoveFileInterfaceCreator | ||
} | ||
|
||
@classmethod | ||
def create(cls, creator_name: str): | ||
""" Return a new Function interface | ||
Arguments : | ||
creator_name, str : the key for the creator to be used | ||
""" | ||
# Actually create the interface, using a creator | ||
creator = cls.creators[creator_name] | ||
return creator.create_interface() |
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
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,103 @@ | ||
#!/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, raises | ||
|
||
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_interface = ValidNC.create_interface() | ||
assert isinstance(test_interface, 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_interface = interfaces.RemoveParentDirectoryInterfaceCreator.create_interface() | ||
assert isinstance(test_interface, Function) | ||
inputs = str(test_interface.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_interface = interfaces.RemoveDirectoryInterfaceCreator.create_interface() | ||
assert isinstance(test_interface, Function) | ||
inputs = str(test_interface.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_interface = interfaces.RemoveFileInterfaceCreator.create_interface() | ||
assert isinstance(test_interface, Function) | ||
inputs = str(test_interface.inputs) | ||
assert '_ = <undefined>' in inputs | ||
assert 'file_name = <undefined>' in inputs | ||
assert 'function_str = def remove_file(_, file_name: str) -> None:' in inputs | ||
|
||
class TestInterfaceFactory: | ||
""" A class that contains all the unit tests for the InterfaceFactory class.""" | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_create(): | ||
""" Test the create method """ | ||
|
||
with raises(KeyError): | ||
interfaces.InterfaceFactory.create('fake_function') | ||
|
||
test_interface = interfaces.InterfaceFactory.create('remove_file') | ||
assert isinstance(test_interface, Function) | ||
inputs = str(test_interface.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.