Browse Source

Skip tests if numpy is not available

refactoring
Matthias Volk 5 years ago
parent
commit
105d9c40b5
  1. 9
      tests/configurations.py
  2. 11
      tests/storage/test_matrix_builder.py

9
tests/configurations.py

@ -7,6 +7,15 @@ has_dft = config.storm_with_dft
has_gspn = config.storm_with_gspn has_gspn = config.storm_with_gspn
has_pars = config.storm_with_pars has_pars = config.storm_with_pars
# Check if numpy is available
try:
import numpy
has_numpy = True
except ImportError:
has_numpy = False
dft = pytest.mark.skipif(not has_dft, reason="No support for DFTs") dft = pytest.mark.skipif(not has_dft, reason="No support for DFTs")
gspn = pytest.mark.skipif(not has_gspn, reason="No support for GSPNs") gspn = pytest.mark.skipif(not has_gspn, reason="No support for GSPNs")
pars = pytest.mark.skipif(not has_pars, reason="No support for parametric model checking") pars = pytest.mark.skipif(not has_pars, reason="No support for parametric model checking")
numpy_avail = pytest.mark.skipif(not has_numpy, reason="Numpy not available")

11
tests/storage/test_matrix_builder.py

@ -1,5 +1,6 @@
import stormpy import stormpy
import numpy as np
from configurations import numpy_avail
class TestMatrixBuilder: class TestMatrixBuilder:
@ -166,7 +167,9 @@ class TestMatrixBuilder:
assert matrix.get_row_group_start(1) == 4 assert matrix.get_row_group_start(1) == 4
assert matrix.get_row_group_end(1) == 5 assert matrix.get_row_group_end(1) == 5
@numpy_avail
def test_matrix_from_numpy(self): def test_matrix_from_numpy(self):
import numpy as np
array = np.array([[0, 2], array = np.array([[0, 2],
[3, 4], [3, 4],
[0.1, 24], [0.1, 24],
@ -185,7 +188,9 @@ class TestMatrixBuilder:
for e in row: for e in row:
assert (e.value() == array[r, e.column]) assert (e.value() == array[r, e.column])
@numpy_avail
def test_parametric_matrix_from_numpy(self): def test_parametric_matrix_from_numpy(self):
import numpy as np
one_pol = stormpy.RationalRF(1) one_pol = stormpy.RationalRF(1)
one_pol = stormpy.FactorizedPolynomial(one_pol) one_pol = stormpy.FactorizedPolynomial(one_pol)
first_val = stormpy.FactorizedRationalFunction(one_pol, one_pol) first_val = stormpy.FactorizedRationalFunction(one_pol, one_pol)
@ -212,7 +217,9 @@ class TestMatrixBuilder:
for e in row: for e in row:
assert (e.value() == array[r, e.column]) assert (e.value() == array[r, e.column])
@numpy_avail
def test_matrix_from_numpy_row_grouping(self): def test_matrix_from_numpy_row_grouping(self):
import numpy as np
array = np.array([[0, 2], array = np.array([[0, 2],
[3, 4], [3, 4],
[0.1, 24], [0.1, 24],
@ -238,7 +245,9 @@ class TestMatrixBuilder:
assert matrix.get_row_group_start(1) == 3 assert matrix.get_row_group_start(1) == 3
assert matrix.get_row_group_end(1) == 4 assert matrix.get_row_group_end(1) == 4
@numpy_avail
def test_parametric_matrix_from_numpy_row_grouping(self): def test_parametric_matrix_from_numpy_row_grouping(self):
import numpy as np
one_pol = stormpy.RationalRF(1) one_pol = stormpy.RationalRF(1)
one_pol = stormpy.FactorizedPolynomial(one_pol) one_pol = stormpy.FactorizedPolynomial(one_pol)
first_val = stormpy.FactorizedRationalFunction(one_pol, one_pol) first_val = stormpy.FactorizedRationalFunction(one_pol, one_pol)

Loading…
Cancel
Save