@@ -639,25 +639,43 @@ def _gen_filename(self, name):
639639 nib .CommandLine .input_spec = nib .CommandLineInputSpec
640640
641641
642- def test_Commandline_environ ():
642+ def test_Commandline_environ (monkeypatch , tmpdir ):
643643 from nipype import config
644644 config .set_default_config ()
645+
646+ tmpdir .chdir ()
647+ monkeypatch .setitem (os .environ , 'DISPLAY' , ':1' )
648+ # Test environment
645649 ci3 = nib .CommandLine (command = 'echo' )
646650 res = ci3 .run ()
647651 assert res .runtime .environ ['DISPLAY' ] == ':1'
652+
653+ # Test display_variable option
654+ monkeypatch .delitem (os .environ , 'DISPLAY' , raising = False )
648655 config .set ('execution' , 'display_variable' , ':3' )
649656 res = ci3 .run ()
650657 assert not 'DISPLAY' in ci3 .inputs .environ
658+ assert not 'DISPLAY' in res .runtime .environ
659+
660+ # If the interface has _redirect_x then yes, it should be set
661+ ci3 ._redirect_x = True
662+ res = ci3 .run ()
651663 assert res .runtime .environ ['DISPLAY' ] == ':3'
664+
665+ # Test overwrite
666+ monkeypatch .setitem (os .environ , 'DISPLAY' , ':1' )
652667 ci3 .inputs .environ = {'DISPLAY' : ':2' }
653668 res = ci3 .run ()
654669 assert res .runtime .environ ['DISPLAY' ] == ':2'
655670
656671
657- def test_CommandLine_output (setup_file ):
658- tmp_infile = setup_file
659- tmpd , name = os .path .split (tmp_infile )
660- assert os .path .exists (tmp_infile )
672+ def test_CommandLine_output (tmpdir ):
673+ # Create one file
674+ tmpdir .chdir ()
675+ file = tmpdir .join ('foo.txt' )
676+ file .write ('123456\n ' )
677+ name = os .path .basename (file .strpath )
678+
661679 ci = nib .CommandLine (command = 'ls -l' )
662680 ci .inputs .terminal_output = 'allatonce'
663681 res = ci .run ()
0 commit comments