Changeset View
Changeset View
Standalone View
Standalone View
swh/model/hypothesis_strategies.py
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | def aware_datetimes(): | ||||
# <https://en.wikipedia.org/wiki/Time_zone#Worldwide_time_zones>), which is not | # <https://en.wikipedia.org/wiki/Time_zone#Worldwide_time_zones>), which is not | ||||
# encodable in ISO8601; and we need our datetimes to be ISO8601-encodable in the | # encodable in ISO8601; and we need our datetimes to be ISO8601-encodable in the | ||||
# RPC protocol | # RPC protocol | ||||
min_value = datetime.datetime(2000, 1, 1, 0, 0, 0) | min_value = datetime.datetime(2000, 1, 1, 0, 0, 0) | ||||
return datetimes(min_value=min_value, timezones=timezones()) | return datetimes(min_value=min_value, timezones=timezones()) | ||||
@composite | @composite | ||||
def urls(draw): | def iris(draw): | ||||
protocol = draw(sampled_from(["git", "http", "https", "deb"])) | protocol = draw(sampled_from(["git", "http", "https", "deb"])) | ||||
domain = draw(from_regex(r"\A([a-z]([a-z0-9-]*)\.){1,3}[a-z0-9]+\Z")) | domain = draw(from_regex(r"\A([a-z]([a-z0-9é🏛️-]*)\.){1,3}([a-z0-9é])+\Z")) | ||||
return "%s://%s" % (protocol, domain) | return "%s://%s" % (protocol, domain) | ||||
@composite | @composite | ||||
def persons_d(draw): | def persons_d(draw): | ||||
fullname = draw(binary()) | fullname = draw(binary()) | ||||
email = draw(optional(binary())) | email = draw(optional(binary())) | ||||
Show All 39 Lines | |||||
timestamps_with_timezone = timestamps_with_timezone_d().map( | timestamps_with_timezone = timestamps_with_timezone_d().map( | ||||
TimestampWithTimezone.from_dict | TimestampWithTimezone.from_dict | ||||
) | ) | ||||
def origins_d(): | def origins_d(): | ||||
return builds(dict, url=urls()) | return builds(dict, url=iris()) | ||||
def origins(): | def origins(): | ||||
return origins_d().map(Origin.from_dict) | return origins_d().map(Origin.from_dict) | ||||
def origin_visits_d(): | def origin_visits_d(): | ||||
return builds( | return builds( | ||||
dict, | dict, | ||||
visit=integers(1, 1000), | visit=integers(1, 1000), | ||||
origin=urls(), | origin=iris(), | ||||
date=aware_datetimes(), | date=aware_datetimes(), | ||||
type=pgsql_text(), | type=pgsql_text(), | ||||
) | ) | ||||
def origin_visits(): | def origin_visits(): | ||||
return origin_visits_d().map(OriginVisit.from_dict) | return origin_visits_d().map(OriginVisit.from_dict) | ||||
def metadata_dicts(): | def metadata_dicts(): | ||||
return dictionaries(pgsql_text(), pgsql_text()) | return dictionaries(pgsql_text(), pgsql_text()) | ||||
def origin_visit_statuses_d(): | def origin_visit_statuses_d(): | ||||
return builds( | return builds( | ||||
dict, | dict, | ||||
visit=integers(1, 1000), | visit=integers(1, 1000), | ||||
origin=urls(), | origin=iris(), | ||||
type=optional(sampled_from(["git", "svn", "pypi", "debian"])), | type=optional(sampled_from(["git", "svn", "pypi", "debian"])), | ||||
status=sampled_from( | status=sampled_from( | ||||
["created", "ongoing", "full", "partial", "not_found", "failed"] | ["created", "ongoing", "full", "partial", "not_found", "failed"] | ||||
), | ), | ||||
date=aware_datetimes(), | date=aware_datetimes(), | ||||
snapshot=optional(sha1_git()), | snapshot=optional(sha1_git()), | ||||
metadata=optional(metadata_dicts()), | metadata=optional(metadata_dicts()), | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 217 Lines • ▼ Show 20 Lines | |||||
def snapshots(*, min_size=0, max_size=100, only_objects=False): | def snapshots(*, min_size=0, max_size=100, only_objects=False): | ||||
return snapshots_d( | return snapshots_d( | ||||
min_size=min_size, max_size=max_size, only_objects=only_objects | min_size=min_size, max_size=max_size, only_objects=only_objects | ||||
).map(Snapshot.from_dict) | ).map(Snapshot.from_dict) | ||||
def metadata_authorities(): | def metadata_authorities(): | ||||
return builds(MetadataAuthority, url=urls(), metadata=just(None)) | return builds(MetadataAuthority, url=iris(), metadata=just(None)) | ||||
def metadata_fetchers(): | def metadata_fetchers(): | ||||
return builds( | return builds( | ||||
MetadataFetcher, | MetadataFetcher, | ||||
name=text(min_size=1, alphabet=string.printable), | name=text(min_size=1, alphabet=string.printable), | ||||
version=text( | version=text( | ||||
min_size=1, | min_size=1, | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |