X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/da0a7a765e57ea2e22caa6d70b5058c7c148d3bd..78f839fbd3ccc623b64895059b440e355c06c7c3:/test/bdd/steps/check_functions.py diff --git a/test/bdd/steps/check_functions.py b/test/bdd/steps/check_functions.py index 58d6c1f2..df9e6f35 100644 --- a/test/bdd/steps/check_functions.py +++ b/test/bdd/steps/check_functions.py @@ -2,7 +2,7 @@ # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 2023 by the Nominatim developer community. +# Copyright (C) 2025 by the Nominatim developer community. # For a full list of authors see the git log. """ Collection of assertion functions used for the steps. @@ -11,20 +11,10 @@ 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'} +OSM_TYPE = {'N': 'node', 'W': 'way', 'R': 'relation', + 'n': 'node', 'w': 'way', 'r': 'relation', + 'node': 'n', 'way': 'w', 'relation': 'r'} class OsmType: @@ -34,11 +24,9 @@ class OsmType: def __init__(self, value): self.value = value - def __eq__(self, other): return other == self.value or other == OSM_TYPE[self.value] - def __str__(self): return f"{self.value} or {OSM_TYPE[self.value]}" @@ -47,15 +35,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 + '}') @@ -91,7 +80,6 @@ class Bbox: return str(self.coord) - def check_for_attributes(obj, attrs, presence='present'): """ Check that the object has the given attributes. 'attrs' is a string with a comma-separated list of attributes. If 'presence' @@ -109,4 +97,3 @@ def check_for_attributes(obj, attrs, presence='present'): else: assert attr in obj, \ f"No attribute '{attr}'. Full response:\n{_dump_json()}" -