Coverage for tests/test_tutorial/test_delete/test_tutorial001_tutorial002.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-27 00:03 +0000

1from unittest.mock import patch 1uvwxyzABCD

2 

3from sqlmodel import create_engine 1uvwxyzABCD

4 

5from ...conftest import get_testing_print_function 1uvwxyzABCD

6 

7expected_calls = [ 1uvwxyzABCD

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 "Hero: ", 

41 { 

42 "id": 2, 

43 "name": "Spider-Youngster", 

44 "secret_name": "Pedro Parqueador", 

45 "age": 16, 

46 }, 

47 ], 

48 [ 

49 "Deleted hero:", 

50 { 

51 "id": 2, 

52 "name": "Spider-Youngster", 

53 "secret_name": "Pedro Parqueador", 

54 "age": 16, 

55 }, 

56 ], 

57 ["There's no hero named Spider-Youngster"], 

58] 

59 

60 

61def test_tutorial001(clear_sqlmodel): 1uvwxyzABCD

62 from docs_src.tutorial.delete import tutorial001 as mod 1abcdefghij

63 

64 mod.sqlite_url = "sqlite://" 1abcdefghij

65 mod.engine = create_engine(mod.sqlite_url) 1abcdefghij

66 calls = [] 1abcdefghij

67 

68 new_print = get_testing_print_function(calls) 1abcdefghij

69 

70 with patch("builtins.print", new=new_print): 1abcdefghij

71 mod.main() 1abcdefghij

72 assert calls == expected_calls 1abcdefghij

73 

74 

75def test_tutorial002(clear_sqlmodel): 1uvwxyzABCD

76 from docs_src.tutorial.delete import tutorial002 as mod 1klmnopqrst

77 

78 mod.sqlite_url = "sqlite://" 1klmnopqrst

79 mod.engine = create_engine(mod.sqlite_url) 1klmnopqrst

80 calls = [] 1klmnopqrst

81 

82 new_print = get_testing_print_function(calls) 1klmnopqrst

83 

84 with patch("builtins.print", new=new_print): 1klmnopqrst

85 mod.main() 1klmnopqrst

86 assert calls == expected_calls 1klmnopqrst