Skip to content

Commit 79c373f

Browse files
Add test for gap update code in fix_ringbuffer
Adds a test case for updating the start time of gaps when it's older than the oldest stored element in the buffer. Signed-off-by: Matthias Wende <[email protected]>
1 parent 8bc19bc commit 79c373f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/timeseries/test_ringbuffer.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,24 @@ def test_off_by_one_gap_logic_bug() -> None:
369369

370370
assert buffer.is_missing(times[0]) is False
371371
assert buffer.is_missing(times[1]) is False
372+
373+
374+
def test_cleanup_oldest_gap_timestamp() -> None:
375+
"""Test that gaps are updated such that they are fully contained in the buffer."""
376+
buffer = OrderedRingBuffer(
377+
np.empty(shape=15, dtype=float),
378+
sampling_period=timedelta(seconds=1),
379+
align_to=datetime(1, 1, 1, tzinfo=timezone.utc),
380+
)
381+
382+
for i in range(10):
383+
buffer.update(
384+
Sample(datetime.fromtimestamp(200 + i, tz=timezone.utc), Quantity(i))
385+
)
386+
387+
gap = Gap(
388+
datetime.fromtimestamp(195, tz=timezone.utc),
389+
datetime.fromtimestamp(200, tz=timezone.utc),
390+
)
391+
392+
assert gap == buffer.gaps[0]

0 commit comments

Comments
 (0)