@@ -639,25 +639,43 @@ def _gen_filename(self, name):
639
639
nib .CommandLine .input_spec = nib .CommandLineInputSpec
640
640
641
641
642
- def test_Commandline_environ ():
642
+ def test_Commandline_environ (monkeypatch , tmpdir ):
643
643
from nipype import config
644
644
config .set_default_config ()
645
+
646
+ tmpdir .chdir ()
647
+ monkeypatch .setitem (os .environ , 'DISPLAY' , ':1' )
648
+ # Test environment
645
649
ci3 = nib .CommandLine (command = 'echo' )
646
650
res = ci3 .run ()
647
651
assert res .runtime .environ ['DISPLAY' ] == ':1'
652
+
653
+ # Test display_variable option
654
+ monkeypatch .delitem (os .environ , 'DISPLAY' , raising = False )
648
655
config .set ('execution' , 'display_variable' , ':3' )
649
656
res = ci3 .run ()
650
657
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 ()
651
663
assert res .runtime .environ ['DISPLAY' ] == ':3'
664
+
665
+ # Test overwrite
666
+ monkeypatch .setitem (os .environ , 'DISPLAY' , ':1' )
652
667
ci3 .inputs .environ = {'DISPLAY' : ':2' }
653
668
res = ci3 .run ()
654
669
assert res .runtime .environ ['DISPLAY' ] == ':2'
655
670
656
671
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
+
661
679
ci = nib .CommandLine (command = 'ls -l' )
662
680
ci .inputs .terminal_output = 'allatonce'
663
681
res = ci .run ()
0 commit comments