Coverage for tests/test_tutorial/test_code_structure/test_tutorial002_py310.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 00:02 +0000

1from unittest.mock import patch 1idefgh

2 

3from sqlmodel import create_engine 1idefgh

4 

5from ...conftest import get_testing_print_function, needs_py310 1idefgh

6 

7expected_calls = [ 1defgh

8 [ 

9 "Created hero:", 

10 { 

11 "id": 1, 

12 "name": "Deadpond", 

13 "age": None, 

14 "secret_name": "Dive Wilson", 

15 "team_id": 1, 

16 }, 

17 ], 

18 [ 

19 "Hero's team:", 

20 {"name": "Z-Force", "headquarters": "Sister Margaret's Bar", "id": 1}, 

21 ], 

22] 

23 

24 

25@needs_py310 1idefgh

26def test_tutorial(clear_sqlmodel): 1defgh

27 from docs_src.tutorial.code_structure.tutorial002_py310 import app, database 1abc

28 

29 database.sqlite_url = "sqlite://" 1abc

30 database.engine = create_engine(database.sqlite_url) 1abc

31 app.engine = database.engine 1abc

32 calls = [] 1abc

33 

34 new_print = get_testing_print_function(calls) 1abc

35 

36 with patch("builtins.print", new=new_print): 1abc

37 app.main() 1abc

38 assert calls == expected_calls 1abc