]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/python/conftest.py
move import-data option to native python
[nominatim.git] / test / python / conftest.py
index ecd40d7cf8b616c0af126d5c411c030527d30c77..f0569ab80477c4e6e1394881695bbf6b03c60096 100644 (file)
@@ -36,6 +36,14 @@ class _TestingCursor(psycopg2.extras.DictCursor):
 
         return set((tuple(row) for row in self))
 
+    def table_exists(self, table):
+        """ Check that a table with the given name exists in the database.
+        """
+        num = self.scalar("""SELECT count(*) FROM pg_tables
+                             WHERE tablename = %s""", (table, ))
+        return num == 1
+
+
 @pytest.fixture
 def temp_db(monkeypatch):
     """ Create an empty database for the test. The database name is also
@@ -77,9 +85,8 @@ def temp_db_with_extensions(temp_db):
 def temp_db_conn(temp_db):
     """ Connection to the test database.
     """
-    conn = connection.connect('dbname=' + temp_db)
-    yield conn
-    conn.close()
+    with connection.connect('dbname=' + temp_db) as conn:
+        yield conn
 
 
 @pytest.fixture
@@ -98,6 +105,9 @@ def temp_db_cursor(temp_db):
 def def_config():
     return Configuration(None, SRC_DIR.resolve() / 'settings')
 
+@pytest.fixture
+def src_dir():
+    return SRC_DIR.resolve()
 
 @pytest.fixture
 def status_table(temp_db_conn):
@@ -188,4 +198,13 @@ def placex_table(temp_db_with_extensions, temp_db_conn):
     temp_db_conn.commit()
 
 
-
+@pytest.fixture
+def osm2pgsql_options(temp_db):
+    return dict(osm2pgsql='echo',
+                osm2pgsql_cache=10,
+                osm2pgsql_style='style.file',
+                threads=1,
+                dsn='dbname=' + temp_db,
+                flatnode_file='',
+                tablespaces=dict(slim_data='', slim_index='',
+                                 main_data='', main_index=''))