8
8
9
9
no_r = r .no_r
10
10
11
-
12
- def clean_workspace_and_get_default_script_file ():
13
- # Make sure things are clean.
14
- default_script_file = r .RInputSpec ().script_file
15
- if os .path .exists (default_script_file ):
16
- os .remove (
17
- default_script_file
18
- ) # raise Exception('Default script file needed for tests; please remove %s!' % default_script_file)
19
- return default_script_file
20
-
21
-
22
11
@pytest .mark .skipif (no_r , reason = "R is not available" )
23
12
def test_cmdline (tmp_path ):
24
- ri = r .RCommand (script = "1 + 1" , script_file = str (tmp_path / "testscript" ), rfile = False )
13
+ default_script_file = str (tmp_path / "testscript" )
14
+ ri = r .RCommand (script = "1 + 1" , script_file = default_script_file , rfile = False )
15
+ r_cmd = r .get_r_command ()
25
16
26
17
assert ri .cmdline == r_cmd + (
27
18
' -e "1 + 1"'
28
19
)
29
20
30
21
assert ri .inputs .script == "1 + 1"
31
- assert ri .inputs .script_file == str ( tmp_path / "testscript" )
22
+ assert ri .inputs .script_file == default_script_file
32
23
assert not os .path .exists (ri .inputs .script_file ), "scriptfile should not exist"
33
24
assert not os .path .exists (
34
25
default_script_file
35
26
), "default scriptfile should not exist."
36
27
37
28
38
- @pytest .mark .skipif (no_r , reason = "R is not available" )
39
- def test_r_init ():
40
- default_script_file = clean_workspace_and_get_default_script_file ()
41
-
42
- assert r .RCommand ._cmd == r .get_r_command ()
43
- assert r .RCommand .input_spec == r .RInputSpec
44
-
45
- assert r .RCommand ().cmd == r_cmd
46
- rc = r .RCommand (r_cmd = "foo_m" )
47
- assert rc .cmd == "foo_m"
48
-
49
-
50
29
@pytest .mark .skipif (no_r , reason = "R is not available" )
51
30
def test_run_interface (tmpdir ):
52
- default_script_file = clean_workspace_and_get_default_script_file ()
31
+ os .chdir (tmpdir )
32
+ default_script_file = r .RInputSpec ().script_file
53
33
54
34
rc = r .RCommand (r_cmd = "foo_m" )
55
35
assert not os .path .exists (default_script_file ), "scriptfile should not exist 1."
@@ -67,31 +47,16 @@ def test_run_interface(tmpdir):
67
47
if os .path .exists (default_script_file ): # cleanup
68
48
os .remove (default_script_file )
69
49
70
- cwd = tmpdir .chdir ()
71
-
72
- # bypasses ubuntu dash issue
73
- rc = r .RCommand (script = "foo;" , rfile = True )
74
- assert not os .path .exists (default_script_file ), "scriptfile should not exist 4."
75
- with pytest .raises (RuntimeError ):
76
- rc .run ()
77
- assert os .path .exists (default_script_file ), "scriptfile should exist 4."
78
- if os .path .exists (default_script_file ): # cleanup
79
- os .remove (default_script_file )
80
-
81
- # bypasses ubuntu dash issue
82
- res = r .RCommand (script = "a=1;" , rfile = True ).run ()
83
- assert res .runtime .returncode == 0
84
- assert os .path .exists (default_script_file ), "scriptfile should exist 5."
85
- cwd .chdir ()
86
50
87
51
88
52
@pytest .mark .skipif (no_r , reason = "R is not available" )
89
- def test_set_rcmd ():
90
- default_script_file = clean_workspace_and_get_default_script_file ()
53
+ def test_set_rcmd (tmpdir ):
54
+ os .chdir (tmpdir )
55
+ default_script_file = r .RInputSpec ().script_file
91
56
92
57
ri = r .RCommand ()
93
- _default_r_cmd = ri ._default_r_cmd
58
+ _default_r_cmd = ri ._cmd
94
59
ri .set_default_r_cmd ("foo" )
95
60
assert not os .path .exists (default_script_file ), "scriptfile should not exist."
96
- assert ri ._default_r_cmd == "foo"
61
+ assert ri ._cmd == "foo"
97
62
ri .set_default_r_cmd (_default_r_cmd )
0 commit comments