forked from nipy/nipype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_r.py
62 lines (49 loc) · 2.09 KB
/
test_r.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
import os
import pytest
from nipype.interfaces import r
no_r = r.no_r
@pytest.mark.skipif(no_r, reason="R is not available")
def test_cmdline(tmp_path):
default_script_file = str(tmp_path / "testscript")
ri = r.RCommand(script="1 + 1", script_file=default_script_file, rfile=False)
r_cmd = r.get_r_command()
assert ri.cmdline == r_cmd + (' -e "1 + 1"')
assert ri.inputs.script == "1 + 1"
assert ri.inputs.script_file == default_script_file
assert not os.path.exists(ri.inputs.script_file), "scriptfile should not exist"
assert not os.path.exists(
default_script_file
), "default scriptfile should not exist."
@pytest.mark.skipif(no_r, reason="R is not available")
def test_run_interface(tmpdir):
cwd = tmpdir.chdir()
default_script_file = r.RInputSpec().script_file
rc = r.RCommand(r_cmd="foo_m")
assert not os.path.exists(default_script_file), "scriptfile should not exist 1."
with pytest.raises(ValueError):
rc.run() # script is mandatory
assert not os.path.exists(default_script_file), "scriptfile should not exist 2."
if os.path.exists(default_script_file): # cleanup
os.remove(default_script_file)
rc.inputs.script = "a=1;"
assert not os.path.exists(default_script_file), "scriptfile should not exist 3."
with pytest.raises(IOError):
rc.run() # foo_m is not an executable
assert os.path.exists(default_script_file), "scriptfile should exist 3."
if os.path.exists(default_script_file): # cleanup
os.remove(default_script_file)
cwd.chdir()
@pytest.mark.skipif(no_r, reason="R is not available")
def test_set_rcmd(tmpdir):
cwd = tmpdir.chdir()
default_script_file = r.RInputSpec().script_file
ri = r.RCommand()
_default_r_cmd = ri._cmd
ri.set_default_r_cmd("foo")
assert not os.path.exists(default_script_file), "scriptfile should not exist."
assert ri._cmd == "foo"
ri.set_default_r_cmd(_default_r_cmd)
cwd.chdir()