]> git.openstreetmap.org Git - nominatim.git/blob - test/bdd/steps/check_functions.py
require tokeinzer for indexer
[nominatim.git] / test / bdd / steps / check_functions.py
1 """
2 Collection of assertion functions used for the steps.
3 """
4
5 class Almost:
6     """ Compares a float value with a certain jitter.
7     """
8     def __init__(self, value, offset=0.00001):
9         self.value = value
10         self.offset = offset
11
12     def __eq__(self, other):
13         return abs(other - self.value) < self.offset
14
15 class Bbox:
16     """ Comparator for bounding boxes.
17     """
18     def __init__(self, bbox_string):
19         self.coord = [float(x) for x in bbox_string.split(',')]
20
21     def __contains__(self, item):
22         if isinstance(item, str):
23             item = item.split(',')
24         item = list(map(float, item))
25
26         if len(item) == 2:
27             return self.coord[0] <= item[0] <= self.coord[2] \
28                    and self.coord[1] <= item[1] <= self.coord[3]
29
30         if len(item) == 4:
31             return item[0] >= self.coord[0] and item[1] <= self.coord[1] \
32                    and item[2] >= self.coord[2] and item[3] <= self.coord[3]
33
34         raise ValueError("Not a coordinate or bbox.")
35
36     def __str__(self):
37         return str(self.coord)