Coverage for tests / test_tutorial / test_relationship_attributes / test_delete_records_relationship / test_tutorial002.py: 100%

13 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("tutorial002_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.cascade_delete_relationships.{request.param}" 

19 ) 

20 mod.engine = database_engine 1abcdefghi

21 return mod 1abcdefghi

22 

23 

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

25 mod.main() 1jklmnopqr

26 assert print_mock.calls == [ 1jklmnopqr

27 [ 

28 "Created hero:", 

29 { 

30 "age": None, 

31 "id": 1, 

32 "name": "Deadpond", 

33 "secret_name": "Dive Wilson", 

34 "team_id": 1, 

35 }, 

36 ], 

37 [ 

38 "Created hero:", 

39 { 

40 "age": 48, 

41 "id": 2, 

42 "name": "Rusty-Man", 

43 "secret_name": "Tommy Sharp", 

44 "team_id": 2, 

45 }, 

46 ], 

47 [ 

48 "Created hero:", 

49 { 

50 "age": None, 

51 "id": 3, 

52 "name": "Spider-Boy", 

53 "secret_name": "Pedro Parqueador", 

54 "team_id": None, 

55 }, 

56 ], 

57 [ 

58 "Updated hero:", 

59 { 

60 "age": None, 

61 "id": 3, 

62 "name": "Spider-Boy", 

63 "secret_name": "Pedro Parqueador", 

64 "team_id": 2, 

65 }, 

66 ], 

67 [ 

68 "Team Wakaland:", 

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

70 ], 

71 [ 

72 "Deleted team:", 

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

74 ], 

75 [ 

76 "Black Lion has no team:", 

77 { 

78 "age": 35, 

79 "id": 4, 

80 "name": "Black Lion", 

81 "secret_name": "Trevor Challa", 

82 "team_id": None, 

83 }, 

84 ], 

85 [ 

86 "Princess Sure-E has no team:", 

87 { 

88 "age": None, 

89 "id": 5, 

90 "name": "Princess Sure-E", 

91 "secret_name": "Sure-E", 

92 "team_id": None, 

93 }, 

94 ], 

95 ]