55import asyncio
66import binascii
77import datetime
8+ import math
89import re
910import sys
1011from string import ascii_letters
1314import pytest_asyncio
1415import valkey
1516from tests .conftest import (
17+ assert_geo_is_close ,
1618 assert_resp_response ,
1719 assert_resp_response_in ,
20+ assert_resp_response_isclose ,
1821 is_resp2_connection ,
1922 skip_if_server_version_gte ,
2023 skip_if_server_version_lt ,
@@ -2459,7 +2462,7 @@ async def test_geopos(self, r: valkey.Valkey):
24592462
24602463 await r .geoadd ("barcelona" , values )
24612464 # valkey uses 52 bits precision, hereby small errors may be introduced.
2462- assert_resp_response (
2465+ assert_resp_response_isclose (
24632466 r ,
24642467 await r .geopos ("barcelona" , "place1" , "place2" ),
24652468 [
@@ -2519,7 +2522,30 @@ async def test_georadius_units(self, r: valkey.Valkey):
25192522
25202523 @skip_unless_arch_bits (64 )
25212524 @skip_if_server_version_lt ("3.2.0" )
2522- async def test_georadius_with (self , r : valkey .Valkey ):
2525+ @pytest .mark .parametrize (
2526+ "georadius_kwargs, expected_georadius_result" ,
2527+ [
2528+ (
2529+ {"withdist" : True , "withcoord" : True , "withhash" : True },
2530+ [b"place1" , 0.0881 , 3471609698139488 ],
2531+ ),
2532+ (
2533+ {"withdist" : True , "withcoord" : True },
2534+ [b"place1" , 0.0881 ],
2535+ ),
2536+ (
2537+ {"withhash" : True , "withcoord" : True },
2538+ [b"place1" , 3471609698139488 ],
2539+ ),
2540+ (
2541+ {"withdist" : True , "withhash" : True },
2542+ [b"place1" , 0.0881 , 3471609698139488 ],
2543+ ),
2544+ ],
2545+ )
2546+ async def test_georadius_with (
2547+ self , r : valkey .Valkey , georadius_kwargs , expected_georadius_result
2548+ ):
25232549 values = (2.1909389952632 , 41.433791470673 , "place1" ) + (
25242550 2.1873744593677 ,
25252551 41.406342043777 ,
@@ -2530,33 +2556,23 @@ async def test_georadius_with(self, r: valkey.Valkey):
25302556
25312557 # test a bunch of combinations to test the parse response
25322558 # function.
2533- assert await r .georadius (
2559+ georadius_result = await r .georadius (
25342560 "barcelona" ,
25352561 2.191 ,
25362562 41.433 ,
25372563 1 ,
25382564 unit = "km" ,
2539- withdist = True ,
2540- withcoord = True ,
2541- withhash = True ,
2542- ) == [
2543- [
2544- b"place1" ,
2545- 0.0881 ,
2546- 3471609698139488 ,
2547- (2.19093829393386841 , 41.43379028184083523 ),
2548- ]
2549- ]
2550-
2551- assert await r .georadius (
2552- "barcelona" , 2.191 , 41.433 , 1 , unit = "km" , withdist = True , withcoord = True
2553- ) == [[b"place1" , 0.0881 , (2.19093829393386841 , 41.43379028184083523 )]]
2565+ ** georadius_kwargs ,
2566+ )
25542567
2555- assert await r .georadius (
2556- "barcelona" , 2.191 , 41.433 , 1 , unit = "km" , withhash = True , withcoord = True
2557- ) == [
2558- [b"place1" , 3471609698139488 , (2.19093829393386841 , 41.43379028184083523 )]
2559- ]
2568+ assert len (georadius_result ) == 1
2569+ if "withcoord" in georadius_kwargs :
2570+ assert_geo_is_close (
2571+ georadius_result [0 ][- 1 ], (2.19093829393386841 , 41.43379028184083523 )
2572+ )
2573+ assert georadius_result [0 ][:- 1 ] == expected_georadius_result
2574+ else :
2575+ assert georadius_result == [expected_georadius_result ]
25602576
25612577 # test no values.
25622578 assert (
@@ -2566,9 +2582,7 @@ async def test_georadius_with(self, r: valkey.Valkey):
25662582 1 ,
25672583 1 ,
25682584 unit = "km" ,
2569- withdist = True ,
2570- withcoord = True ,
2571- withhash = True ,
2585+ ** georadius_kwargs ,
25722586 )
25732587 == []
25742588 )
@@ -2632,7 +2646,8 @@ async def test_georadius_store_dist(self, r: valkey.Valkey):
26322646 "barcelona" , 2.191 , 41.433 , 1000 , store_dist = "places_barcelona"
26332647 )
26342648 # instead of save the geo score, the distance is saved.
2635- assert await r .zscore ("places_barcelona" , "place1" ) == 88.05060698409301
2649+ z_score = await r .zscore ("places_barcelona" , "place1" )
2650+ assert math .isclose (z_score , 88.05060698409301 )
26362651
26372652 @skip_unless_arch_bits (64 )
26382653 @skip_if_server_version_lt ("3.2.0" )
@@ -2650,21 +2665,22 @@ async def test_georadiusmember(self, r: valkey.Valkey):
26502665 ]
26512666 assert await r .georadiusbymember ("barcelona" , "place1" , 10 ) == [b"place1" ]
26522667
2653- assert await r .georadiusbymember (
2668+ radius_place2 , radius_place1 = await r .georadiusbymember (
26542669 "barcelona" , "place1" , 4000 , withdist = True , withcoord = True , withhash = True
2655- ) == [
2656- [
2657- b"\x80 place2" ,
2658- 3067.4157 ,
2659- 3471609625421029 ,
2660- (2.187376320362091 , 41.40634178640635 ),
2661- ],
2662- [
2663- b"place1" ,
2664- 0.0 ,
2665- 3471609698139488 ,
2666- (2.1909382939338684 , 41.433790281840835 ),
2667- ],
2670+ )
2671+
2672+ assert_geo_is_close (radius_place2 [- 1 ], (2.187376320362091 , 41.40634178640635 ))
2673+ assert radius_place2 [:- 1 ] == [
2674+ b"\x80 place2" ,
2675+ 3067.4157 ,
2676+ 3471609625421029 ,
2677+ ]
2678+
2679+ assert_geo_is_close (radius_place1 [- 1 ], (2.1909382939338684 , 41.433790281840835 ))
2680+ assert radius_place1 [:- 1 ] == [
2681+ b"place1" ,
2682+ 0.0 ,
2683+ 3471609698139488 ,
26682684 ]
26692685
26702686 @skip_if_server_version_lt ("5.0.0" )
0 commit comments