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

20 statements  

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

1import importlib 1abcdefgh

2from types import ModuleType 1abcdefgh

3 

4import pytest 1abcdefgh

5from dirty_equals import IsUUID 1abcdefgh

6from sqlmodel import create_engine 1abcdefgh

7 

8from ...conftest import PrintMock 1abcdefgh

9 

10 

11@pytest.fixture( 1abcdefgh

12 name="mod", 

13 params=[ 

14 pytest.param("tutorial001_py310"), 

15 ], 

16) 

17def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefgh

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

19 mod.sqlite_url = "sqlite://" 1abcdefgh

20 mod.engine = create_engine(mod.sqlite_url) 1abcdefgh

21 return mod 1abcdefgh

22 

23 

24def test_tutorial(print_mock: PrintMock, mod: ModuleType) -> None: 1abcdefgh

25 mod.main() 1ijklmnop

26 first_uuid = print_mock.calls[1][0]["id"] 1ijklmnop

27 assert first_uuid == IsUUID(4) 1ijklmnop

28 

29 second_uuid = print_mock.calls[7][0]["id"] 1ijklmnop

30 assert second_uuid == IsUUID(4) 1ijklmnop

31 

32 assert first_uuid != second_uuid 1ijklmnop

33 

34 assert print_mock.calls == [ 1ijklmnop

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

36 [ 

37 { 

38 "name": "Deadpond", 

39 "secret_name": "Dive Wilson", 

40 "id": first_uuid, 

41 "age": None, 

42 } 

43 ], 

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

45 [first_uuid], 

46 ["After saving in the DB"], 

47 [ 

48 { 

49 "name": "Deadpond", 

50 "secret_name": "Dive Wilson", 

51 "age": None, 

52 "id": first_uuid, 

53 } 

54 ], 

55 ["Created hero:"], 

56 [ 

57 { 

58 "name": "Spider-Boy", 

59 "secret_name": "Pedro Parqueador", 

60 "age": None, 

61 "id": second_uuid, 

62 } 

63 ], 

64 ["Created hero ID:"], 

65 [second_uuid], 

66 ["Selected hero:"], 

67 [ 

68 { 

69 "name": "Spider-Boy", 

70 "secret_name": "Pedro Parqueador", 

71 "age": None, 

72 "id": second_uuid, 

73 } 

74 ], 

75 ["Selected hero ID:"], 

76 [second_uuid], 

77 ]