Skip to content

Commit eacd567

Browse files
authored
Merge pull request #2735 from leej3/master
ENH: Add tab completion for node and interface inputs properties
2 parents 3ec8065 + 59a4ba0 commit eacd567

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

nipype/interfaces/base/specs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ def get_hashval(self, hash_method=None):
234234
The md5 hash value of the traited spec
235235
236236
"""
237-
238237
list_withhash = []
239238
list_nofilename = []
240239
for name, val in sorted(self.trait_get().items()):
@@ -309,6 +308,10 @@ def _get_sorteddict(self,
309308
out = objekt
310309
return out
311310

311+
@property
312+
def __all__(self):
313+
return self.copyable_trait_names()
314+
312315

313316
class TraitedSpec(BaseTraitedSpec):
314317
""" Create a subclass with strict traits.

nipype/interfaces/base/tests/test_specs.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
from ....utils.filemanip import split_filename
1212
from ... import base as nib
1313
from ...base import traits, Undefined
14+
from ....interfaces import fsl
15+
from ...utility.wrappers import Function
16+
from ....pipeline import Node
17+
1418

1519
standard_library.install_aliases()
1620

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

4953

54+
def test_TraitedSpec_tab_completion():
55+
bet_nd = Node(fsl.BET(), name='bet')
56+
bet_interface = fsl.BET()
57+
bet_inputs = bet_nd.inputs.class_editable_traits()
58+
bet_outputs = bet_nd.outputs.class_editable_traits()
59+
60+
# Check __all__ for bet node and interface inputs
61+
assert set(bet_nd.inputs.__all__) == set(bet_inputs)
62+
assert set(bet_interface.inputs.__all__) == set(bet_inputs)
63+
64+
# Check __all__ for bet node outputs
65+
assert set(bet_nd.outputs.__all__) == set(bet_outputs)
66+
67+
5068
@pytest.mark.skip
5169
def test_TraitedSpec_dynamic():
5270
from pickle import dumps, loads
@@ -63,6 +81,36 @@ def test_TraitedSpec_dynamic():
6381
assign_a_again
6482

6583

84+
def test_DynamicTraitedSpec_tab_completion():
85+
def extract_func(list_out):
86+
return list_out[0]
87+
88+
# Define interface
89+
func_interface = Function(input_names=["list_out"],
90+
output_names=["out_file", "another_file"],
91+
function=extract_func)
92+
# Define node
93+
list_extract = Node(Function(
94+
input_names=["list_out"], output_names=["out_file"],
95+
function=extract_func), name="list_extract")
96+
97+
# Check __all__ for interface inputs
98+
expected_input = set(list_extract.inputs.editable_traits())
99+
assert(set(func_interface.inputs.__all__) == expected_input)
100+
101+
# Check __all__ for node inputs
102+
assert(set(list_extract.inputs.__all__) == expected_input)
103+
104+
# Check __all__ for node outputs
105+
expected_output = set(list_extract.outputs.editable_traits())
106+
assert(set(list_extract.outputs.__all__) == expected_output)
107+
108+
# Add trait and retest
109+
list_extract._interface._output_names.append('added_out_trait')
110+
expected_output.add('added_out_trait')
111+
assert(set(list_extract.outputs.__all__) == expected_output)
112+
113+
66114
def test_TraitedSpec_logic():
67115
class spec3(nib.TraitedSpec):
68116
_xor_inputs = ('foo', 'bar')

0 commit comments

Comments
 (0)