properly close connection in test

This commit is contained in:
Sarah Hoffmann
2015-01-09 23:16:53 +01:00
parent 6d0ab44800
commit 14d17a3ad4

View File

@@ -22,7 +22,7 @@ logger = logging.getLogger(__name__)
@step(u'table placex contains as names for (N|R|W)(\d+)') @step(u'table placex contains as names for (N|R|W)(\d+)')
def check_placex_names(step, osmtyp, osmid): def check_placex_names(step, osmtyp, osmid):
""" Check for the exact content of the name hstaore in placex. """ Check for the exact content of the name hstore in placex.
""" """
cur = world.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) cur = world.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute('SELECT name FROM placex where osm_type = %s and osm_id =%s', (osmtyp, int(osmid))) cur.execute('SELECT name FROM placex where osm_type = %s and osm_id =%s', (osmtyp, int(osmid)))
@@ -43,6 +43,7 @@ def check_placex_content(step, tablename):
given columns are tested. If there is more than one given columns are tested. If there is more than one
line for an OSM object, they must match in these columns. line for an OSM object, they must match in these columns.
""" """
try:
cur = world.conn.cursor(cursor_factory=psycopg2.extras.DictCursor) cur = world.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
for line in step.hashes: for line in step.hashes:
osmtype, osmid, cls = world.split_id(line['object']) osmtype, osmid, cls = world.split_id(line['object'])
@@ -72,10 +73,14 @@ def check_placex_content(step, tablename):
world.match_geometry((res['clat'], res['clon']), v) world.match_geometry((res['clat'], res['clon']), v)
else: else:
assert_equals(str(res[k]), v, "Results for '%s'/'%s' differ: '%s' != '%s'" % (line['object'], k, str(res[k]), v)) assert_equals(str(res[k]), v, "Results for '%s'/'%s' differ: '%s' != '%s'" % (line['object'], k, str(res[k]), v))
finally:
cur.close()
world.conn.commit()
@step(u'table (placex?) has no entry for (N|R|W)(\d+)(:\w+)?') @step(u'table (placex?) has no entry for (N|R|W)(\d+)(:\w+)?')
def check_placex_missing(step, tablename, osmtyp, osmid, placeclass): def check_placex_missing(step, tablename, osmtyp, osmid, placeclass):
cur = world.conn.cursor() cur = world.conn.cursor()
try:
q = 'SELECT count(*) FROM %s where osm_type = %%s and osm_id = %%s' % (tablename, ) q = 'SELECT count(*) FROM %s where osm_type = %%s and osm_id = %%s' % (tablename, )
args = [osmtyp, int(osmid)] args = [osmtyp, int(osmid)]
if placeclass is not None: if placeclass is not None:
@@ -84,6 +89,9 @@ def check_placex_missing(step, tablename, osmtyp, osmid, placeclass):
cur.execute(q, args) cur.execute(q, args)
numres = cur.fetchone()[0] numres = cur.fetchone()[0]
assert_equals (numres, 0) assert_equals (numres, 0)
finally:
cur.close()
world.conn.commit()
@step(u'search_name table contains$') @step(u'search_name table contains$')
def check_search_name_content(step): def check_search_name_content(step):