Coverage for tests/test_tutorial/test_indexes/test_tutorial001.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-16 00:02 +0000

1import importlib 1abcdefghijklm

2from types import ModuleType 1abcdefghijklm

3 

4import pytest 1abcdefghijklm

5from sqlalchemy import Engine, inspect 1abcdefghijklm

6from sqlalchemy.engine.reflection import Inspector 1abcdefghijklm

7 

8from ...conftest import PrintMock 1abcdefghijklm

9 

10 

11@pytest.fixture( 1abcdefghijklm

12 name="mod", 

13 params=[ 

14 pytest.param("tutorial001"), 

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

21 

22 

23def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefghijklm

24 mod.main() 1nopqrstuvwxyz

25 assert print_mock.calls == [ 1nopqrstuvwxyz

26 [{"secret_name": "Dive Wilson", "age": None, "id": 1, "name": "Deadpond"}] 

27 ] 

28 

29 insp: Inspector = inspect(mod.engine) 1nopqrstuvwxyz

30 indexes = insp.get_indexes(str(mod.Hero.__tablename__)) 1nopqrstuvwxyz

31 assert { 1nopqrstuvwxyz

32 index["name"]: (index["column_names"], index["unique"]) for index in indexes 

33 } == { 

34 "ix_hero_name": (["name"], False), 

35 "ix_hero_age": (["age"], False), 

36 }