Skip to content

Commit 9e225a5

Browse files
committed
Add rounding to delicate timeseries test
1 parent ab14af5 commit 9e225a5

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

tests/test_asyncio/test_timeseries.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ async def test_range(modclient: redis.Redis):
217217
assert 10 == len(await modclient.ts().range(1, 0, 500, count=10))
218218

219219

220+
def round_reply(tuples, digits=3):
221+
"""
222+
Round the timeseries reply since we are not testing for minute differences
223+
in server implementation precision
224+
"""
225+
return [(a, round(b, digits)) for (a, b) in tuples]
226+
227+
220228
@pytest.mark.redismod
221229
@skip_ifmodversion_lt("99.99.99", "timeseries")
222230
async def test_range_advanced(modclient: redis.Redis):
@@ -240,8 +248,10 @@ async def test_range_advanced(modclient: redis.Redis):
240248
assert [(0, 5.0), (5, 6.0)] == await modclient.ts().range(
241249
1, 0, 10, aggregation_type="count", bucket_size_msec=10, align=5
242250
)
243-
assert [(0, 2.5500000000000003), (10, 3.0)] == await modclient.ts().range(
244-
1, 0, 10, aggregation_type="twa", bucket_size_msec=10
251+
assert [(0, 2.55), (10, 3.0)] == round_reply(
252+
await modclient.ts().range(
253+
1, 0, 10, aggregation_type="twa", bucket_size_msec=10
254+
)
245255
)
246256

247257

tests/test_timeseries.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ def test_range(client):
210210
assert 10 == len(client.ts().range(1, 0, 500, count=10))
211211

212212

213+
def round_reply(tuples, digits=3):
214+
"""
215+
Round the timeseries reply since we are not testing for minute differences
216+
in server implementation precision
217+
"""
218+
return [(a, round(b, digits)) for (a, b) in tuples]
219+
220+
213221
@pytest.mark.redismod
214222
@skip_ifmodversion_lt("99.99.99", "timeseries")
215223
def test_range_advanced(client):
@@ -233,8 +241,8 @@ def test_range_advanced(client):
233241
assert [(0, 5.0), (5, 6.0)] == client.ts().range(
234242
1, 0, 10, aggregation_type="count", bucket_size_msec=10, align=5
235243
)
236-
assert [(0, 2.5500000000000003), (10, 3.0)] == client.ts().range(
237-
1, 0, 10, aggregation_type="twa", bucket_size_msec=10
244+
assert [(0, 2.55), (10, 3.0)] == round_reply(
245+
client.ts().range(1, 0, 10, aggregation_type="twa", bucket_size_msec=10)
238246
)
239247

240248

@@ -343,8 +351,8 @@ def test_rev_range(client):
343351
assert [(1, 10.0), (0, 1.0)] == client.ts().revrange(
344352
1, 0, 10, aggregation_type="count", bucket_size_msec=10, align=1
345353
)
346-
assert [(10, 3.0), (0, 2.5500000000000003)] == client.ts().revrange(
347-
1, 0, 10, aggregation_type="twa", bucket_size_msec=10
354+
assert [(10, 3.0), (0, 2.55)] == round_reply(
355+
client.ts().revrange(1, 0, 10, aggregation_type="twa", bucket_size_msec=10)
348356
)
349357

350358

0 commit comments

Comments
 (0)