Coverage for tests/test_tutorial/test_connect/test_select/test_tutorial001_tutorial002.py: 100%
22 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 dirty_equals import IsList 1abcdefghijklm
6from sqlalchemy import Engine 1abcdefghijklm
8from ....conftest import PrintMock 1abcdefghijklm
10expected_calls = [ 1abcdefghijklm
11 [
12 "Created hero:",
13 {
14 "age": None,
15 "id": 1,
16 "secret_name": "Dive Wilson",
17 "team_id": 2,
18 "name": "Deadpond",
19 },
20 ],
21 [
22 "Created hero:",
23 {
24 "age": 48,
25 "id": 2,
26 "secret_name": "Tommy Sharp",
27 "team_id": 1,
28 "name": "Rusty-Man",
29 },
30 ],
31 [
32 "Created hero:",
33 {
34 "age": None,
35 "id": 3,
36 "secret_name": "Pedro Parqueador",
37 "team_id": None,
38 "name": "Spider-Boy",
39 },
40 ],
41 [
42 "Hero:",
43 {
44 "age": None,
45 "id": 1,
46 "secret_name": "Dive Wilson",
47 "team_id": 2,
48 "name": "Deadpond",
49 },
50 "Team:",
51 {"id": 2, "name": "Z-Force", "headquarters": "Sister Margaret's Bar"},
52 ],
53 [
54 "Hero:",
55 {
56 "age": 48,
57 "id": 2,
58 "secret_name": "Tommy Sharp",
59 "team_id": 1,
60 "name": "Rusty-Man",
61 },
62 "Team:",
63 {"id": 1, "name": "Preventers", "headquarters": "Sharp Tower"},
64 ],
65]
68@pytest.fixture(name="module") 1abcdefghijklm
69def get_module(request: pytest.FixtureRequest, database_engine: Engine) -> ModuleType: 1abcdefghijklm
70 module = importlib.import_module( 1abcdefghijklm
71 f"docs_src.tutorial.connect.select.{request.param}"
72 )
73 module.engine = database_engine 1abcdefghijklm
74 return module 1abcdefghijklm
77@pytest.mark.parametrize( 1abcdefghijklm
78 "module",
79 [
80 pytest.param("tutorial001"),
81 ],
82 indirect=True,
83)
84def test_tutorial001(print_mock: PrintMock, module: ModuleType): 1abcdefghijklm
85 module.main() 1nopqrstuvwxyz
86 assert print_mock.calls[:3] == expected_calls[:3] 1nopqrstuvwxyz
87 assert print_mock.calls[3:] == IsList(*expected_calls[3:], check_order=False) 1nopqrstuvwxyz
90@pytest.mark.parametrize( 1abcdefghijklm
91 "module",
92 [
93 pytest.param("tutorial002"),
94 ],
95 indirect=True,
96)
97def test_tutorial002(print_mock: PrintMock, module: ModuleType): 1abcdefghijklm
98 module.main() 1ABCDEFGHIJKLM
99 assert print_mock.calls[:3] == expected_calls[:3] 1ABCDEFGHIJKLM
100 assert print_mock.calls[3:] == IsList(*expected_calls[3:], check_order=False) 1ABCDEFGHIJKLM