Skip to content
Open
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
4 changes: 2 additions & 2 deletions aw_query/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ def q2_union_no_overlap(events1: list, events2: list) -> List[Event]:

@q2_function(flood)
@q2_typecheck
def q2_flood(events: list) -> List[Event]:
return flood(events)
def q2_flood(events: list, pulsetime: float = 5) -> List[Event]:
return flood(events, pulsetime)


"""
Expand Down
21 changes: 21 additions & 0 deletions tests/test_flood.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,24 @@ def test_flood_negative_small_gap_differing_data():
flooded = flood(events)
duration = sum((e.duration for e in flooded), timedelta(0))
assert duration == timedelta(seconds=100 + 99.99)


def test_flood_with_custom_pulsetime():
"""Test that flood respects custom pulsetime parameter"""
# Create events with 30s gap (simulating 30s poll_time)
events = [
Event(timestamp=now, duration=5, data={"a": 0}),
Event(timestamp=now + 35 * td1s, duration=5, data={"b": 1}),
]

# With default pulsetime=5, gap should NOT be flooded
flooded_default = flood(events)
assert len(flooded_default) == 2
total_duration_default = sum((e.duration for e in flooded_default), timedelta(0))
assert total_duration_default == timedelta(seconds=10)

# With pulsetime=31 (matching 30s poll_time + 1), gap should be flooded
flooded_custom = flood(events, pulsetime=31)
assert len(flooded_custom) == 2
total_duration_custom = sum((e.duration for e in flooded_custom), timedelta(0))
assert total_duration_custom == timedelta(seconds=40) # Full duration with gap filled
Comment on lines +83 to +101
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test covers flood() directly, not q2_flood through the query2 layer

The new test validates the underlying flood() function with pulsetime, but it doesn't verify that the parameter is correctly forwarded through the q2_flood wrapper and its decorator chain (q2_function + q2_typecheck). Since q2_function manipulates *args by stripping datastore/namespace arguments positionally, a positional-index shift bug in the decorator could cause pulsetime to be silently ignored without this test catching it. There are no existing q2_flood tests in test_query2.py to compensate.

Loading