forked from hans/Nominatim
correctly close API objects during testing
This commit is contained in:
@@ -29,9 +29,12 @@ async def convert(project_dir: Path, outfile: Path, options: Set[str]) -> None:
|
|||||||
outapi = napi.NominatimAPIAsync(project_dir,
|
outapi = napi.NominatimAPIAsync(project_dir,
|
||||||
{'NOMINATIM_DATABASE_DSN': f"sqlite:dbname={outfile}"})
|
{'NOMINATIM_DATABASE_DSN': f"sqlite:dbname={outfile}"})
|
||||||
|
|
||||||
async with api.begin() as src, outapi.begin() as dest:
|
try:
|
||||||
writer = SqliteWriter(src, dest, options)
|
async with api.begin() as src, outapi.begin() as dest:
|
||||||
await writer.write()
|
writer = SqliteWriter(src, dest, options)
|
||||||
|
await writer.write()
|
||||||
|
finally:
|
||||||
|
await outapi.close()
|
||||||
finally:
|
finally:
|
||||||
await api.close()
|
await api.close()
|
||||||
|
|
||||||
|
|||||||
@@ -190,18 +190,24 @@ def apiobj(temp_db_with_extensions, temp_db_conn, monkeypatch):
|
|||||||
|
|
||||||
@pytest.fixture(params=['postgres_db', 'sqlite_db'])
|
@pytest.fixture(params=['postgres_db', 'sqlite_db'])
|
||||||
def frontend(request, event_loop, tmp_path):
|
def frontend(request, event_loop, tmp_path):
|
||||||
|
testapis = []
|
||||||
if request.param == 'sqlite_db':
|
if request.param == 'sqlite_db':
|
||||||
db = str(tmp_path / 'test_nominatim_python_unittest.sqlite')
|
db = str(tmp_path / 'test_nominatim_python_unittest.sqlite')
|
||||||
|
|
||||||
def mkapi(apiobj, options={'reverse'}):
|
def mkapi(apiobj, options={'reverse'}):
|
||||||
event_loop.run_until_complete(convert_sqlite.convert(Path('/invalid'),
|
event_loop.run_until_complete(convert_sqlite.convert(Path('/invalid'),
|
||||||
db, options))
|
db, options))
|
||||||
return napi.NominatimAPI(Path('/invalid'),
|
outapi = napi.NominatimAPI(Path('/invalid'),
|
||||||
{'NOMINATIM_DATABASE_DSN': f"sqlite:dbname={db}",
|
{'NOMINATIM_DATABASE_DSN': f"sqlite:dbname={db}",
|
||||||
'NOMINATIM_USE_US_TIGER_DATA': 'yes',
|
'NOMINATIM_USE_US_TIGER_DATA': 'yes'})
|
||||||
'NOMINATIM_API_POOL_SIZE': '0'})
|
testapis.append(outapi)
|
||||||
|
|
||||||
|
return outapi
|
||||||
elif request.param == 'postgres_db':
|
elif request.param == 'postgres_db':
|
||||||
def mkapi(apiobj, options=None):
|
def mkapi(apiobj, options=None):
|
||||||
return apiobj.api
|
return apiobj.api
|
||||||
|
|
||||||
return mkapi
|
yield mkapi
|
||||||
|
|
||||||
|
for api in testapis:
|
||||||
|
api.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user