Coverage for tests/test_tutorial/test_one/test_tutorial004_py310.py: 100%
21 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 1idefgh
3import pytest 1idefgh
4from sqlalchemy.exc import MultipleResultsFound 1idefgh
5from sqlmodel import Session, create_engine, delete 1idefgh
7from ...conftest import get_testing_print_function, needs_py310 1idefgh
10@needs_py310 1idefgh
11def test_tutorial(clear_sqlmodel): 1defgh
12 from docs_src.tutorial.one import tutorial004_py310 as mod 1abc
14 mod.sqlite_url = "sqlite://" 1abc
15 mod.engine = create_engine(mod.sqlite_url) 1abc
16 with pytest.raises(MultipleResultsFound): 1abc
17 mod.main() 1abc
18 with Session(mod.engine) as session: 1abc
19 # TODO: create delete() function
20 # TODO: add overloads for .exec() with delete object
21 session.exec(delete(mod.Hero)) 1abc
22 session.add(mod.Hero(name="Test Hero", secret_name="Secret Test Hero", age=24)) 1abc
23 session.commit() 1abc
25 calls = [] 1abc
27 new_print = get_testing_print_function(calls) 1abc
29 with patch("builtins.print", new=new_print): 1abc
30 mod.select_heroes() 1abc
31 assert calls == [ 1abc
32 [
33 "Hero:",
34 {
35 "id": 1,
36 "name": "Test Hero",
37 "secret_name": "Secret Test Hero",
38 "age": 24,
39 },
40 ]
41 ]