mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-14 01:47:57 +00:00
avoid f-strings in SQL creation in tests
This commit is contained in:
@@ -60,7 +60,7 @@ def temp_db(monkeypatch):
|
|||||||
|
|
||||||
with psycopg.connect(dbname='postgres', autocommit=True) as conn:
|
with psycopg.connect(dbname='postgres', autocommit=True) as conn:
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
cur.execute('DROP DATABASE IF EXISTS {}'.format(name))
|
cur.execute(pysql.SQL('DROP DATABASE IF EXISTS') + pysql.Identifier(name))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@@ -104,7 +104,9 @@ def table_factory(temp_db_conn):
|
|||||||
"""
|
"""
|
||||||
def mk_table(name, definition='id INT', content=None):
|
def mk_table(name, definition='id INT', content=None):
|
||||||
with psycopg.ClientCursor(temp_db_conn) as cur:
|
with psycopg.ClientCursor(temp_db_conn) as cur:
|
||||||
cur.execute('CREATE TABLE {} ({})'.format(name, definition))
|
cur.execute(pysql.SQL("CREATE TABLE {} ({})")
|
||||||
|
.format(pysql.Identifier(name),
|
||||||
|
pysql.SQL(definition)))
|
||||||
if content:
|
if content:
|
||||||
sql = pysql.SQL("INSERT INTO {} VALUES ({})")\
|
sql = pysql.SQL("INSERT INTO {} VALUES ({})")\
|
||||||
.format(pysql.Identifier(name),
|
.format(pysql.Identifier(name),
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# This file is part of Nominatim. (https://nominatim.org)
|
# This file is part of Nominatim. (https://nominatim.org)
|
||||||
#
|
#
|
||||||
# Copyright (C) 2025 by the Nominatim developer community.
|
# Copyright (C) 2026 by the Nominatim developer community.
|
||||||
# For a full list of authors see the git log.
|
# For a full list of authors see the git log.
|
||||||
"""
|
"""
|
||||||
Tests for functions to import a new database.
|
Tests for functions to import a new database.
|
||||||
@@ -25,12 +25,14 @@ class TestDatabaseSetup:
|
|||||||
def setup_nonexistant_db(self):
|
def setup_nonexistant_db(self):
|
||||||
with psycopg.connect(dbname='postgres', autocommit=True) as conn:
|
with psycopg.connect(dbname='postgres', autocommit=True) as conn:
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
cur.execute(f'DROP DATABASE IF EXISTS {self.DBNAME}')
|
cur.execute(pysql.SQL('DROP DATABASE IF EXISTS ')
|
||||||
|
+ pysql.Identifier(self.DBNAME))
|
||||||
|
|
||||||
yield True
|
yield True
|
||||||
|
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
cur.execute(f'DROP DATABASE IF EXISTS {self.DBNAME}')
|
cur.execute(pysql.SQL('DROP DATABASE IF EXISTS ')
|
||||||
|
+ pysql.Identifier(self.DBNAME))
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def cursor(self):
|
def cursor(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user