]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge pull request #3666 from eumiro/math-isclose
authorSarah Hoffmann <lonvia@denofr.de>
Thu, 6 Mar 2025 16:53:01 +0000 (17:53 +0100)
committerGitHub <noreply@github.com>
Thu, 6 Mar 2025 16:53:01 +0000 (17:53 +0100)
Replace custom Almost with stdlib math.isclose

test/bdd/steps/check_functions.py
test/bdd/steps/http_responses.py
test/bdd/steps/table_compare.py

index 49676896f4ff4487d5bc3e5ec815a339c3b8043b..708de852c03a5720d5a656a3c0d372911bdbb0a0 100644 (file)
@@ -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'}
index 2e24ed5043bddf87bcfde92e897a6f95e241674e..c28c4e1c899422700ffb5989032c2edbb22c33c1 100644 (file)
@@ -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:
index 4284fad962607796c59560dbda2bceb687375a1e..f0d27ba595494df92938263c146c82d584086c50 100644 (file)
@@ -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<typ>[NRW])(?P<oid>\d+)(:(?P<cls>\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)