88
99no_r = r .no_r
1010
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-
2211@pytest .mark .skipif (no_r , reason = "R is not available" )
2312def 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 ()
2516
2617 assert ri .cmdline == r_cmd + (
2718 ' -e "1 + 1"'
2819 )
2920
3021 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
3223 assert not os .path .exists (ri .inputs .script_file ), "scriptfile should not exist"
3324 assert not os .path .exists (
3425 default_script_file
3526 ), "default scriptfile should not exist."
3627
3728
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-
5029@pytest .mark .skipif (no_r , reason = "R is not available" )
5130def 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
5333
5434 rc = r .RCommand (r_cmd = "foo_m" )
5535 assert not os .path .exists (default_script_file ), "scriptfile should not exist 1."
@@ -67,31 +47,16 @@ def test_run_interface(tmpdir):
6747 if os .path .exists (default_script_file ): # cleanup
6848 os .remove (default_script_file )
6949
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 ()
8650
8751
8852@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
9156
9257 ri = r .RCommand ()
93- _default_r_cmd = ri ._default_r_cmd
58+ _default_r_cmd = ri ._cmd
9459 ri .set_default_r_cmd ("foo" )
9560 assert not os .path .exists (default_script_file ), "scriptfile should not exist."
96- assert ri ._default_r_cmd == "foo"
61+ assert ri ._cmd == "foo"
9762 ri .set_default_r_cmd (_default_r_cmd )
0 commit comments