X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/6d0ab4480086a20d6c19e0c9ca5df944be3c1a23..051998dd80b0def50058266b7adbdf2e971032eb:/tests/steps/terrain.py?ds=sidebyside diff --git a/tests/steps/terrain.py b/tests/steps/terrain.py index 746485ac..80beebd5 100644 --- a/tests/steps/terrain.py +++ b/tests/steps/terrain.py @@ -23,7 +23,7 @@ class NominatimConfig: logging.basicConfig(level=loglevel) # Nominatim test setup self.base_url = os.environ.get('NOMINATIM_SERVER', 'http://localhost/nominatim') - self.source_dir = os.path.abspath(os.environ.get('NOMINATIM_DIR', '..')) + self.source_dir = os.path.abspath(os.environ.get('NOMINATIM_DIR', '../build')) self.template_db = os.environ.get('TEMPLATE_DB', 'test_template_nominatim') self.test_db = os.environ.get('TEST_DB', 'test_nominatim') self.local_settings_file = os.environ.get('NOMINATIM_SETTINGS', '/tmp/nominatim_settings.php') @@ -52,8 +52,10 @@ def write_nominatim_config(dbname): def run_nominatim_script(script, *args): cmd = [os.path.join(world.config.source_dir, 'utils', '%s.php' % script)] cmd.extend(['--%s' % x for x in args]) - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + proc = subprocess.Popen(cmd, cwd=world.config.source_dir, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) (outp, outerr) = proc.communicate() + logger.debug("run_nominatim_script: %s\n%s\n%s" % (cmd, outp, outerr)) assert (proc.returncode == 0), "Script '%s' failed:\n%s\n%s\n" % (script, outp, outerr) @world.absorb @@ -94,7 +96,7 @@ def get_placeid(oid): q = 'SELECT place_id FROM placex where osm_type = %s and osm_id = %s and class = %s' params = (osmtype, osmid, cls) cur.execute(q, params) - assert_equals (cur.rowcount, 1) + assert_equals(cur.rowcount, 1, "%d rows found for place %s" % (cur.rowcount, oid)) return cur.fetchone()[0] @@ -121,16 +123,19 @@ def match_geometry(coord, matchstring): logger.debug("Distances expected: %f, got: %f" % (expdist, dist)) assert dist <= expdist, "Geometry too far away, expected: %f, got: %f" % (expdist, dist) +@world.absorb +def print_statement(element): + print '\n\n\n'+str(element)+'\n\n\n' @world.absorb def db_dump_table(table): cur = world.conn.cursor() cur.execute('SELECT * FROM %s' % table) - print '<<<<<<< BEGIN OF TABLE DUMP %s' % table + print '\n\n\n<<<<<<< BEGIN OF TABLE DUMP %s' % table for res in cur: print res - print '<<<<<<< END OF TABLE DUMP %s' % table + print '<<<<<<< END OF TABLE DUMP %s\n\n\n' % table @world.absorb def db_drop_database(name): @@ -170,15 +175,19 @@ def db_template_setup(): conn = psycopg2.connect(database=world.config.template_db) psycopg2.extras.register_hstore(conn, globally=False, unicode=True) cur = conn.cursor() - for table in ('gb_postcode', 'us_postcode', 'us_state', 'us_statecounty'): - cur.execute('TRUNCATE TABLE %s' % (table,)) + for table in ('gb_postcode', 'us_postcode'): + cur.execute("select * from pg_tables where tablename = '%s'" % (table, )) + if cur.rowcount > 0: + cur.execute('TRUNCATE TABLE %s' % (table,)) conn.commit() conn.close() # execute osm2pgsql on an empty file to get the right tables osm2pgsql = os.path.join(world.config.source_dir, 'osm2pgsql', 'osm2pgsql') - proc = subprocess.Popen([osm2pgsql, '-lsc', '-O', 'gazetteer', '-d', world.config.template_db, '-'], - stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + proc = subprocess.Popen([osm2pgsql, '-lsc', '-r', 'xml', '-O', 'gazetteer', '-d', world.config.template_db, '-'], + cwd=world.config.source_dir, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) [outstr, errstr] = proc.communicate(input='') + logger.debug("running osm2pgsql for template: %s\n%s\n%s" % (osm2pgsql, outstr, errstr)) world.run_nominatim_script('setup', 'create-functions', 'create-tables', 'create-partition-tables', 'create-partition-functions', 'load-data', 'create-search-indices')