Skip to content

Commit

Permalink
Merge pull request #2735 from leej3/master
Browse files Browse the repository at this point in the history
ENH: Add tab completion for node and interface inputs properties
  • Loading branch information
effigies committed Oct 17, 2018
2 parents 3ec8065 + 59a4ba0 commit eacd567
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
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()


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 = set(list_extract.inputs.editable_traits())
assert(set(func_interface.inputs.__all__) == expected_input)

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

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

# Add trait and retest
list_extract._interface._output_names.append('added_out_trait')
expected_output.add('added_out_trait')
assert(set(list_extract.outputs.__all__) == expected_output)


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

0 comments on commit eacd567

Please sign in to comment.