@@ -274,6 +274,55 @@ class TestCycle(nib.CommandLine):
274274 assert '%s_generated_mootpl' % nme in res
275275
276276
277+ def test_namesource_constraints (setup_file ):
278+ tmp_infile = setup_file
279+ tmpd , nme , ext = split_filename (tmp_infile )
280+
281+ class constrained_spec (nib .CommandLineInputSpec ):
282+ in_file = nib .File (argstr = "%s" , position = 1 )
283+ threshold = traits .Float (
284+ argstr = "%g" ,
285+ xor = ['mask_file' ],
286+ position = 2 )
287+ mask_file = nib .File (
288+ argstr = "%s" ,
289+ name_source = ['in_file' ],
290+ name_template = '%s_mask' ,
291+ keep_extension = True ,
292+ xor = ['threshold' ],
293+ position = 2 )
294+ out_file1 = nib .File (
295+ argstr = "%s" ,
296+ name_source = ['in_file' ],
297+ name_template = '%s_out1' ,
298+ keep_extension = True ,
299+ position = 3 )
300+ out_file2 = nib .File (
301+ argstr = "%s" ,
302+ name_source = ['in_file' ],
303+ name_template = '%s_out2' ,
304+ keep_extension = True ,
305+ requires = ['threshold' ],
306+ position = 4 )
307+
308+ class TestConstrained (nib .CommandLine ):
309+ _cmd = "mycommand"
310+ input_spec = constrained_spec
311+
312+ tc = TestConstrained ()
313+
314+ # name_source undefined, so template traits remain undefined
315+ assert tc .cmdline == 'mycommand'
316+
317+ # mask_file and out_file1 enabled by name_source definition
318+ tc .inputs .in_file = os .path .basename (tmp_infile )
319+ assert tc .cmdline == 'mycommand foo.txt foo_mask.txt foo_out1.txt'
320+
321+ # mask_file disabled by threshold, out_file2 enabled by threshold
322+ tc .inputs .threshold = 10.
323+ assert tc .cmdline == 'mycommand foo.txt 10 foo_out1.txt foo_out2.txt'
324+
325+
277326def test_TraitedSpec_withFile (setup_file ):
278327 tmp_infile = setup_file
279328 tmpd , nme = os .path .split (tmp_infile )
0 commit comments