Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dist
venv*
.*cache
coverage_html
.hypothesis
47 changes: 46 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pylint = "^2.4.4"
black = "^22.1.0"
ruff = "^0.0.254"
pyupgrade = "^3.3.1"
hypothesis = "^6.75.2"

[tool.ruff]
ignore = ["E402", "E501"]
Expand Down
27 changes: 27 additions & 0 deletions tests/test_transforms_hypot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Tests of aw-core transforms using hypothesis
"""

from datetime import datetime, timedelta

from aw_core.models import Event
from hypothesis import assume, given

Check notice

Code scanning / CodeQL

Unused import

Import of 'assume' is not used.
from hypothesis import strategies as st


@st.composite
def events(draw, min_start=datetime.min):
start = draw(st.datetimes(min_value=min_start, timezones=st.timezones()))
duration = draw(st.timedeltas(min_value=timedelta(seconds=0)))
title = draw(st.text())

return Event(timestamp=start, duration=duration, data={"title": title})


@given(eventlist=st.lists(events(), min_size=1))
def test_sum_durations(eventlist):
from aw_transform import sum_durations

assert sum_durations(eventlist) == sum(
[e.duration for e in eventlist], timedelta(seconds=0)
)