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

22 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-07 05:42 +0000

1from unittest.mock import patch 1uopqrst

2 

3from sqlmodel import create_engine 1uopqrst

4 

5from ...conftest import get_testing_print_function 1uopqrst

6 

7expected_calls = [ 1opqrst

8 [ 

9 "Hero 1:", 

10 {"id": 2, "name": "Spider-Boy", "secret_name": "Pedro Parqueador", "age": None}, 

11 ], 

12 [ 

13 "Hero 2:", 

14 { 

15 "id": 7, 

16 "name": "Captain North America", 

17 "secret_name": "Esteban Rogelios", 

18 "age": 93, 

19 }, 

20 ], 

21 [ 

22 "Updated hero 1:", 

23 { 

24 "id": 2, 

25 "name": "Spider-Youngster", 

26 "secret_name": "Pedro Parqueador", 

27 "age": 16, 

28 }, 

29 ], 

30 [ 

31 "Updated hero 2:", 

32 { 

33 "id": 7, 

34 "name": "Captain North America Except Canada", 

35 "secret_name": "Esteban Rogelios", 

36 "age": 110, 

37 }, 

38 ], 

39] 

40 

41 

42def test_tutorial003(clear_sqlmodel): 1uopqrst

43 from docs_src.tutorial.update import tutorial003 as mod 1abcdefg

44 

45 mod.sqlite_url = "sqlite://" 1abcdefg

46 mod.engine = create_engine(mod.sqlite_url) 1abcdefg

47 calls = [] 1abcdefg

48 

49 new_print = get_testing_print_function(calls) 1abcdefg

50 

51 with patch("builtins.print", new=new_print): 1abcdefg

52 mod.main() 1abcdefg

53 assert calls == expected_calls 1abcdefg

54 

55 

56def test_tutorial004(clear_sqlmodel): 1uopqrst

57 from docs_src.tutorial.update import tutorial004 as mod 1hijklmn

58 

59 mod.sqlite_url = "sqlite://" 1hijklmn

60 mod.engine = create_engine(mod.sqlite_url) 1hijklmn

61 calls = [] 1hijklmn

62 

63 new_print = get_testing_print_function(calls) 1hijklmn

64 

65 with patch("builtins.print", new=new_print): 1hijklmn

66 mod.main() 1hijklmn

67 assert calls == expected_calls 1hijklmn