Skip to content

Commit

Permalink
Unflake hypothesis tests
Browse files Browse the repository at this point in the history
Restrict hypothesis strategies generating interaction types and molecule names from using characters in the unicode classes Z (separators) and C (control characters).
  • Loading branch information
pckroon committed Feb 3, 2021
1 parent 6ccc2d2 commit 52ba5ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion vermouth/tests/molecule_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@

# pylint: disable=no-value-for-parameter

# This is a strategy that creates "sane" names. It's currently used to generate
# interaction type names, and molecule names. The produced strings will not
# contain characters from the unicode categories C and Z, which contain
# control characters and separators, respectively.
SANE_NAME_STRATEGY = st.text(st.characters(blacklist_categories=('C', 'Z')), min_size=1)


@st.composite
def attribute_dict(draw, min_size=0, max_size=None, max_depth=1):
"""
Expand Down Expand Up @@ -148,7 +155,7 @@ def interaction_collection(draw, graph,
ninteraction_types = draw(st.integers(min_value=0, max_value=2))
for _ in range(ninteraction_types):
ninteractions = draw(st.integers(min_value=0, max_value=2))
type_name = draw(st.text())
type_name = draw(SANE_NAME_STRATEGY)
if type_name not in result:
result[type_name] = []
for _ in range(ninteractions):
Expand Down
11 changes: 9 additions & 2 deletions vermouth/tests/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import vermouth.forcefield
from vermouth.molecule import Interaction, Molecule

from .molecule_strategies import random_molecule, random_block, random_link
from .molecule_strategies import (random_molecule, random_block, random_link,
SANE_NAME_STRATEGY,)

# pylint: disable=redefined-outer-name, no-value-for-parameter

Expand Down Expand Up @@ -1229,7 +1230,13 @@ def test_interaction_sort(interactions, expected):
assert vermouth.molecule.Molecule.sort_interactions(interactions) == expected


@hypothesis.given(moltype=st.one_of(st.none(), st.text()), mol=random_molecule())
@hypothesis.given(
moltype=st.one_of(
st.none(),
SANE_NAME_STRATEGY,
),
mol=random_molecule()
)
def test_str_method(mol, moltype):
"""
Test Molecule.__str__
Expand Down

0 comments on commit 52ba5ad

Please sign in to comment.