Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/strategies.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import random | import random | ||||
from collections import defaultdict | from collections import defaultdict | ||||
from datetime import datetime | from datetime import datetime | ||||
from hypothesis import settings, assume | from hypothesis import settings, assume | ||||
from hypothesis.extra.dateutil import timezones | |||||
from hypothesis.strategies import ( | from hypothesis.strategies import ( | ||||
just, | just, | ||||
sampled_from, | sampled_from, | ||||
lists, | lists, | ||||
composite, | composite, | ||||
datetimes, | datetimes, | ||||
binary, | binary, | ||||
text, | text, | ||||
▲ Show 20 Lines • Show All 281 Lines • ▼ Show 20 Lines | |||||
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( | return lists( | ||||
datetimes( | datetimes( | ||||
min_value=datetime(2015, 1, 1, 0, 0), max_value=datetime(2018, 12, 31, 0, 0) | min_value=datetime(2015, 1, 1, 0, 0), | ||||
max_value=datetime(2018, 12, 31, 0, 0), | |||||
timezones=timezones(), | |||||
), | ), | ||||
min_size=min_size, | min_size=min_size, | ||||
max_size=max_size, | max_size=max_size, | ||||
unique=True, | unique=True, | ||||
).map(sorted) | ).map(sorted) | ||||
def release(): | def release(): | ||||
▲ Show 20 Lines • Show All 263 Lines • Show Last 20 Lines |