Skip to content

Commit 3d9997e

Browse files
committed
Fix comparson of time.
You can't test rounded values for equalness, since they may fall each on a different side of 0.5. It is better to test their absolute difference for a certain tolerance, in this case 1.0 which is the intent of the original round.
1 parent 599515c commit 3d9997e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

tests/test_asyncio/test_timeseries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def test_add(modclient: redis.Redis):
7373
4, 4, 2, retention_msecs=10, labels={"Redis": "Labs", "Time": "Series"}
7474
)
7575
res = await modclient.ts().add(5, "*", 1)
76-
assert round(time.time()) == round(float(res) / 1000)
76+
assert abs(time.time() - round(float(res) / 1000)) < 1.0
7777

7878
info = await modclient.ts().info(4)
7979
assert 10 == info.retention_msecs

tests/test_timeseries.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ def test_add(client):
7070
assert 4 == client.ts().add(
7171
4, 4, 2, retention_msecs=10, labels={"Redis": "Labs", "Time": "Series"}
7272
)
73-
assert round(time.time()) == round(float(client.ts().add(5, "*", 1)) / 1000)
73+
74+
assert abs(time.time() - float(client.ts().add(5, "*", 1)) / 1000) < 1.0
7475

7576
info = client.ts().info(4)
7677
assert 10 == info.retention_msecs

0 commit comments

Comments
 (0)