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

14 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("tutorial003_py310"), 

14 ], 

15) 

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

17 mod = importlib.import_module( 1abcdefgh

18 f"docs_src.tutorial.relationship_attributes.cascade_delete_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 

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

26 mod.main() 1ijklmnop

27 assert print_mock.calls == [ 1ijklmnop

28 [ 

29 "Created hero:", 

30 { 

31 "age": None, 

32 "id": 1, 

33 "name": "Deadpond", 

34 "secret_name": "Dive Wilson", 

35 "team_id": 1, 

36 }, 

37 ], 

38 [ 

39 "Created hero:", 

40 { 

41 "age": 48, 

42 "id": 2, 

43 "name": "Rusty-Man", 

44 "secret_name": "Tommy Sharp", 

45 "team_id": 2, 

46 }, 

47 ], 

48 [ 

49 "Created hero:", 

50 { 

51 "age": None, 

52 "id": 3, 

53 "name": "Spider-Boy", 

54 "secret_name": "Pedro Parqueador", 

55 "team_id": None, 

56 }, 

57 ], 

58 [ 

59 "Updated hero:", 

60 { 

61 "age": None, 

62 "id": 3, 

63 "name": "Spider-Boy", 

64 "secret_name": "Pedro Parqueador", 

65 "team_id": 2, 

66 }, 

67 ], 

68 [ 

69 "Team Wakaland:", 

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

71 ], 

72 [ 

73 "Deleted team:", 

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

75 ], 

76 [ 

77 "Black Lion has no team:", 

78 { 

79 "age": 35, 

80 "id": 4, 

81 "name": "Black Lion", 

82 "secret_name": "Trevor Challa", 

83 "team_id": None, 

84 }, 

85 ], 

86 [ 

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

88 { 

89 "age": None, 

90 "id": 5, 

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

92 "secret_name": "Sure-E", 

93 "team_id": None, 

94 }, 

95 ], 

96 ]