Coverage for tests / test_tutorial / test_connect / test_select / test_tutorial001_tutorial002.py: 100%
22 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-11-09 00:02 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-11-09 00:02 +0000
1import importlib 1abcdefghi
2from types import ModuleType 1abcdefghi
4import pytest 1abcdefghi
5from dirty_equals import IsList 1abcdefghi
6from sqlalchemy import Engine 1abcdefghi
8from ....conftest import PrintMock 1abcdefghi
10expected_calls = [ 1abcdefghi
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") 1abcdefghi
69def get_module(request: pytest.FixtureRequest, database_engine: Engine) -> ModuleType: 1abcdefghi
70 module = importlib.import_module( 1abcdefghi
71 f"docs_src.tutorial.connect.select.{request.param}"
72 )
73 module.engine = database_engine 1abcdefghi
74 return module 1abcdefghi
77@pytest.mark.parametrize( 1abcdefghi
78 "module",
79 [
80 pytest.param("tutorial001_py310"),
81 ],
82 indirect=True,
83)
84def test_tutorial001(print_mock: PrintMock, module: ModuleType): 1abcdefghi
85 module.main() 1jklmnopqr
86 assert print_mock.calls[:3] == expected_calls[:3] 1jklmnopqr
87 assert print_mock.calls[3:] == IsList(*expected_calls[3:], check_order=False) 1jklmnopqr
90@pytest.mark.parametrize( 1abcdefghi
91 "module",
92 [
93 pytest.param("tutorial002_py310"),
94 ],
95 indirect=True,
96)
97def test_tutorial002(print_mock: PrintMock, module: ModuleType): 1abcdefghi
98 module.main() 1stuvwxyzA
99 assert print_mock.calls[:3] == expected_calls[:3] 1stuvwxyzA
100 assert print_mock.calls[3:] == IsList(*expected_calls[3:], check_order=False) 1stuvwxyzA