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

13 statements  

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

1from unittest.mock import patch 1lghijk

2 

3from sqlmodel import create_engine 1lghijk

4 

5from ...conftest import get_testing_print_function 1lghijk

6 

7expected_calls = [ 1ghijk

8 [ 

9 "Deadpond:", 

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

11 ], 

12 [ 

13 "Deadpond teams:", 

14 [ 

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

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

17 ], 

18 ], 

19 [ 

20 "Rusty-Man:", 

21 {"id": 2, "secret_name": "Tommy Sharp", "age": 48, "name": "Rusty-Man"}, 

22 ], 

23 [ 

24 "Rusty-Man Teams:", 

25 [{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}], 

26 ], 

27 [ 

28 "Spider-Boy:", 

29 {"id": 3, "secret_name": "Pedro Parqueador", "age": None, "name": "Spider-Boy"}, 

30 ], 

31 [ 

32 "Spider-Boy Teams:", 

33 [{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}], 

34 ], 

35 [ 

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

37 [ 

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

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

40 ], 

41 ], 

42 [ 

43 "Z-Force heroes:", 

44 [ 

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

46 { 

47 "id": 3, 

48 "secret_name": "Pedro Parqueador", 

49 "age": None, 

50 "name": "Spider-Boy", 

51 }, 

52 ], 

53 ], 

54 [ 

55 "Reverted Z-Force's heroes:", 

56 [{"id": 1, "secret_name": "Dive Wilson", "age": None, "name": "Deadpond"}], 

57 ], 

58 [ 

59 "Reverted Spider-Boy's teams:", 

60 [{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}], 

61 ], 

62] 

63 

64 

65def test_tutorial(clear_sqlmodel): 1lghijk

66 from docs_src.tutorial.many_to_many import tutorial002 as mod 1abcdef

67 

68 mod.sqlite_url = "sqlite://" 1abcdef

69 mod.engine = create_engine(mod.sqlite_url) 1abcdef

70 calls = [] 1abcdef

71 

72 new_print = get_testing_print_function(calls) 1abcdef

73 

74 with patch("builtins.print", new=new_print): 1abcdef

75 mod.main() 1abcdef

76 assert calls == expected_calls 1abcdef