Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/strategies.py
Show First 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | def new_origin(): | ||||
""" | """ | ||||
Hypothesis strategy returning a random origin not ingested | Hypothesis strategy returning a random origin not ingested | ||||
into the test archive. | into the test archive. | ||||
""" | """ | ||||
return new_origin_strategy().filter( | return new_origin_strategy().filter( | ||||
lambda origin: storage.origin_get(origin) is None) | lambda origin: storage.origin_get(origin) is None) | ||||
def new_origins(nb_origins=None): | |||||
""" | |||||
Hypothesis strategy returning random origins not ingested | |||||
into the test archive. | |||||
""" | |||||
min_size = nb_origins if nb_origins is not None else 2 | |||||
vlorentz: You might want to check for `None`ness, `nb_origins` might be zero on purpose (eg. when… | |||||
max_size = nb_origins if nb_origins is not None else 8 | |||||
size = random.randint(min_size, max_size) | |||||
return lists(new_origin(), min_size=size, max_size=size, | |||||
Not Done Inline Actionsunique_by=lambda o: tuple(sorted(o.items())) vlorentz: `unique_by=lambda o: tuple(sorted(o.items()))` | |||||
unique_by=lambda o: tuple(sorted(o.items()))) | |||||
def visit_dates(nb_dates=None): | def visit_dates(nb_dates=None): | ||||
""" | """ | ||||
Hypothesis strategy returning a list of visit dates. | Hypothesis strategy returning a list of visit dates. | ||||
""" | """ | ||||
min_size = nb_dates if nb_dates else 2 | min_size = nb_dates if nb_dates else 2 | ||||
max_size = nb_dates if nb_dates else 8 | max_size = nb_dates if nb_dates else 8 | ||||
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)), | ||||
▲ Show 20 Lines • Show All 259 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).