From: Miroslav Šedivý <6774676+eumiro@users.noreply.github.com> Date: Wed, 5 Mar 2025 19:35:01 +0000 (+0100) Subject: Replace custom Almost with stdlib math.isclose X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/cd64788a583f7737ff7cddaa4f21e74ea747bef9?hp=-c Replace custom Almost with stdlib math.isclose --- cd64788a583f7737ff7cddaa4f21e74ea747bef9 diff --git a/test/bdd/steps/check_functions.py b/test/bdd/steps/check_functions.py index 49676896..708de852 100644 --- a/test/bdd/steps/check_functions.py +++ b/test/bdd/steps/check_functions.py @@ -11,17 +11,6 @@ import json import math import re -class Almost: - """ Compares a float value with a certain jitter. - """ - def __init__(self, value, offset=0.00001): - self.value = value - self.offset = offset - - def __eq__(self, other): - return abs(other - self.value) < self.offset - - OSM_TYPE = {'N' : 'node', 'W' : 'way', 'R' : 'relation', 'n' : 'node', 'w' : 'way', 'r' : 'relation', 'node' : 'n', 'way' : 'w', 'relation' : 'r'} diff --git a/test/bdd/steps/http_responses.py b/test/bdd/steps/http_responses.py index 2e24ed50..c28c4e1c 100644 --- a/test/bdd/steps/http_responses.py +++ b/test/bdd/steps/http_responses.py @@ -11,7 +11,7 @@ import re import json import xml.etree.ElementTree as ET -from check_functions import Almost, OsmType, Field, check_for_attributes +from check_functions import OsmType, Field, check_for_attributes class GenericResponse: diff --git a/test/bdd/steps/table_compare.py b/test/bdd/steps/table_compare.py index 4284fad9..f0d27ba5 100644 --- a/test/bdd/steps/table_compare.py +++ b/test/bdd/steps/table_compare.py @@ -7,14 +7,13 @@ """ Functions to facilitate accessing and comparing the content of DB tables. """ +import math import re import json import psycopg from psycopg import sql as pysql -from steps.check_functions import Almost - ID_REGEX = re.compile(r"(?P[NRW])(?P\d+)(:(?P\w+))?") class NominatimID: @@ -166,7 +165,7 @@ class DBRow: else: x, y = self.context.osm.grid_node(int(expected)) - return Almost(float(x)) == self.db_row['cx'] and Almost(float(y)) == self.db_row['cy'] + return math.isclose(float(x), self.db_row['cx']) and math.isclose(float(y), self.db_row['cy']) def _has_geometry(self, expected): geom = self.context.osm.parse_geometry(expected)