Skip to content

Commit 42b4777

Browse files
committed
enh: increase coverage of KeySelect utility
1 parent 087f5c3 commit 42b4777

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""KeySelect tests."""
2+
import pytest
3+
from ..utility import KeySelect
4+
5+
6+
def test_KeySelect():
7+
"""Test KeySelect."""
8+
with pytest.raises(ValueError):
9+
KeySelect(fields='field1', keys=['a', 'b', 'c', 'a'])
10+
11+
with pytest.raises(ValueError):
12+
KeySelect(fields=[])

niworkflows/interfaces/utility.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,36 @@ class KeySelect(BaseInterface):
8989
output_spec = _KeySelectOutputSpec
9090

9191
def __init__(self, keys=None, fields=None, **inputs):
92+
"""
93+
Instantiate a KeySelect utility interface.
94+
95+
Examples
96+
--------
97+
>>> ks = KeySelect(fields='field1')
98+
>>> ks.inputs
99+
<BLANKLINE>
100+
field1 = <undefined>
101+
key = <undefined>
102+
keys = <undefined>
103+
<BLANKLINE>
104+
105+
>>> ks = KeySelect(fields='field1', field1=['a', 'b'])
106+
>>> ks.inputs
107+
<BLANKLINE>
108+
field1 = ['a', 'b']
109+
key = <undefined>
110+
keys = <undefined>
111+
<BLANKLINE>
112+
113+
>>> ks = KeySelect()
114+
Traceback (most recent call last):
115+
ValueError: A list or multiplexed...
116+
117+
>>> ks = KeySelect(fields='key')
118+
Traceback (most recent call last):
119+
ValueError: Some fields are invalid...
120+
121+
"""
92122
# Call constructor
93123
super(KeySelect, self).__init__(**inputs)
94124

@@ -151,6 +181,5 @@ def _list_outputs(self):
151181

152182
def _outputs(self):
153183
base = super(KeySelect, self)._outputs()
154-
if self._fields:
155-
base = add_traits(base, self._fields)
184+
base = add_traits(base, self._fields)
156185
return base

0 commit comments

Comments
 (0)