Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion nipype/interfaces/base/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ def get_hashval(self, hash_method=None):
The md5 hash value of the traited spec

"""

list_withhash = []
list_nofilename = []
for name, val in sorted(self.trait_get().items()):
Expand Down Expand Up @@ -309,6 +308,10 @@ def _get_sorteddict(self,
out = objekt
return out

@property
def __all__(self):
return self.copyable_trait_names()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many blank lines.


class TraitedSpec(BaseTraitedSpec):
""" Create a subclass with strict traits.
Expand Down
48 changes: 48 additions & 0 deletions nipype/interfaces/base/tests/test_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
from ....utils.filemanip import split_filename
from ... import base as nib
from ...base import traits, Undefined
from ....interfaces import fsl
from ...utility.wrappers import Function
from ....pipeline import Node


standard_library.install_aliases()

Expand Down Expand Up @@ -47,6 +51,20 @@ class spec(nib.TraitedSpec):
assert infields.__repr__() == '\nfoo = 1\ngoo = 0.0\n'


def test_TraitedSpec_tab_completion():
bet_nd = Node(fsl.BET(), name = 'bet')
bet_interface = fsl.BET()
bet_inputs = bet_nd.inputs.class_editable_traits()
bet_outputs = bet_nd.outputs.class_editable_traits()

# Check __all__ for bet node and interface inputs
assert set(bet_nd.inputs.__all__) == set(bet_inputs)
assert set(bet_interface.inputs.__all__) == set(bet_inputs)

# Check __all__ for bet node outputs
assert set(bet_nd.outputs.__all__) == set(bet_outputs)


@pytest.mark.skip
def test_TraitedSpec_dynamic():
from pickle import dumps, loads
Expand All @@ -63,6 +81,36 @@ def test_TraitedSpec_dynamic():
assign_a_again


def test_DynamicTraitedSpec_tab_completion():
def extract_func(list_out):
return list_out[0]

# Define interface
func_interface = Function(input_names=["list_out"],
output_names=["out_file","another_file"],
function=extract_func)
# Define node
list_extract = Node(Function(
input_names=["list_out"],output_names=["out_file"],
function=extract_func), name="list_extract")

# Check __all__ for interface inputs
expected_input = sorted(list_extract.inputs.editable_traits())
assert(sorted(func_interface.inputs.__all__) == expected_input)

# Check __all__ for node inputs
assert(sorted(list_extract.inputs.__all__) == expected_input)

# Check __all__ for node outputs
expected_output = sorted(list_extract.outputs.editable_traits())
assert(sorted(list_extract.outputs.__all__) == expected_output)

# Add trait and retest
list_extract._interface._output_names.append('added_out_trait')
expected_output = sorted(['added_out_trait',*expected_output])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 2.7, 3.4 don't like the [*x] syntax. How about making expected_output a set above, moving to set comparisons, and changing this to:

expected_output.add('added_out_trait')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. Thanks for the tip. done

assert(sorted(list_extract.outputs.__all__) == expected_output)


def test_TraitedSpec_logic():
class spec3(nib.TraitedSpec):
_xor_inputs = ('foo', 'bar')
Expand Down