Coverage for tests / test_tutorial / test_many_to_many / test_tutorial003.py: 100%
15 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-01-06 21:09 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-01-06 21:09 +0000
1import importlib 1abcdefghi
2from types import ModuleType 1abcdefghi
4import pytest 1abcdefghi
5from sqlmodel import create_engine 1abcdefghi
7from ...conftest import PrintMock, needs_py310 1abcdefghi
10@pytest.fixture( 1abcdefghi
11 name="mod",
12 params=[
13 pytest.param("tutorial003_py39"),
14 pytest.param("tutorial003_py310", marks=needs_py310),
15 ],
16)
17def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghi
18 mod = importlib.import_module(f"docs_src.tutorial.many_to_many.{request.param}") 1abcdefghi
19 mod.sqlite_url = "sqlite://" 1abcdefghi
20 mod.engine = create_engine(mod.sqlite_url) 1abcdefghi
21 return mod 1abcdefghi
24expected_calls = [ 1abcdefghi
25 [
26 "Z-Force hero:",
27 {"name": "Deadpond", "secret_name": "Dive Wilson", "id": 1, "age": None},
28 "is training:",
29 False,
30 ],
31 [
32 "Preventers hero:",
33 {"name": "Deadpond", "secret_name": "Dive Wilson", "id": 1, "age": None},
34 "is training:",
35 True,
36 ],
37 [
38 "Preventers hero:",
39 {"name": "Spider-Boy", "secret_name": "Pedro Parqueador", "id": 2, "age": None},
40 "is training:",
41 True,
42 ],
43 [
44 "Preventers hero:",
45 {"name": "Rusty-Man", "secret_name": "Tommy Sharp", "id": 3, "age": 48},
46 "is training:",
47 False,
48 ],
49 [
50 "Updated Spider-Boy's Teams:",
51 [
52 {"team_id": 2, "is_training": True, "hero_id": 2},
53 {"team_id": 1, "is_training": True, "hero_id": 2},
54 ],
55 ],
56 [
57 "Z-Force heroes:",
58 [
59 {"team_id": 1, "is_training": False, "hero_id": 1},
60 {"team_id": 1, "is_training": True, "hero_id": 2},
61 ],
62 ],
63 [
64 "Spider-Boy team:",
65 {"headquarters": "Sharp Tower", "id": 2, "name": "Preventers"},
66 "is training:",
67 False,
68 ],
69 [
70 "Spider-Boy team:",
71 {"headquarters": "Sister Margaret's Bar", "id": 1, "name": "Z-Force"},
72 "is training:",
73 True,
74 ],
75]
78def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefghi
79 mod.main() 1jklmnopqr
80 assert print_mock.calls == expected_calls 1jklmnopqr