Coverage for tests/test_tutorial/test_many_to_many/test_tutorial003.py: 100%
13 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 unittest.mock import patch 1lghijk
3from sqlmodel import create_engine 1lghijk
5from ...conftest import get_testing_print_function 1lghijk
7expected_calls = [ 1ghijk
8 [
9 "Z-Force hero:",
10 {"name": "Deadpond", "secret_name": "Dive Wilson", "id": 1, "age": None},
11 "is training:",
12 False,
13 ],
14 [
15 "Preventers hero:",
16 {"name": "Deadpond", "secret_name": "Dive Wilson", "id": 1, "age": None},
17 "is training:",
18 True,
19 ],
20 [
21 "Preventers hero:",
22 {"name": "Spider-Boy", "secret_name": "Pedro Parqueador", "id": 2, "age": None},
23 "is training:",
24 True,
25 ],
26 [
27 "Preventers hero:",
28 {"name": "Rusty-Man", "secret_name": "Tommy Sharp", "id": 3, "age": 48},
29 "is training:",
30 False,
31 ],
32 [
33 "Updated Spider-Boy's Teams:",
34 [
35 {"team_id": 2, "is_training": True, "hero_id": 2},
36 {"team_id": 1, "is_training": True, "hero_id": 2},
37 ],
38 ],
39 [
40 "Z-Force heroes:",
41 [
42 {"team_id": 1, "is_training": False, "hero_id": 1},
43 {"team_id": 1, "is_training": True, "hero_id": 2},
44 ],
45 ],
46 [
47 "Spider-Boy team:",
48 {"headquarters": "Sharp Tower", "id": 2, "name": "Preventers"},
49 "is training:",
50 False,
51 ],
52 [
53 "Spider-Boy team:",
54 {"headquarters": "Sister Margaret's Bar", "id": 1, "name": "Z-Force"},
55 "is training:",
56 True,
57 ],
58]
61def test_tutorial(clear_sqlmodel): 1lghijk
62 from docs_src.tutorial.many_to_many import tutorial003 as mod 1abcdef
64 mod.sqlite_url = "sqlite://" 1abcdef
65 mod.engine = create_engine(mod.sqlite_url) 1abcdef
66 calls = [] 1abcdef
68 new_print = get_testing_print_function(calls) 1abcdef
70 with patch("builtins.print", new=new_print): 1abcdef
71 mod.main() 1abcdef
72 assert calls == expected_calls 1abcdef