Coverage for tests/test_tutorial/test_indexes/test_tutorial001_py310.py: 100%
22 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-03-24 00:02 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-03-24 00:02 +0000
1from unittest.mock import patch 1efghij
3from sqlalchemy import inspect 1efghij
4from sqlalchemy.engine.reflection import Inspector 1efghij
5from sqlmodel import create_engine 1efghij
7from ...conftest import get_testing_print_function, needs_py310 1efghij
10@needs_py310 1efghij
11def test_tutorial(clear_sqlmodel): 1efghij
12 from docs_src.tutorial.indexes import tutorial001_py310 as mod 1abcd
14 mod.sqlite_url = "sqlite://" 1abcd
15 mod.engine = create_engine(mod.sqlite_url) 1abcd
16 calls = [] 1abcd
18 new_print = get_testing_print_function(calls) 1abcd
20 with patch("builtins.print", new=new_print): 1abcd
21 mod.main() 1abcd
22 assert calls == [ 1abcd
23 [{"secret_name": "Dive Wilson", "age": None, "id": 1, "name": "Deadpond"}]
24 ]
26 insp: Inspector = inspect(mod.engine) 1abcd
27 indexes = insp.get_indexes(str(mod.Hero.__tablename__)) 1abcd
28 expected_indexes = [ 1abcd
29 {
30 "name": "ix_hero_name",
31 "dialect_options": {},
32 "column_names": ["name"],
33 "unique": 0,
34 },
35 {
36 "name": "ix_hero_age",
37 "dialect_options": {},
38 "column_names": ["age"],
39 "unique": 0,
40 },
41 ]
42 for index in expected_indexes: 1abcd
43 assert index in indexes, "This expected index should be in the indexes in DB" 1abcd
44 # Now that this index was checked, remove it from the list of indexes
45 indexes.pop(indexes.index(index)) 1abcd
46 assert len(indexes) == 0, "The database should only have the expected indexes" 1abcd