Coverage for tests/test_advanced/test_uuid/test_tutorial001_py310.py: 100%
19 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-27 00:03 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-27 00:03 +0000
1from unittest.mock import patch 1ijklmnopqr
3from dirty_equals import IsUUID 1ijklmnopqr
4from sqlmodel import create_engine 1ijklmnopqr
6from ...conftest import get_testing_print_function, needs_py310 1ijklmnopqr
9@needs_py310 1ijklmnopqr
10def test_tutorial() -> None: 1ijklmnopqr
11 from docs_src.advanced.uuid import tutorial001_py310 as mod 1abcdefgh
13 mod.sqlite_url = "sqlite://" 1abcdefgh
14 mod.engine = create_engine(mod.sqlite_url) 1abcdefgh
15 calls = [] 1abcdefgh
17 new_print = get_testing_print_function(calls) 1abcdefgh
19 with patch("builtins.print", new=new_print): 1abcdefgh
20 mod.main() 1abcdefgh
21 first_uuid = calls[1][0]["id"] 1abcdefgh
22 assert first_uuid == IsUUID(4) 1abcdefgh
24 second_uuid = calls[7][0]["id"] 1abcdefgh
25 assert second_uuid == IsUUID(4) 1abcdefgh
27 assert first_uuid != second_uuid 1abcdefgh
29 assert calls == [ 1abcdefgh
30 ["The hero before saving in the DB"],
31 [
32 {
33 "name": "Deadpond",
34 "secret_name": "Dive Wilson",
35 "id": first_uuid,
36 "age": None,
37 }
38 ],
39 ["The hero ID was already set"],
40 [first_uuid],
41 ["After saving in the DB"],
42 [
43 {
44 "name": "Deadpond",
45 "secret_name": "Dive Wilson",
46 "age": None,
47 "id": first_uuid,
48 }
49 ],
50 ["Created hero:"],
51 [
52 {
53 "name": "Spider-Boy",
54 "secret_name": "Pedro Parqueador",
55 "age": None,
56 "id": second_uuid,
57 }
58 ],
59 ["Created hero ID:"],
60 [second_uuid],
61 ["Selected hero:"],
62 [
63 {
64 "name": "Spider-Boy",
65 "secret_name": "Pedro Parqueador",
66 "age": None,
67 "id": second_uuid,
68 }
69 ],
70 ["Selected hero ID:"],
71 [second_uuid],
72 ]