Coverage for mlos_bench/mlos_bench/tests/storage/schema_test.py: 100%
16 statements
« prev ^ index » next coverage.py v7.17.0, created at 2026-10-27 00:50 +0000
« prev ^ index » next coverage.py v7.17.0, created at 2026-10-27 00:50 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""Regression tests for SQL schema migration configuration."""
7from pathlib import Path
9import pytest
10from sqlalchemy import URL, create_engine
12from mlos_bench.storage.sql.schema import DbSchema
15@pytest.mark.parametrize("database", [":memory:", "database%name.sqlite", "database name.sqlite"])
16def test_alembic_url_round_trip(database: str, tmp_path: Path) -> None:
17 """Preserve URL escaping when Alembic reads its interpolated configuration."""
18 if database != ":memory:":
19 database = str(tmp_path / database)
20 engine = create_engine(URL.create("sqlite", database=database))
21 try:
22 schema = DbSchema(engine)
23 with engine.connect() as connection:
24 config = schema._get_alembic_cfg(connection) # pylint: disable=protected-access
25 assert config.get_main_option("sqlalchemy.url") == engine.url.render_as_string(
26 hide_password=False,
27 )
28 assert config.attributes["connection"] is connection
29 finally:
30 engine.dispose()