Coverage for tests/test_tutorial/test_update/test_tutorial001_tutorial002.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-07 05:42 +0000

1from unittest.mock import patch 1uopqrst

2 

3from sqlmodel import create_engine 1uopqrst

4 

5from ...conftest import get_testing_print_function 1uopqrst

6 

7expected_calls = [ 1opqrst

8 [ 

9 "Hero:", 

10 { 

11 "id": 2, 

12 "name": "Spider-Boy", 

13 "secret_name": "Pedro Parqueador", 

14 "age": None, 

15 }, 

16 ], 

17 [ 

18 "Updated hero:", 

19 { 

20 "id": 2, 

21 "name": "Spider-Boy", 

22 "secret_name": "Pedro Parqueador", 

23 "age": 16, 

24 }, 

25 ], 

26] 

27 

28 

29def test_tutorial001(clear_sqlmodel): 1uopqrst

30 from docs_src.tutorial.update import tutorial001 as mod 1abcdefg

31 

32 mod.sqlite_url = "sqlite://" 1abcdefg

33 mod.engine = create_engine(mod.sqlite_url) 1abcdefg

34 calls = [] 1abcdefg

35 

36 new_print = get_testing_print_function(calls) 1abcdefg

37 

38 with patch("builtins.print", new=new_print): 1abcdefg

39 mod.main() 1abcdefg

40 assert calls == expected_calls 1abcdefg

41 

42 

43def test_tutorial002(clear_sqlmodel): 1uopqrst

44 from docs_src.tutorial.update import tutorial002 as mod 1hijklmn

45 

46 mod.sqlite_url = "sqlite://" 1hijklmn

47 mod.engine = create_engine(mod.sqlite_url) 1hijklmn

48 calls = [] 1hijklmn

49 

50 new_print = get_testing_print_function(calls) 1hijklmn

51 

52 with patch("builtins.print", new=new_print): 1hijklmn

53 mod.main() 1hijklmn

54 assert calls == expected_calls 1hijklmn