Coverage for tests / test_advanced / test_uuid / test_tutorial001.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-01-06 21:09 +0000

1import importlib 1abcdefghi

2from types import ModuleType 1abcdefghi

3 

4import pytest 1abcdefghi

5from dirty_equals import IsUUID 1abcdefghi

6from sqlmodel import create_engine 1abcdefghi

7 

8from ...conftest import PrintMock, needs_py310 1abcdefghi

9 

10 

11@pytest.fixture( 1abcdefghi

12 name="mod", 

13 params=[ 

14 pytest.param("tutorial001_py39"), 

15 pytest.param("tutorial001_py310", marks=needs_py310), 

16 ], 

17) 

18def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghi

19 mod = importlib.import_module(f"docs_src.advanced.uuid.{request.param}") 1abcdefghi

20 mod.sqlite_url = "sqlite://" 1abcdefghi

21 mod.engine = create_engine(mod.sqlite_url) 1abcdefghi

22 return mod 1abcdefghi

23 

24 

25def test_tutorial(print_mock: PrintMock, mod: ModuleType) -> None: 1abcdefghi

26 mod.main() 1jklmnopqr

27 first_uuid = print_mock.calls[1][0]["id"] 1jklmnopqr

28 assert first_uuid == IsUUID(4) 1jklmnopqr

29 

30 second_uuid = print_mock.calls[7][0]["id"] 1jklmnopqr

31 assert second_uuid == IsUUID(4) 1jklmnopqr

32 

33 assert first_uuid != second_uuid 1jklmnopqr

34 

35 assert print_mock.calls == [ 1jklmnopqr

36 ["The hero before saving in the DB"], 

37 [ 

38 { 

39 "name": "Deadpond", 

40 "secret_name": "Dive Wilson", 

41 "id": first_uuid, 

42 "age": None, 

43 } 

44 ], 

45 ["The hero ID was already set"], 

46 [first_uuid], 

47 ["After saving in the DB"], 

48 [ 

49 { 

50 "name": "Deadpond", 

51 "secret_name": "Dive Wilson", 

52 "age": None, 

53 "id": first_uuid, 

54 } 

55 ], 

56 ["Created hero:"], 

57 [ 

58 { 

59 "name": "Spider-Boy", 

60 "secret_name": "Pedro Parqueador", 

61 "age": None, 

62 "id": second_uuid, 

63 } 

64 ], 

65 ["Created hero ID:"], 

66 [second_uuid], 

67 ["Selected hero:"], 

68 [ 

69 { 

70 "name": "Spider-Boy", 

71 "secret_name": "Pedro Parqueador", 

72 "age": None, 

73 "id": second_uuid, 

74 } 

75 ], 

76 ["Selected hero ID:"], 

77 [second_uuid], 

78 ]