Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unflake hypothesis tests #333

Merged
merged 1 commit into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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