Skip to content

Commit

Permalink
Python: Round map values in tests for floating-point comparison (#2592)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Ubuntu <[email protected]>
Signed-off-by: Shoham Elias <[email protected]>
Co-authored-by: Ubuntu <[email protected]>
  • Loading branch information
shohamazon and Ubuntu authored Nov 4, 2024
1 parent 9340ea4 commit db7b1bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
get_random_string,
is_single_response,
parse_info_response,
round_values,
)


Expand Down Expand Up @@ -2687,6 +2688,7 @@ async def test_geosearchstore_by_box(self, glide_client: TGlideClient):
)
expected_map = {member: value[1] for member, value in result.items()}
sorted_expected_map = dict(sorted(expected_map.items(), key=lambda x: x[1]))
zrange_map = round_values(zrange_map, 10)
assert compare_maps(zrange_map, sorted_expected_map) is True

# Test storing results of a box search, unit: kilometes, from a geospatial data, with distance
Expand All @@ -2706,6 +2708,8 @@ async def test_geosearchstore_by_box(self, glide_client: TGlideClient):
)
expected_map = {member: value[0] for member, value in result.items()}
sorted_expected_map = dict(sorted(expected_map.items(), key=lambda x: x[1]))
zrange_map = round_values(zrange_map, 10)
sorted_expected_map = round_values(sorted_expected_map, 10)
assert compare_maps(zrange_map, sorted_expected_map) is True

# Test storing results of a box search, unit: kilometes, from a geospatial data, with count
Expand Down Expand Up @@ -2746,6 +2750,8 @@ async def test_geosearchstore_by_box(self, glide_client: TGlideClient):
b"Palermo": 166274.15156960033,
b"edge2": 236529.17986494553,
}
zrange_map = round_values(zrange_map, 9)
expected_distances = round_values(expected_distances, 9)
assert compare_maps(zrange_map, expected_distances) is True

# Test search by box, unit: feet, from a member, with limited ANY count to 2, with hash
Expand Down Expand Up @@ -2827,6 +2833,8 @@ async def test_geosearchstore_by_radius(self, glide_client: TGlideClient):
b"Catania": 0.0,
b"Palermo": 166274.15156960033,
}
zrange_map = round_values(zrange_map, 9)
expected_distances = round_values(expected_distances, 9)
assert compare_maps(zrange_map, expected_distances) is True

# Test search by radius, unit: miles, from a geospatial data
Expand Down Expand Up @@ -2860,6 +2868,8 @@ async def test_geosearchstore_by_radius(self, glide_client: TGlideClient):
)
expected_map = {member: value[0] for member, value in result.items()}
sorted_expected_map = dict(sorted(expected_map.items(), key=lambda x: x[1]))
zrange_map = round_values(zrange_map, 10)
sorted_expected_map = round_values(sorted_expected_map, 10)
assert compare_maps(zrange_map, sorted_expected_map) is True

# Test storing results of a radius search, unit: kilometers, from a geospatial data, with limited ANY count to 1
Expand Down
5 changes: 5 additions & 0 deletions python/python/tests/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ def compare_maps(
)


def round_values(map_data: dict, decimal_places: int) -> dict:
"""Round the values in a map to the specified number of decimal places."""
return {key: round(value, decimal_places) for key, value in map_data.items()}


def convert_bytes_to_string_object(
# TODO: remove the str options
byte_string_dict: Optional[
Expand Down

0 comments on commit db7b1bb

Please sign in to comment.