X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/1f29475fa51455363f8cc7b55bec0e801afc638b..815e3cccf6840d935e5a708588700cca23b976e9:/test/bdd/steps/table_compare.py diff --git a/test/bdd/steps/table_compare.py b/test/bdd/steps/table_compare.py index 51d1b645..ca6c3020 100644 --- a/test/bdd/steps/table_compare.py +++ b/test/bdd/steps/table_compare.py @@ -1,3 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# This file is part of Nominatim. (https://nominatim.org) +# +# Copyright (C) 2022 by the Nominatim developer community. +# For a full list of authors see the git log. """ Functions to facilitate accessing and comparing the content of DB tables. """ @@ -56,11 +62,14 @@ class NominatimID: ','.join(['*'] + (extra_columns or [])), table) cur.execute(query, (pid, )) - def get_place_id(self, cur): + def get_place_id(self, cur, allow_empty=False): """ Look up the place id for the ID. Throws an assertion if the ID is not unique. """ self.query_osm_id(cur, "SELECT place_id FROM placex WHERE {}") + if cur.rowcount == 0 and allow_empty: + return None + assert cur.rowcount == 1, \ "Place ID {!s} not unique. Found {} entries.".format(self, cur.rowcount) @@ -196,7 +205,7 @@ class DBRow: if actual == 0: return "place ID 0" - with self.context.db.cursor(): + with self.context.db.cursor() as cur: cur.execute("""SELECT osm_type, osm_id, class FROM placex WHERE place_id = %s""", (actual, ))