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

24 statements  

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

1from unittest.mock import patch 1abcdefghij

2 

3from sqlmodel import create_engine 1abcdefghij

4 

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

6 

7expected_calls = [ 1abcdefghij

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

40 { 

41 "age": None, 

42 "id": 1, 

43 "secret_name": "Dive Wilson", 

44 "team_id": 2, 

45 "name": "Deadpond", 

46 }, 

47 "Team:", 

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

49 ], 

50 [ 

51 "Hero:", 

52 { 

53 "age": 48, 

54 "id": 2, 

55 "secret_name": "Tommy Sharp", 

56 "team_id": 1, 

57 "name": "Rusty-Man", 

58 }, 

59 "Team:", 

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

61 ], 

62] 

63 

64 

65@needs_py310 1abcdefghij

66def test_tutorial001(): 1abcdefghij

67 from docs_src.tutorial.connect.select import tutorial001_py310 as mod 1klmnopqr

68 

69 mod.sqlite_url = "sqlite://" 1klmnopqr

70 mod.engine = create_engine(mod.sqlite_url) 1klmnopqr

71 calls = [] 1klmnopqr

72 

73 new_print = get_testing_print_function(calls) 1klmnopqr

74 

75 with patch("builtins.print", new=new_print): 1klmnopqr

76 mod.main() 1klmnopqr

77 assert calls == expected_calls 1klmnopqr

78 

79 

80@needs_py310 1abcdefghij

81def test_tutorial002(): 1abcdefghij

82 from docs_src.tutorial.connect.select import tutorial002_py310 as mod 1stuvwxyz

83 

84 mod.sqlite_url = "sqlite://" 1stuvwxyz

85 mod.engine = create_engine(mod.sqlite_url) 1stuvwxyz

86 calls = [] 1stuvwxyz

87 

88 new_print = get_testing_print_function(calls) 1stuvwxyz

89 

90 with patch("builtins.print", new=new_print): 1stuvwxyz

91 mod.main() 1stuvwxyz

92 assert calls == expected_calls 1stuvwxyz