14
14
mlab .MatlabCommand .set_default_matlab_cmd (matlab_cmd )
15
15
16
16
17
+ def clean_workspace_and_get_default_script_file ():
18
+ # Make sure things are clean.
19
+ default_script_file = mlab .MatlabInputSpec ().script_file
20
+ if os .path .exists (default_script_file ):
21
+ os .remove (default_script_file ) # raise Exception('Default script file needed for tests; please remove %s!' % default_script_file)
22
+ return default_script_file
23
+
17
24
@skipif (no_matlab )
18
25
def test_cmdline ():
19
- basedir = mkdtemp ()
26
+ default_script_file = clean_workspace_and_get_default_script_file ()
27
+
20
28
mi = mlab .MatlabCommand (script = 'whos' ,
21
29
script_file = 'testscript' , mfile = False )
22
30
@@ -31,25 +39,27 @@ def test_cmdline():
31
39
32
40
yield assert_equal , mi .inputs .script , 'whos'
33
41
yield assert_equal , mi .inputs .script_file , 'testscript'
34
- path_exists = os .path .exists (os .path .join (basedir , 'testscript.m' ))
35
- yield assert_false , path_exists
36
- rmtree (basedir )
42
+ yield assert_false , os .path .exists (mi .inputs .script_file ), 'scriptfile should not exist'
43
+ yield assert_false , os .path .exists (default_script_file ), 'default scriptfile should not exist.'
37
44
38
45
39
46
@skipif (no_matlab )
40
47
def test_mlab_inputspec ():
48
+ default_script_file = clean_workspace_and_get_default_script_file ()
41
49
spec = mlab .MatlabInputSpec ()
42
50
for k in ['paths' , 'script' , 'nosplash' , 'mfile' , 'logfile' , 'script_file' ,
43
51
'nodesktop' ]:
44
52
yield assert_true , k in spec .copyable_trait_names ()
45
53
yield assert_true , spec .nodesktop
46
54
yield assert_true , spec .nosplash
47
55
yield assert_true , spec .mfile
48
- yield assert_equal , spec .script_file , 'pyscript.m'
56
+ yield assert_equal , spec .script_file , default_script_file
49
57
50
58
51
59
@skipif (no_matlab )
52
60
def test_mlab_init ():
61
+ default_script_file = clean_workspace_and_get_default_script_file ()
62
+
53
63
yield assert_equal , mlab .MatlabCommand ._cmd , 'matlab'
54
64
yield assert_equal , mlab .MatlabCommand .input_spec , mlab .MatlabInputSpec
55
65
@@ -60,26 +70,48 @@ def test_mlab_init():
60
70
61
71
@skipif (no_matlab )
62
72
def test_run_interface ():
73
+ default_script_file = clean_workspace_and_get_default_script_file ()
74
+
63
75
mc = mlab .MatlabCommand (matlab_cmd = 'foo_m' )
76
+ yield assert_false , os .path .exists (default_script_file ), 'scriptfile should not exist 1.'
64
77
yield assert_raises , ValueError , mc .run # script is mandatory
78
+ yield assert_false , os .path .exists (default_script_file ), 'scriptfile should not exist 2.'
79
+ if os .path .exists (default_script_file ): # cleanup
80
+ os .remove (default_script_file )
81
+
65
82
mc .inputs .script = 'a=1;'
83
+ yield assert_false , os .path .exists (default_script_file ), 'scriptfile should not exist 3.'
66
84
yield assert_raises , IOError , mc .run # foo_m is not an executable
85
+ yield assert_true , os .path .exists (default_script_file ), 'scriptfile should exist 3.'
86
+ if os .path .exists (default_script_file ): # cleanup
87
+ os .remove (default_script_file )
88
+
67
89
cwd = os .getcwd ()
68
90
basedir = mkdtemp ()
69
91
os .chdir (basedir )
92
+
70
93
# bypasses ubuntu dash issue
71
94
mc = mlab .MatlabCommand (script = 'foo;' , paths = [basedir ], mfile = True )
95
+ yield assert_false , os .path .exists (default_script_file ), 'scriptfile should not exist 4.'
72
96
yield assert_raises , RuntimeError , mc .run
97
+ yield assert_true , os .path .exists (default_script_file ), 'scriptfile should exist 4.'
98
+ if os .path .exists (default_script_file ): # cleanup
99
+ os .remove (default_script_file )
100
+
73
101
# bypasses ubuntu dash issue
74
102
res = mlab .MatlabCommand (script = 'a=1;' , paths = [basedir ], mfile = True ).run ()
75
103
yield assert_equal , res .runtime .returncode , 0
104
+ yield assert_true , os .path .exists (default_script_file ), 'scriptfile should exist 5.'
76
105
os .chdir (cwd )
77
106
rmtree (basedir )
78
107
79
108
80
109
@skipif (no_matlab )
81
110
def test_set_matlabcmd ():
111
+ default_script_file = clean_workspace_and_get_default_script_file ()
112
+
82
113
mi = mlab .MatlabCommand ()
83
114
mi .set_default_matlab_cmd ('foo' )
115
+ yield assert_false , os .path .exists (default_script_file ), 'scriptfile should not exist.'
84
116
yield assert_equal , mi ._default_matlab_cmd , 'foo'
85
117
mi .set_default_matlab_cmd (matlab_cmd )
0 commit comments