+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):
+
+ def __init__(self, placeid, conn):
+ self.pid = placeid
+ self.conn = conn
+
+ def __str__(self):
+ if self.pid is None:
+ return "<null>"
+
+ cur = self.conn.cursor()
+ cur.execute("""SELECT osm_type, osm_id, class
+ FROM placex WHERE place_id = %s""",
+ (self.pid, ))
+ eq_(1, cur.rowcount, "No entry found for place id %s" % self.pid)
+
+ return "%s%s:%s" % cur.fetchone()
+
+def compare_place_id(expected, result, column, context):
+ if expected == '0':
+ eq_(0, result,
+ LazyFmt("Bad place id in column %s. Expected: 0, got: %s.",
+ column, PlaceObjName(result, context.db)))
+ elif expected == '-':
+ assert_is_none(result,
+ LazyFmt("bad place id in column %s: %s.",
+ column, PlaceObjName(result, context.db)))
+ else:
+ eq_(NominatimID(expected).get_place_id(context.db.cursor()), result,
+ LazyFmt("Bad place id in column %s. Expected: %s, got: %s.",
+ column, expected, PlaceObjName(result, context.db)))
+