Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7163733
D3082.id10976.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D3082.id10976.diff
View Options
diff --git a/swh/model/hypothesis_strategies.py b/swh/model/hypothesis_strategies.py
--- a/swh/model/hypothesis_strategies.py
+++ b/swh/model/hypothesis_strategies.py
@@ -6,6 +6,7 @@
import datetime
from hypothesis import assume
+from hypothesis.extra.dateutil import timezones
from hypothesis.strategies import (
binary,
booleans,
@@ -70,6 +71,10 @@
return binary(min_size=20, max_size=20)
+def aware_datetimes():
+ return datetimes(timezones=timezones())
+
+
@composite
def urls(draw):
protocol = draw(sampled_from(["git", "http", "https", "deb"]))
@@ -138,7 +143,7 @@
dict,
visit=integers(0, 1000),
origin=urls(),
- date=datetimes(),
+ date=aware_datetimes(),
status=sampled_from(["ongoing", "full", "partial"]),
type=pgsql_text(),
snapshot=optional(sha1_git()),
@@ -159,7 +164,7 @@
visit=integers(0, 1000),
origin=urls(),
status=sampled_from(["ongoing", "full", "partial"]),
- date=datetimes(),
+ date=aware_datetimes(),
snapshot=optional(sha1_git()),
metadata=one_of(none(), metadata_dicts()),
)
@@ -268,7 +273,7 @@
return builds(
dict,
data=binary(max_size=4096),
- ctime=optional(datetimes()),
+ ctime=optional(aware_datetimes()),
status=one_of(just("visible"), just("hidden")),
)
@@ -288,7 +293,7 @@
result[k] = None
result["reason"] = draw(pgsql_text())
result["status"] = "absent"
- result["ctime"] = draw(optional(datetimes()))
+ result["ctime"] = draw(optional(aware_datetimes()))
return result
diff --git a/swh/model/tests/test_hypothesis_strategies.py b/swh/model/tests/test_hypothesis_strategies.py
--- a/swh/model/tests/test_hypothesis_strategies.py
+++ b/swh/model/tests/test_hypothesis_strategies.py
@@ -9,7 +9,14 @@
from hypothesis import given, settings
from swh.model.hashutil import DEFAULT_ALGORITHMS
-from swh.model.hypothesis_strategies import objects, object_dicts, snapshots
+from swh.model.hypothesis_strategies import (
+ objects,
+ object_dicts,
+ contents,
+ skipped_contents,
+ snapshots,
+ origin_visits,
+)
from swh.model.model import TargetType
@@ -125,6 +132,16 @@
assert branch is None or branch["target_type"] in target_types
+@given(contents())
+def test_content_aware_datetime(cont):
+ assert cont.ctime is None or cont.ctime.tzinfo is not None
+
+
+@given(skipped_contents())
+def test_skipped_content_aware_datetime(cont):
+ assert cont.ctime is None or cont.ctime.tzinfo is not None
+
+
_min_snp_size = 10
_max_snp_size = 100
@@ -164,3 +181,8 @@
@settings(max_examples=1)
def test_snapshots_strategy_fixed_size(snapshot):
assert len(snapshot.branches) == _min_snp_size
+
+
+@given(origin_visits())
+def test_origin_visit_aware_datetime(visit):
+ assert visit.date.tzinfo is not None
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 30, 2:12 PM (1 w, 15 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3223309
Attached To
D3082: hypothesis_strategies: Generate aware datetimes instead of naive ones.
Event Timeline
Log In to Comment