]> git.openstreetmap.org Git - nominatim.git/blob - test/bdd/steps/check_functions.py
save differing linked polace names in extra fields
[nominatim.git] / test / bdd / steps / check_functions.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Collection of assertion functions used for the steps.
9 """
10
11 class Almost:
12     """ Compares a float value with a certain jitter.
13     """
14     def __init__(self, value, offset=0.00001):
15         self.value = value
16         self.offset = offset
17
18     def __eq__(self, other):
19         return abs(other - self.value) < self.offset
20
21 class Bbox:
22     """ Comparator for bounding boxes.
23     """
24     def __init__(self, bbox_string):
25         self.coord = [float(x) for x in bbox_string.split(',')]
26
27     def __contains__(self, item):
28         if isinstance(item, str):
29             item = item.split(',')
30         item = list(map(float, item))
31
32         if len(item) == 2:
33             return self.coord[0] <= item[0] <= self.coord[2] \
34                    and self.coord[1] <= item[1] <= self.coord[3]
35
36         if len(item) == 4:
37             return item[0] >= self.coord[0] and item[1] <= self.coord[1] \
38                    and item[2] >= self.coord[2] and item[3] <= self.coord[3]
39
40         raise ValueError("Not a coordinate or bbox.")
41
42     def __str__(self):
43         return str(self.coord)