Coverage for tests/test_tutorial/test_automatic_id_none_refresh/test_tutorial001_py310_tutorial002_py310.py: 100%
53 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 00:02 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 00:02 +0000
1from typing import Any, Dict, List, Union 1lghijk
2from unittest.mock import patch 1lghijk
4from sqlmodel import create_engine 1lghijk
6from tests.conftest import get_testing_print_function, needs_py310 1lghijk
9def check_calls(calls: List[List[Union[str, Dict[str, Any]]]]): 1lghijk
10 assert calls[0] == ["Before interacting with the database"] 1abcdef
11 assert calls[1] == [ 1abcdef
12 "Hero 1:",
13 {
14 "id": None,
15 "name": "Deadpond",
16 "secret_name": "Dive Wilson",
17 "age": None,
18 },
19 ]
20 assert calls[2] == [ 1abcdef
21 "Hero 2:",
22 {
23 "id": None,
24 "name": "Spider-Boy",
25 "secret_name": "Pedro Parqueador",
26 "age": None,
27 },
28 ]
29 assert calls[3] == [ 1abcdef
30 "Hero 3:",
31 {
32 "id": None,
33 "name": "Rusty-Man",
34 "secret_name": "Tommy Sharp",
35 "age": 48,
36 },
37 ]
38 assert calls[4] == ["After adding to the session"] 1abcdef
39 assert calls[5] == [ 1abcdef
40 "Hero 1:",
41 {
42 "id": None,
43 "name": "Deadpond",
44 "secret_name": "Dive Wilson",
45 "age": None,
46 },
47 ]
48 assert calls[6] == [ 1abcdef
49 "Hero 2:",
50 {
51 "id": None,
52 "name": "Spider-Boy",
53 "secret_name": "Pedro Parqueador",
54 "age": None,
55 },
56 ]
57 assert calls[7] == [ 1abcdef
58 "Hero 3:",
59 {
60 "id": None,
61 "name": "Rusty-Man",
62 "secret_name": "Tommy Sharp",
63 "age": 48,
64 },
65 ]
66 assert calls[8] == ["After committing the session"] 1abcdef
67 assert calls[9] == ["Hero 1:", {}] 1abcdef
68 assert calls[10] == ["Hero 2:", {}] 1abcdef
69 assert calls[11] == ["Hero 3:", {}] 1abcdef
70 assert calls[12] == ["After committing the session, show IDs"] 1abcdef
71 assert calls[13] == ["Hero 1 ID:", 1] 1abcdef
72 assert calls[14] == ["Hero 2 ID:", 2] 1abcdef
73 assert calls[15] == ["Hero 3 ID:", 3] 1abcdef
74 assert calls[16] == ["After committing the session, show names"] 1abcdef
75 assert calls[17] == ["Hero 1 name:", "Deadpond"] 1abcdef
76 assert calls[18] == ["Hero 2 name:", "Spider-Boy"] 1abcdef
77 assert calls[19] == ["Hero 3 name:", "Rusty-Man"] 1abcdef
78 assert calls[20] == ["After refreshing the heroes"] 1abcdef
79 assert calls[21] == [ 1abcdef
80 "Hero 1:",
81 {
82 "id": 1,
83 "name": "Deadpond",
84 "secret_name": "Dive Wilson",
85 "age": None,
86 },
87 ]
88 assert calls[22] == [ 1abcdef
89 "Hero 2:",
90 {
91 "id": 2,
92 "name": "Spider-Boy",
93 "secret_name": "Pedro Parqueador",
94 "age": None,
95 },
96 ]
97 assert calls[23] == [ 1abcdef
98 "Hero 3:",
99 {
100 "id": 3,
101 "name": "Rusty-Man",
102 "secret_name": "Tommy Sharp",
103 "age": 48,
104 },
105 ]
106 assert calls[24] == ["After the session closes"] 1abcdef
107 assert calls[21] == [ 1abcdef
108 "Hero 1:",
109 {
110 "id": 1,
111 "name": "Deadpond",
112 "secret_name": "Dive Wilson",
113 "age": None,
114 },
115 ]
116 assert calls[22] == [ 1abcdef
117 "Hero 2:",
118 {
119 "id": 2,
120 "name": "Spider-Boy",
121 "secret_name": "Pedro Parqueador",
122 "age": None,
123 },
124 ]
125 assert calls[23] == [ 1abcdef
126 "Hero 3:",
127 {
128 "id": 3,
129 "name": "Rusty-Man",
130 "secret_name": "Tommy Sharp",
131 "age": 48,
132 },
133 ]
136@needs_py310 1lghijk
137def test_tutorial_001(clear_sqlmodel): 1ghijk
138 from docs_src.tutorial.automatic_id_none_refresh import tutorial001_py310 as mod 1ace
140 mod.sqlite_url = "sqlite://" 1ace
141 mod.engine = create_engine(mod.sqlite_url) 1ace
142 calls = [] 1ace
144 new_print = get_testing_print_function(calls) 1ace
146 with patch("builtins.print", new=new_print): 1ace
147 mod.main() 1ace
148 check_calls(calls) 1ace
151@needs_py310 1lghijk
152def test_tutorial_002(clear_sqlmodel): 1ghijk
153 from docs_src.tutorial.automatic_id_none_refresh import tutorial002_py310 as mod 1bdf
155 mod.sqlite_url = "sqlite://" 1bdf
156 mod.engine = create_engine(mod.sqlite_url) 1bdf
157 calls = [] 1bdf
159 new_print = get_testing_print_function(calls) 1bdf
161 with patch("builtins.print", new=new_print): 1bdf
162 mod.main() 1bdf
163 check_calls(calls) 1bdf