+@step(u'way (\d+) expands to housenumbers')
+def check_interpolated_housenumbers(step, nodeid):
+ """Check that the exact set of housenumbers has been entered in
+ placex for the given source node. Expected are two columns:
+ housenumber and centroid
+ """
+ numbers = {}
+ for line in step.hashes:
+ assert line["housenumber"] not in numbers
+ numbers[line["housenumber"]] = line["centroid"]
+ cur = world.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
+ cur.execute("""SELECT DISTINCT housenumber,
+ ST_X(centroid) as clat, ST_Y(centroid) as clon
+ FROM placex WHERE osm_type = 'W' and osm_id = %s
+ and class = 'place' and type = 'address'""",
+ (int(nodeid),))
+ assert_equals(len(numbers), cur.rowcount)
+ for r in cur:
+ assert_in(r["housenumber"], numbers)
+ world.match_geometry((r['clat'], r['clon']), numbers[r["housenumber"]])
+ del numbers[r["housenumber"]]
+
+@step(u'way (\d+) expands exactly to housenumbers ([0-9,]*)')
+def check_interpolated_housenumber_list(step, nodeid, numberlist):
+ """ Checks that the interpolated house numbers corresponds
+ to the given list.
+ """
+ expected = numberlist.split(',');
+ cur = world.conn.cursor()
+ cur.execute("""SELECT housenumber FROM placex
+ WHERE osm_type = 'W' and osm_id = %s
+ and class = 'place' and type = 'address'""", (int(nodeid),))
+ for r in cur:
+ assert_in(r[0], expected, "Unexpected house number %s for node %s." % (r[0], nodeid))
+ expected.remove(r[0])
+ assert_equals(0, len(expected), "Missing house numbers for way %s: %s" % (nodeid, expected))
+
+@step(u'way (\d+) expands to no housenumbers')
+def check_no_interpolated_housenumber_list(step, nodeid):
+ """ Checks that the interpolated house numbers corresponds
+ to the given list.
+ """
+ cur = world.conn.cursor()
+ cur.execute("""SELECT housenumber FROM placex
+ WHERE osm_type = 'W' and osm_id = %s
+ and class = 'place' and type = 'address'""", (int(nodeid),))
+ res = [r[0] for r in cur]
+ assert_equals(0, len(res), "Unexpected house numbers for way %s: %s" % (nodeid, res))