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

14 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-11-09 00:02 +0000

1import importlib 1abcdefghi

2from types import ModuleType 1abcdefghi

3 

4import pytest 1abcdefghi

5from sqlalchemy import Engine 1abcdefghi

6 

7from ....conftest import PrintMock 1abcdefghi

8 

9 

10@pytest.fixture( 1abcdefghi

11 name="mod", 

12 params=[ 

13 pytest.param("tutorial001_py310"), 

14 ], 

15) 

16def get_module(request: pytest.FixtureRequest, database_engine: Engine) -> ModuleType: 1abcdefghi

17 mod = importlib.import_module( 1abcdefghi

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

19 ) 

20 mod.engine = database_engine 1abcdefghi

21 return mod 1abcdefghi

22 

23 

24expected_calls = [ 1abcdefghi

25 [ 

26 "Created hero:", 

27 { 

28 "age": None, 

29 "id": 1, 

30 "secret_name": "Dive Wilson", 

31 "team_id": 1, 

32 "name": "Deadpond", 

33 }, 

34 ], 

35 [ 

36 "Created hero:", 

37 { 

38 "age": 48, 

39 "id": 2, 

40 "secret_name": "Tommy Sharp", 

41 "team_id": 2, 

42 "name": "Rusty-Man", 

43 }, 

44 ], 

45 [ 

46 "Created hero:", 

47 { 

48 "age": None, 

49 "id": 3, 

50 "secret_name": "Pedro Parqueador", 

51 "team_id": None, 

52 "name": "Spider-Boy", 

53 }, 

54 ], 

55 [ 

56 "Updated hero:", 

57 { 

58 "age": None, 

59 "id": 3, 

60 "secret_name": "Pedro Parqueador", 

61 "team_id": 2, 

62 "name": "Spider-Boy", 

63 }, 

64 ], 

65 [ 

66 "Team Wakaland:", 

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

68 ], 

69 [ 

70 "Preventers new hero:", 

71 { 

72 "age": 32, 

73 "id": 6, 

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

75 "team_id": 2, 

76 "name": "Tarantula", 

77 }, 

78 ], 

79 [ 

80 "Preventers new hero:", 

81 { 

82 "age": 36, 

83 "id": 7, 

84 "secret_name": "Steve Weird", 

85 "team_id": 2, 

86 "name": "Dr. Weird", 

87 }, 

88 ], 

89 [ 

90 "Preventers new hero:", 

91 { 

92 "age": 93, 

93 "id": 8, 

94 "secret_name": "Esteban Rogelios", 

95 "team_id": 2, 

96 "name": "Captain North America", 

97 }, 

98 ], 

99] 

100 

101 

102def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefghi

103 mod.main() 1jklmnopqr

104 assert print_mock.calls == expected_calls 1jklmnopqr