Skip to content

Commit 2be89f7

Browse files
committed
Read to be merged. Added test_setup() and test_teardown() functions. Now for each test file only one Matlab session will be started.
1 parent 2ea0235 commit 2be89f7

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

pymatbridge/tests/test_array.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
import test_utils as tu
66

77
class TestArray:
8-
# Start a Matlab session
8+
9+
# Start a Matlab session before any tests
910
@classmethod
1011
def setup_class(cls):
1112
cls.mlab = tu.connect_to_matlab()
1213

13-
# Tear down the Matlab session
14+
# Tear down the Matlab session after all the tests are done
1415
@classmethod
1516
def teardown_class(cls):
1617
tu.stop_matlab(cls.mlab)
1718

19+
1820
# Pass a 50*50 array to Matlab
1921
def test_array_size(self):
2022
array = np.random.random_sample((50,50)).tolist()

pymatbridge/tests/test_json.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
class TestJson:
66

7-
# Start a Matlab session
7+
# Start a Matlab session before doing any tests
88
@classmethod
99
def setup_class(cls):
1010
cls.mlab = tu.connect_to_matlab()
1111

12-
# Tear down the Matlab session
12+
# Tear down the Matlab session after all the tests are done
1313
@classmethod
1414
def teardown_class(cls):
1515
tu.stop_matlab(cls.mlab)
@@ -22,7 +22,6 @@ def test_demo_func(self):
2222
ans = i + 1
2323
npt.assert_equal(res, ans, err_msg = "demo_func.m test failed")
2424

25-
2625
# Print some strange characters in Matlab, get them back and compare.
2726
def test_special_character(self):
2827

pymatbridge/tests/test_precision.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,56 @@
66

77

88
class TestPrecision:
9-
10-
# Start a Matlab session
9+
10+
# Start a Matlab session before running any tests
1111
@classmethod
1212
def setup_class(cls):
1313
cls.mlab = tu.connect_to_matlab()
14-
15-
# Tear down the Matlab session
14+
15+
# Tear down the Matlab session after running all the tests
1616
@classmethod
1717
def teardown_class(cls):
1818
tu.stop_matlab(cls.mlab)
19-
20-
19+
20+
2121
# Pass a 64-bit floating number through the signal path
2222
def test_float64_roundtrip(self):
2323
for i in range(0,10):
2424
val = np.float64(rd.random())
2525
res = self.mlab.run_func('precision_pass.m', {'val':val})['result']
2626
npt.assert_almost_equal(res, val, decimal=8, err_msg="Float64 roundtrip error")
27-
28-
27+
2928
# Add two 64-bit floating number in Matlab and return the sum
3029
def test_float64_sum(self):
3130
for i in range(0,10):
3231
val1 = np.float64(rd.random())
3332
val2 = np.float64(rd.random())
34-
33+
3534
res = self.mlab.run_func('precision_sum.m', {'val1':val1, 'val2':val2})['result']
3635
npt.assert_almost_equal(res, val1 + val2, decimal=8, err_msg="Float64 sum error")
37-
38-
36+
3937
# Multiply two 64-bit floating number in Matlab and return the product
4038
def test_float64_multiply(self):
4139
for i in range(0,10):
4240
val1 = np.float64(rd.random())
4341
val2 = np.float64(rd.random())
44-
42+
4543
res = self.mlab.run_func('precision_multiply.m', {'val1':val1, 'val2':val2})['result']
4644
npt.assert_almost_equal(res, val1 * val2, decimal=8, err_msg="Float64 multiply error")
47-
48-
45+
4946
# Make a division in Matlab and return the results
5047
def test_float64_divide(self):
5148
for i in range(0,10):
5249
val1 = np.float64(rd.random())
5350
val2 = np.float64(rd.random())
54-
51+
5552
res = self.mlab.run_func('precision_divide.m', {'val1':val1, 'val2':val2})['result']
5653
npt.assert_almost_equal(res, val1 / val2, decimal=8, err_msg="Float64 divide error")
57-
58-
54+
5955
# Calculate the square root in Matlab and return the result
6056
def test_float64_sqrt(self):
6157
for i in range(0,10):
6258
val = np.float64(rd.random())
63-
59+
6460
res = self.mlab.run_func('precision_sqrt.m', {'val':val})['result']
6561
npt.assert_almost_equal(res, np.sqrt(val), decimal=8, err_msg="Float64 square root error")

0 commit comments

Comments
 (0)