]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/bdd/steps/check_functions.py
Replace custom Almost with stdlib math.isclose
[nominatim.git] / test / bdd / steps / check_functions.py
index 58d6c1f2a481ddf61453df633d90e725ef457036..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'}
@@ -47,15 +36,16 @@ class Field:
     """ Generic comparator for fields, which looks at the type of the
         value compared.
     """
-    def __init__(self, value):
+    def __init__(self, value, **extra_args):
         self.value = value
+        self.extra_args = extra_args
 
     def __eq__(self, other):
         if isinstance(self.value, float):
-            return math.isclose(self.value, float(other))
+            return math.isclose(self.value, float(other), **self.extra_args)
 
         if self.value.startswith('^'):
-            return re.fullmatch(self.value, other)
+            return re.fullmatch(self.value, str(other))
 
         if isinstance(other, dict):
             return other == eval('{' + self.value + '}')