Skip to content

Commit

Permalink
TST: assert that CUDD statistics interfaces issue UserWarning
Browse files Browse the repository at this point in the history
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
  • Loading branch information
johnyf committed Jan 11, 2022
1 parent aceff98 commit f93ce11
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions tests/autoref_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 0 additions & 5 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion tests/cudd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/cudd_zdd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f93ce11

Please sign in to comment.