From 14eedd6ca38ab0950244119aa56629800d83137c Mon Sep 17 00:00:00 2001 From: Matthias Volk Date: Tue, 8 Aug 2017 15:47:53 +0200 Subject: [PATCH] Skip tests if submodules are not supported --- lib/stormpy/dft/__init__.py | 2 +- lib/stormpy/pars/__init__.py | 2 +- setup.py | 7 +++++-- tests/configurations.py | 10 ++++++++++ tests/dft/conftest.py | 4 ++++ tests/dft/test_build.py | 11 ++--------- tests/pars/conftest.py | 4 ++++ tests/pars/test_model_instantiator.py | 4 +++- tests/pars/test_parametric.py | 5 +++++ tests/pars/test_pla.py | 5 ++++- 10 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 tests/configurations.py create mode 100644 tests/dft/conftest.py create mode 100644 tests/pars/conftest.py diff --git a/lib/stormpy/dft/__init__.py b/lib/stormpy/dft/__init__.py index 0cd0541..9006444 100644 --- a/lib/stormpy/dft/__init__.py +++ b/lib/stormpy/dft/__init__.py @@ -1,6 +1,6 @@ from . import _config -if not _config.has_storm_dft: +if not _config.storm_with_dft: raise ImportError("No support for DFTs was built in Storm.") from . import dft diff --git a/lib/stormpy/pars/__init__.py b/lib/stormpy/pars/__init__.py index f178522..8ea02d4 100644 --- a/lib/stormpy/pars/__init__.py +++ b/lib/stormpy/pars/__init__.py @@ -1,6 +1,6 @@ from . import _config -if not _config.has_storm_pars: +if not _config.storm_with_pars: raise ImportError("No support for parametric analysis was built in Storm.") from . import pars diff --git a/setup.py b/setup.py index 72e2cb5..9a4f148 100755 --- a/setup.py +++ b/setup.py @@ -127,6 +127,9 @@ class CMakeBuild(build_ext): f.write("FactorizedPolynomial = pycarl.{}.FactorizedPolynomial\n".format(rfpackage)) f.write("RationalFunction = pycarl.{}.RationalFunction\n".format(rfpackage)) f.write("FactorizedRationalFunction = pycarl.{}.FactorizedRationalFunction\n".format(rfpackage)) + f.write("\n") + f.write("storm_with_pars = {}\n".format(self.conf.HAVE_STORM_PARS)) + f.write("storm_with_dft = {}\n".format(self.conf.HAVE_STORM_DFT)) elif ext.name == "info": with open(os.path.join(self.extdir(ext.name), ext.subdir, "_config.py"), "w") as f: @@ -137,14 +140,14 @@ class CMakeBuild(build_ext): elif ext.name == "pars": with open(os.path.join(self.extdir(ext.name), ext.subdir, "_config.py"), "w") as f: f.write("# Generated from setup.py at {}\n".format(datetime.datetime.now())) - f.write("has_storm_pars = {}".format(self.conf.HAVE_STORM_PARS)) + f.write("storm_with_pars = {}".format(self.conf.HAVE_STORM_PARS)) if not self.conf.HAVE_STORM_PARS: print("WARNING: storm-pars not found. No support for parametric analysis will be built.") continue elif ext.name == "dft": with open(os.path.join(self.extdir(ext.name), ext.subdir, "_config.py"), "w") as f: f.write("# Generated from setup.py at {}\n".format(datetime.datetime.now())) - f.write("has_storm_dft = {}".format(self.conf.HAVE_STORM_DFT)) + f.write("storm_with_dft = {}".format(self.conf.HAVE_STORM_DFT)) if not self.conf.HAVE_STORM_DFT: print("WARNING: storm-dft not found. No support for DFTs will be built.") continue diff --git a/tests/configurations.py b/tests/configurations.py new file mode 100644 index 0000000..6dc681f --- /dev/null +++ b/tests/configurations.py @@ -0,0 +1,10 @@ +import pytest + +import stormpy._config as config + +# Skip not supported functionality +has_dft = config.storm_with_dft +has_pars = config.storm_with_pars + +dft = pytest.mark.skipif(not has_dft, reason="No support for DFTs") +pars = pytest.mark.skipif(not has_pars, reason="No support for parametric model checking") diff --git a/tests/dft/conftest.py b/tests/dft/conftest.py new file mode 100644 index 0000000..cdbde3a --- /dev/null +++ b/tests/dft/conftest.py @@ -0,0 +1,4 @@ +from configurations import has_dft + +if has_dft: + import stormpy.dft diff --git a/tests/dft/test_build.py b/tests/dft/test_build.py index 338f0be..e09bc66 100644 --- a/tests/dft/test_build.py +++ b/tests/dft/test_build.py @@ -3,19 +3,12 @@ import stormpy.logic from helpers.helper import get_example_path import math +from configurations import dft +@dft class TestBuild: - def test_import(self): - import stormpy.dft - def test_build_dft(self): - try: - import stormpy.dft - except ImportError: - # No support for DFTs - return - model = stormpy.dft.build_sparse_model_from_json_dft(get_example_path("dft", "and.json")) formulas = stormpy.parse_properties("T=? [ F \"failed\" ]") assert model.nr_states == 4 diff --git a/tests/pars/conftest.py b/tests/pars/conftest.py new file mode 100644 index 0000000..81110b0 --- /dev/null +++ b/tests/pars/conftest.py @@ -0,0 +1,4 @@ +from configurations import has_pars + +if has_pars: + import stormpy.pars diff --git a/tests/pars/test_model_instantiator.py b/tests/pars/test_model_instantiator.py index 4ac38f5..cebc399 100644 --- a/tests/pars/test_model_instantiator.py +++ b/tests/pars/test_model_instantiator.py @@ -1,9 +1,11 @@ import stormpy import stormpy.logic -import stormpy.pars from helpers.helper import get_example_path +from configurations import pars + +@pars class TestModelInstantiator: def test_instantiate_dtmc(self): program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm")) diff --git a/tests/pars/test_parametric.py b/tests/pars/test_parametric.py index dd221ef..9b7a41d 100644 --- a/tests/pars/test_parametric.py +++ b/tests/pars/test_parametric.py @@ -3,8 +3,13 @@ import stormpy.info import stormpy.logic from helpers.helper import get_example_path +from configurations import pars + +@pars class TestParametric: + import stormpy.pars + def test_constraints_collector(self): from pycarl.formula import FormulaType, Relation if stormpy.info.storm_ratfunc_use_cln(): diff --git a/tests/pars/test_pla.py b/tests/pars/test_pla.py index 7f1a86e..4c3a255 100644 --- a/tests/pars/test_pla.py +++ b/tests/pars/test_pla.py @@ -1,11 +1,14 @@ import stormpy import stormpy.logic -import stormpy.pars from helpers.helper import get_example_path +from configurations import pars + +@pars class TestPLA: def test_pla(self): + import stormpy.pars program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm")) prop = "P<=0.84 [F s=5 ]" formulas = stormpy.parse_properties_for_prism_program(prop, program)