From f93ce11fa5b205982bd9de72e3c8875b0c362a6d Mon Sep 17 00:00:00 2001 From: Ioannis Filippidis Date: Sun, 9 May 2021 18:20:49 +0200 Subject: [PATCH] TST: assert that CUDD statistics interfaces issue `UserWarning` specifically the methods `dd.cudd.BDD.statistics` and `dd.cudd_zdd.BDD.statistics`. This `UserWarning` was introduced to inform the users about a recent API change. Moving the function `test_str` from the module `tests/common.py` to the modules `tests/autoref_test.py`, `tests/cudd_test.py`, and `tests/cudd_zdd_test.py`, with appropriate modification in each case, turned out to be the simplest way of implementing this check. The function `nose.tools.assert_warns` is used. In the upcoming commit that switches to using `pytest` for testing, the function [`pytest.warns`][1] will be used (read also ["Asserting warnings with the warns function"][2]). [1]: https://docs.pytest.org/en/latest/reference/reference.html#pytest-warns [2]: https://docs.pytest.org/en/latest/how-to/capture-warnings.html#warns --- tests/autoref_test.py | 6 ++++++ tests/common.py | 5 ----- tests/cudd_test.py | 9 ++++++++- tests/cudd_zdd_test.py | 8 ++++++++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/tests/autoref_test.py b/tests/autoref_test.py index 61321573..c5e26e19 100644 --- a/tests/autoref_test.py +++ b/tests/autoref_test.py @@ -16,6 +16,12 @@ BDDTests.DD = _bdd.BDD +def test_str(): + bdd = _bdd.BDD() + s = str(bdd) + s + 'must be a string' + + def test_find_or_add(): bdd = _bdd.BDD() bdd.declare('x', 'y') diff --git a/tests/common.py b/tests/common.py index 237e2ad9..d4efe018 100644 --- a/tests/common.py +++ b/tests/common.py @@ -83,11 +83,6 @@ def test_contains(self): with assert_raises(AssertionError): other_true in bdd - def test_str(self): - bdd = self.DD() - s = str(bdd) - s + 'must be a string' - def test_var_levels(self): bdd = self.DD() # single variable diff --git a/tests/cudd_test.py b/tests/cudd_test.py index a5f64d2b..afff20d2 100644 --- a/tests/cudd_test.py +++ b/tests/cudd_test.py @@ -2,7 +2,7 @@ import logging from dd import cudd -from nose.tools import assert_raises +from nose.tools import assert_raises, assert_warns from common import Tests from common_bdd import Tests as BDDTests @@ -18,6 +18,13 @@ CuddTests.MODULE = cudd +def test_str(): + bdd = cudd.BDD() + with assert_warns(UserWarning): + s = str(bdd) + s + 'must be a string' + + def test_insert_var(): bdd = cudd.BDD() level = 0 diff --git a/tests/cudd_zdd_test.py b/tests/cudd_zdd_test.py index 74f1fa5b..a90b683f 100644 --- a/tests/cudd_zdd_test.py +++ b/tests/cudd_zdd_test.py @@ -4,6 +4,7 @@ from dd import cudd from dd import cudd_zdd from dd import _copy +from nose.tools import assert_warns from common import Tests as Tests from common_cudd import Tests as CuddTests @@ -14,6 +15,13 @@ CuddTests.MODULE = cudd_zdd +def test_str(): + bdd = cudd_zdd.ZDD() + with assert_warns(UserWarning): + s = str(bdd) + s + 'must be a string' + + def test_false(): zdd = cudd_zdd.ZDD() u = zdd.false