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

20 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-01-06 21:09 +0000

1import importlib 1abcdefghi

2from types import ModuleType 1abcdefghi

3 

4import pytest 1abcdefghi

5from sqlmodel import create_engine 1abcdefghi

6 

7from ....conftest import PrintMock, needs_py310 1abcdefghi

8 

9expected_calls = [ 1abcdefghi

10 [ 

11 "Created hero:", 

12 { 

13 "age": None, 

14 "id": 1, 

15 "secret_name": "Dive Wilson", 

16 "team_id": 2, 

17 "name": "Deadpond", 

18 }, 

19 ], 

20 [ 

21 "Created hero:", 

22 { 

23 "age": 48, 

24 "id": 2, 

25 "secret_name": "Tommy Sharp", 

26 "team_id": 1, 

27 "name": "Rusty-Man", 

28 }, 

29 ], 

30 [ 

31 "Created hero:", 

32 { 

33 "age": None, 

34 "id": 3, 

35 "secret_name": "Pedro Parqueador", 

36 "team_id": None, 

37 "name": "Spider-Boy", 

38 }, 

39 ], 

40 [ 

41 "Hero:", 

42 { 

43 "age": None, 

44 "id": 1, 

45 "secret_name": "Dive Wilson", 

46 "team_id": 2, 

47 "name": "Deadpond", 

48 }, 

49 "Team:", 

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

51 ], 

52 [ 

53 "Hero:", 

54 { 

55 "age": 48, 

56 "id": 2, 

57 "secret_name": "Tommy Sharp", 

58 "team_id": 1, 

59 "name": "Rusty-Man", 

60 }, 

61 "Team:", 

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

63 ], 

64] 

65 

66 

67@pytest.fixture(name="module") 1abcdefghi

68def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghi

69 module = importlib.import_module( 1abcdefghi

70 f"docs_src.tutorial.connect.select.{request.param}" 

71 ) 

72 module.sqlite_url = "sqlite://" 1abcdefghi

73 module.engine = create_engine(module.sqlite_url) 1abcdefghi

74 return module 1abcdefghi

75 

76 

77@pytest.mark.parametrize( 1abcdefghi

78 "module", 

79 [ 

80 "tutorial001_py39", 

81 pytest.param("tutorial001_py310", marks=needs_py310), 

82 ], 

83 indirect=True, 

84) 

85def test_tutorial001(print_mock: PrintMock, module: ModuleType): 1abcdefghi

86 module.main() 1jklmnopqr

87 assert print_mock.calls == expected_calls 1jklmnopqr

88 

89 

90@pytest.mark.parametrize( 1abcdefghi

91 "module", 

92 [ 

93 "tutorial002_py39", 

94 pytest.param("tutorial002_py310", marks=needs_py310), 

95 ], 

96 indirect=True, 

97) 

98def test_tutorial002(print_mock: PrintMock, module: ModuleType): 1abcdefghi

99 module.main() 1stuvwxyzA

100 assert print_mock.calls == expected_calls 1stuvwxyzA