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

14 statements  

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

1from unittest.mock import patch 1idefgh

2 

3from sqlmodel import create_engine 1idefgh

4 

5from ...conftest import get_testing_print_function, needs_py310 1idefgh

6 

7expected_calls = [ 1defgh

8 [ 

9 "Z-Force hero:", 

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

11 "is training:", 

12 False, 

13 ], 

14 [ 

15 "Preventers hero:", 

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

17 "is training:", 

18 True, 

19 ], 

20 [ 

21 "Preventers hero:", 

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

23 "is training:", 

24 True, 

25 ], 

26 [ 

27 "Preventers hero:", 

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

29 "is training:", 

30 False, 

31 ], 

32 [ 

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

34 [ 

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

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

37 ], 

38 ], 

39 [ 

40 "Z-Force heroes:", 

41 [ 

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

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

44 ], 

45 ], 

46 [ 

47 "Spider-Boy team:", 

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

49 "is training:", 

50 False, 

51 ], 

52 [ 

53 "Spider-Boy team:", 

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

55 "is training:", 

56 True, 

57 ], 

58] 

59 

60 

61@needs_py310 1idefgh

62def test_tutorial(clear_sqlmodel): 1defgh

63 from docs_src.tutorial.many_to_many import tutorial003_py310 as mod 1abc

64 

65 mod.sqlite_url = "sqlite://" 1abc

66 mod.engine = create_engine(mod.sqlite_url) 1abc

67 calls = [] 1abc

68 

69 new_print = get_testing_print_function(calls) 1abc

70 

71 with patch("builtins.print", new=new_print): 1abc

72 mod.main() 1abc

73 assert calls == expected_calls 1abc