Coverage for tests/test_tutorial/test_connect/test_select/test_tutorial005_py310.py: 100%

14 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 "age": None, 

12 "id": 1, 

13 "secret_name": "Dive Wilson", 

14 "team_id": 2, 

15 "name": "Deadpond", 

16 }, 

17 ], 

18 [ 

19 "Created hero:", 

20 { 

21 "age": 48, 

22 "id": 2, 

23 "secret_name": "Tommy Sharp", 

24 "team_id": 1, 

25 "name": "Rusty-Man", 

26 }, 

27 ], 

28 [ 

29 "Created hero:", 

30 { 

31 "age": None, 

32 "id": 3, 

33 "secret_name": "Pedro Parqueador", 

34 "team_id": None, 

35 "name": "Spider-Boy", 

36 }, 

37 ], 

38 [ 

39 "Preventer Hero:", 

40 { 

41 "age": 48, 

42 "id": 2, 

43 "secret_name": "Tommy Sharp", 

44 "team_id": 1, 

45 "name": "Rusty-Man", 

46 }, 

47 "Team:", 

48 {"id": 1, "name": "Preventers", "headquarters": "Sharp Tower"}, 

49 ], 

50] 

51 

52 

53@needs_py310 1idefgh

54def test_tutorial(clear_sqlmodel): 1defgh

55 from docs_src.tutorial.connect.select import tutorial005_py310 as mod 1abc

56 

57 mod.sqlite_url = "sqlite://" 1abc

58 mod.engine = create_engine(mod.sqlite_url) 1abc

59 calls = [] 1abc

60 

61 new_print = get_testing_print_function(calls) 1abc

62 

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

64 mod.main() 1abc

65 assert calls == expected_calls 1abc