Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/strategies.py
Show All 21 Lines | |||||
from swh.web.tests.data import get_tests_data | from swh.web.tests.data import get_tests_data | ||||
# Module dedicated to the generation of input data for tests through | # Module dedicated to the generation of input data for tests through | ||||
# the use of hypothesis. | # the use of hypothesis. | ||||
# Some of these data are sampled from a test archive created and populated | # Some of these data are sampled from a test archive created and populated | ||||
# in the swh.web.tests.data module. | # in the swh.web.tests.data module. | ||||
# Set some hypothesis settings | # Set some hypothesis settings | ||||
settings.register_profile("swh-web", settings(deadline=None, max_examples=1)) | settings.register_profile('swh-web', settings(deadline=None, max_examples=1)) | ||||
settings.load_profile("swh-web") | settings.load_profile('swh-web') | ||||
def set_hypothesis_settings(**kwargs): | |||||
""" | |||||
Utility function to dynamically override some hypothesis | |||||
settings (for instance the max_examples value) during | |||||
tests execution. | |||||
""" | |||||
previous_settings = settings.get_profile('swh-web') | |||||
settings.register_profile('swh-web', | |||||
settings(previous_settings, **kwargs)) | |||||
settings.load_profile('swh-web') | |||||
# The following strategies exploit the hypothesis capabilities | # The following strategies exploit the hypothesis capabilities | ||||
def _known_swh_object(object_type): | def _known_swh_object(object_type): | ||||
tests_data = get_tests_data() | tests_data = get_tests_data() | ||||
return sampled_from(tests_data[object_type]) | return sampled_from(tests_data[object_type]) | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | def origin(): | ||||
""" | """ | ||||
return _known_swh_object('origins') | return _known_swh_object('origins') | ||||
def visit_dates(): | def visit_dates(): | ||||
""" | """ | ||||
Hypothesis strategy returning a list of visit dates. | Hypothesis strategy returning a list of visit dates. | ||||
""" | """ | ||||
return lists(datetimes(min_value=datetime(2015, 1, 1, 0, 0), | return lists(datetimes(min_value=datetime(2015, 1, 1, 0, 0), | ||||
max_value=datetime(2018, 12, 31, 0, 0)), | max_value=datetime(2018, 12, 31, 0, 0)), | ||||
vlorentz: You might want to check for `None`ness, `nb_origins` might be zero on purpose (eg. when… | |||||
min_size=2, max_size=8, unique=True) | min_size=2, max_size=8, unique=True) | ||||
Not Done Inline Actionsunique_by=lambda o: tuple(sorted(o.items())) vlorentz: `unique_by=lambda o: tuple(sorted(o.items()))` | |||||
def release(): | def release(): | ||||
""" | """ | ||||
Hypothesis strategy returning a random release ingested | Hypothesis strategy returning a random release ingested | ||||
into the test archive. | into the test archive. | ||||
""" | """ | ||||
return _known_swh_object('releases') | return _known_swh_object('releases') | ||||
▲ Show 20 Lines • Show All 189 Lines • Show Last 20 Lines |
You might want to check for Noneness, nb_origins might be zero on purpose (eg. when combined with other strategies that vary that parameter).