Coverage for tests / test_tutorial / test_relationship_attributes / test_read_relationships / test_tutorial001.py: 100%

15 statements  

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

1import importlib 1abcdefgh

2from types import ModuleType 1abcdefgh

3 

4import pytest 1abcdefgh

5from sqlmodel import create_engine 1abcdefgh

6 

7from ....conftest import PrintMock 1abcdefgh

8 

9 

10@pytest.fixture( 1abcdefgh

11 name="mod", 

12 params=[ 

13 pytest.param("tutorial001_py310"), 

14 ], 

15) 

16def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefgh

17 mod = importlib.import_module( 1abcdefgh

18 f"docs_src.tutorial.relationship_attributes.read_relationships.{request.param}" 

19 ) 

20 mod.sqlite_url = "sqlite://" 1abcdefgh

21 mod.engine = create_engine(mod.sqlite_url) 1abcdefgh

22 return mod 1abcdefgh

23 

24 

25expected_calls = [ 1abcdefgh

26 [ 

27 "Created hero:", 

28 { 

29 "age": None, 

30 "id": 1, 

31 "secret_name": "Dive Wilson", 

32 "team_id": 1, 

33 "name": "Deadpond", 

34 }, 

35 ], 

36 [ 

37 "Created hero:", 

38 { 

39 "age": 48, 

40 "id": 2, 

41 "secret_name": "Tommy Sharp", 

42 "team_id": 2, 

43 "name": "Rusty-Man", 

44 }, 

45 ], 

46 [ 

47 "Created hero:", 

48 { 

49 "age": None, 

50 "id": 3, 

51 "secret_name": "Pedro Parqueador", 

52 "team_id": None, 

53 "name": "Spider-Boy", 

54 }, 

55 ], 

56 [ 

57 "Updated hero:", 

58 { 

59 "age": None, 

60 "id": 3, 

61 "secret_name": "Pedro Parqueador", 

62 "team_id": 2, 

63 "name": "Spider-Boy", 

64 }, 

65 ], 

66 [ 

67 "Team Wakaland:", 

68 {"headquarters": "Wakaland Capital City", "id": 3, "name": "Wakaland"}, 

69 ], 

70 [ 

71 "Preventers new hero:", 

72 { 

73 "age": 32, 

74 "id": 6, 

75 "secret_name": "Natalia Roman-on", 

76 "team_id": 2, 

77 "name": "Tarantula", 

78 }, 

79 ], 

80 [ 

81 "Preventers new hero:", 

82 { 

83 "age": 36, 

84 "id": 7, 

85 "secret_name": "Steve Weird", 

86 "team_id": 2, 

87 "name": "Dr. Weird", 

88 }, 

89 ], 

90 [ 

91 "Preventers new hero:", 

92 { 

93 "age": 93, 

94 "id": 8, 

95 "secret_name": "Esteban Rogelios", 

96 "team_id": 2, 

97 "name": "Captain North America", 

98 }, 

99 ], 

100 [ 

101 "Spider-Boy's team:", 

102 {"headquarters": "Sharp Tower", "id": 2, "name": "Preventers"}, 

103 ], 

104 [ 

105 "Spider-Boy's team again:", 

106 {"headquarters": "Sharp Tower", "id": 2, "name": "Preventers"}, 

107 ], 

108] 

109 

110 

111def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefgh

112 mod.main() 1ijklmnop

113 assert print_mock.calls == expected_calls 1ijklmnop