Coverage for tests/test_tutorial/test_select/test_tutorial003_tutorial004.py: 100%

24 statements  

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

1from typing import Any, Dict, List, Union 1mnopqr

2from unittest.mock import patch 1mnopqr

3 

4from sqlmodel import create_engine 1mnopqr

5 

6from ...conftest import get_testing_print_function 1mnopqr

7 

8 

9def check_calls(calls: List[List[Union[str, Dict[str, Any]]]]): 1mnopqr

10 assert calls[0][0] == [ 1abcdefghijkl

11 { 

12 "name": "Deadpond", 

13 "secret_name": "Dive Wilson", 

14 "age": None, 

15 "id": 1, 

16 }, 

17 { 

18 "name": "Spider-Boy", 

19 "secret_name": "Pedro Parqueador", 

20 "age": None, 

21 "id": 2, 

22 }, 

23 { 

24 "name": "Rusty-Man", 

25 "secret_name": "Tommy Sharp", 

26 "age": 48, 

27 "id": 3, 

28 }, 

29 ] 

30 

31 

32def test_tutorial_003(clear_sqlmodel): 1mnopqr

33 from docs_src.tutorial.select import tutorial003 as mod 1bdfhjl

34 

35 mod.sqlite_url = "sqlite://" 1bdfhjl

36 mod.engine = create_engine(mod.sqlite_url) 1bdfhjl

37 calls = [] 1bdfhjl

38 

39 new_print = get_testing_print_function(calls) 1bdfhjl

40 

41 with patch("builtins.print", new=new_print): 1bdfhjl

42 mod.main() 1bdfhjl

43 check_calls(calls) 1bdfhjl

44 

45 

46def test_tutorial_002(clear_sqlmodel): 1mnopqr

47 from docs_src.tutorial.select import tutorial004 as mod 1acegik

48 

49 mod.sqlite_url = "sqlite://" 1acegik

50 mod.engine = create_engine(mod.sqlite_url) 1acegik

51 calls = [] 1acegik

52 

53 new_print = get_testing_print_function(calls) 1acegik

54 

55 with patch("builtins.print", new=new_print): 1acegik

56 mod.main() 1acegik

57 check_calls(calls) 1acegik