Skip to content

Commit b6c7cf1

Browse files
committed
Added tests for "get_variable()" funtion
1 parent c5e61e9 commit b6c7cf1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import pymatbridge as pymat
2+
import numpy.testing as npt
3+
import test_utils as tu
4+
5+
6+
class TestGetVariable:
7+
8+
# Start a Matlab session before running any tests
9+
@classmethod
10+
def setup_class(cls):
11+
cls.mlab = tu.connect_to_matlab()
12+
13+
# Tear down the Matlab session after running all the tests
14+
@classmethod
15+
def teardown_class(cls):
16+
tu.stop_matlab(cls.mlab)
17+
18+
19+
# Set up a floating point and get it
20+
def test_get_float(self):
21+
self.mlab.run_code("a = 456345.345345")
22+
self.mlab.run_code("b = 0.39748e3")
23+
24+
npt.assert_equal(self.mlab.get_variable('a'), unicode("456345.3453"))
25+
npt.assert_equal(self.mlab.get_variable('b'), unicode("397.48"))
26+
27+
28+
# Get some arrays
29+
def test_get_array(self):
30+
self.mlab.run_code("a = [1 2 3 4]")
31+
self.mlab.run_code("b = [1 2; 3 4]")
32+
33+
npt.assert_equal(self.mlab.get_variable('a'), unicode("[1,2,3,4]"))
34+
npt.assert_equal(self.mlab.get_variable('b'), unicode("[[1,2],[3,4]]"))
35+
36+
37+
# Try to get a non-existent variable
38+
# This one will always fail now since the matlab function cannot handle this situation
39+
# def test_nonexistent_var(self):
40+
# self.mlab.run_code("clear")
41+
42+
# npt.assert_equal(self.mlab.get_variable('a'), unicode("456345.3453"))

0 commit comments

Comments
 (0)