Coverage for tests / test_tutorial / test_many_to_many / test_tutorial003.py: 100%

18 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 dirty_equals import IsList 1abcdefghi

6from sqlalchemy import Engine 1abcdefghi

7 

8from ...conftest import PrintMock 1abcdefghi

9 

10 

11@pytest.fixture( 1abcdefghi

12 name="mod", 

13 params=[ 

14 pytest.param("tutorial003_py310"), 

15 ], 

16) 

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

18 mod = importlib.import_module(f"docs_src.tutorial.many_to_many.{request.param}") 1abcdefghi

19 mod.engine = database_engine 1abcdefghi

20 return mod 1abcdefghi

21 

22 

23expected_calls = [ 1abcdefghi

24 [ 

25 "Z-Force hero:", 

26 {"name": "Deadpond", "secret_name": "Dive Wilson", "id": 1, "age": None}, 

27 "is training:", 

28 False, 

29 ], 

30 [ 

31 "Preventers hero:", 

32 {"name": "Deadpond", "secret_name": "Dive Wilson", "id": 1, "age": None}, 

33 "is training:", 

34 True, 

35 ], 

36 [ 

37 "Preventers hero:", 

38 {"name": "Spider-Boy", "secret_name": "Pedro Parqueador", "id": 2, "age": None}, 

39 "is training:", 

40 True, 

41 ], 

42 [ 

43 "Preventers hero:", 

44 {"name": "Rusty-Man", "secret_name": "Tommy Sharp", "id": 3, "age": 48}, 

45 "is training:", 

46 False, 

47 ], 

48 [ 

49 "Updated Spider-Boy's Teams:", 

50 IsList( 

51 {"team_id": 2, "is_training": True, "hero_id": 2}, 

52 {"team_id": 1, "is_training": True, "hero_id": 2}, 

53 check_order=False, 

54 ), 

55 ], 

56 [ 

57 "Z-Force heroes:", 

58 IsList( 

59 {"team_id": 1, "is_training": False, "hero_id": 1}, 

60 {"team_id": 1, "is_training": True, "hero_id": 2}, 

61 check_order=False, 

62 ), 

63 ], 

64 [ 

65 "Spider-Boy team:", 

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

67 "is training:", 

68 False, 

69 ], 

70 [ 

71 "Spider-Boy team:", 

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

73 "is training:", 

74 True, 

75 ], 

76] 

77 

78 

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

80 mod.main() 1jklmnopqr

81 assert print_mock.calls[:1] == expected_calls[:1] 1jklmnopqr

82 assert print_mock.calls[1:4] == IsList(*expected_calls[1:4], check_order=False) 1jklmnopqr

83 assert print_mock.calls[4:6] == expected_calls[4:6] 1jklmnopqr

84 assert print_mock.calls[6:] == IsList(*expected_calls[6:], check_order=False) 1jklmnopqr