Skip to content

Commit

Permalink
fix subprocess logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanmcreynolds committed Apr 23, 2024
1 parent 74a79e7 commit 0f9e681
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions tiled/_tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,34 @@ async def test_constraints_on_parameter_and_num(a, assets):
)
],
)


@pytest.mark.asyncio
async def test_init_db_logging(tmpdir, caplog):
config = {
"database": {
"uri": "sqlite+aiosqlite://", # in-memory
},
"trees": [
{
"tree": "catalog",
"path": "/",
"args": {
"uri": f"sqlite+aiosqlite:///{tmpdir}/catalog.db",
"writable_storage": str(tmpdir / "data"),
"init_if_not_exists": True,
},
},
],
}
# Issue 721 notes that the logging of the subprocess that creates
# a database logs normal things to error. This test looks at the log
# and fails if an error log happens. This could catch anything that is
# an error during the app build.
import logging

with caplog.at_level(logging.INFO):
app = build_app_from_config(config)
for record in caplog.records:
assert record.levelname != "ERROR", f"Error found creating app {record.msg}"
assert app
2 changes: 1 addition & 1 deletion tiled/catalog/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ def from_uri(
stdout = process.stdout.decode()
stderr = process.stderr.decode()
logging.info(f"Subprocess stdout: {stdout}")
logging.error(f"Subprocess stderr: {stderr}")
logging.info(f"Subprocess stderr: {stderr}")
if not SCHEME_PATTERN.match(uri):
# Interpret URI as filepath.
uri = f"sqlite+aiosqlite:///{uri}"
Expand Down

0 comments on commit 0f9e681

Please sign in to comment.