bdd: remove class for lazy formatting

assert in combination with format() does the right thing and calls
the __str__() method only when an assertion hits.
This commit is contained in:
Sarah Hoffmann
2021-01-05 10:39:44 +01:00
parent 213bf7d19d
commit 58c471c627

View File

@@ -92,14 +92,6 @@ class PlaceColumn:
self.geometry)
cursor.execute(query, list(self.columns.values()))
class LazyFmt(object):
def __init__(self, fmtstr, *args):
self.fmt = fmtstr
self.args = args
def __str__(self):
return self.fmt % self.args
class PlaceObjName(object):
@@ -125,15 +117,15 @@ class PlaceObjName(object):
def compare_place_id(expected, result, column, context):
if expected == '0':
assert result == 0, \
LazyFmt("Bad place id in column %s. Expected: 0, got: %s.",
"Bad place id in column {}. Expected: 0, got: {!s}.".format(
column, PlaceObjName(result, context.db))
elif expected == '-':
assert result is None, \
LazyFmt("bad place id in column %s: %s.",
"Bad place id in column {}: {!s}.".format(
column, PlaceObjName(result, context.db))
else:
assert NominatimID(expected).get_place_id(context.db.cursor()) == result, \
LazyFmt("Bad place id in column %s. Expected: %s, got: %s.",
"Bad place id in column {}. Expected: {}, got: {!s}.".format(
column, expected, PlaceObjName(result, context.db))
def check_database_integrity(context):