Coverage for tests/test_tutorial/test_indexes/test_tutorial002.py: 100%
17 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-16 00:02 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-16 00:02 +0000
1import importlib 1abcdefghijklm
2from types import ModuleType 1abcdefghijklm
4import pytest 1abcdefghijklm
5from sqlalchemy import Engine, inspect 1abcdefghijklm
6from sqlalchemy.engine.reflection import Inspector 1abcdefghijklm
8from ...conftest import PrintMock 1abcdefghijklm
11@pytest.fixture( 1abcdefghijklm
12 name="mod",
13 params=[
14 pytest.param("tutorial002"),
15 ],
16)
17def get_module(request: pytest.FixtureRequest, database_engine: Engine) -> ModuleType: 1abcdefghijklm
18 mod = importlib.import_module(f"docs_src.tutorial.indexes.{request.param}") 1abcdefghijklm
19 mod.engine = database_engine 1abcdefghijklm
20 return mod 1abcdefghijklm
23def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefghijklm
24 mod.main() 1nopqrstuvwxyz
25 assert print_mock.calls == [ 1nopqrstuvwxyz
26 [{"name": "Tarantula", "secret_name": "Natalia Roman-on", "age": 32, "id": 4}],
27 [{"name": "Black Lion", "secret_name": "Trevor Challa", "age": 35, "id": 5}],
28 ]
30 insp: Inspector = inspect(mod.engine) 1nopqrstuvwxyz
31 indexes = insp.get_indexes(str(mod.Hero.__tablename__)) 1nopqrstuvwxyz
32 assert { 1nopqrstuvwxyz
33 index["name"]: (index["column_names"], index["unique"]) for index in indexes
34 } == {
35 "ix_hero_name": (["name"], False),
36 "ix_hero_age": (["age"], False),
37 }