Skip to content

Commit a064c03

Browse files
committed
Enhance index access tests for moving window
More tests for single element access of the moving window are added including tests that indicate bugs which should be fixed in follow-up commits. Signed-off-by: cwasicki <[email protected]>
1 parent bd7822c commit a064c03

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

tests/timeseries/test_moving_window.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,31 @@ def dt(i: int) -> datetime: # pylint: disable=invalid-name
8080

8181
async def test_access_window_by_index() -> None:
8282
"""Test indexing a window by integer index."""
83-
window, sender = init_moving_window(timedelta(seconds=1))
83+
window, sender = init_moving_window(timedelta(seconds=2))
8484
async with window:
85-
await push_logical_meter_data(sender, [1])
86-
assert np.array_equal(window[0], 1.0)
85+
await push_logical_meter_data(sender, [1, 2, 3])
86+
assert np.array_equal(window[0], 3.0) # bug: should be 2
87+
assert np.array_equal(window[1], 2.0) # bug: should be 3
88+
assert np.array_equal(window[-1], 2.0) # bug: should be 3
89+
assert np.array_equal(window[-2], 3.0) # bug: should be 2
90+
with pytest.raises(IndexError):
91+
_ = window[3]
92+
with pytest.raises(IndexError):
93+
_ = window[-3]
8794

8895

8996
async def test_access_window_by_timestamp() -> None:
9097
"""Test indexing a window by timestamp."""
91-
window, sender = init_moving_window(timedelta(seconds=1))
98+
window, sender = init_moving_window(timedelta(seconds=2))
9299
async with window:
93-
await push_logical_meter_data(sender, [1])
94-
assert np.array_equal(window[UNIX_EPOCH], 1.0)
100+
await push_logical_meter_data(sender, [0, 1, 2])
101+
assert np.array_equal(window[dt(1)], 1.0)
102+
assert np.array_equal(window[dt(2)], 2.0)
103+
assert np.array_equal(window[dt(3)], 1.0) # bug: should raise
104+
with pytest.raises(IndexError):
105+
_ = window[dt(0)]
106+
with pytest.raises(IndexError):
107+
_ = window[dt(4)]
95108

96109

97110
async def test_access_window_by_int_slice() -> None:

0 commit comments

Comments
 (0)