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

24 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

3from typing import Any 1abcdefgh

4 

5import pytest 1abcdefgh

6from sqlmodel import create_engine 1abcdefgh

7 

8from ...conftest import PrintMock 1abcdefgh

9 

10 

11def check_calls(calls: list[list[str | dict[str, Any]]]): 1abcdefgh

12 assert calls[0][0] == { 1ijklmnopqrstuvwx

13 "name": "Deadpond", 

14 "secret_name": "Dive Wilson", 

15 "age": None, 

16 "id": 1, 

17 } 

18 assert calls[1][0] == { 1ijklmnopqrstuvwx

19 "name": "Spider-Boy", 

20 "secret_name": "Pedro Parqueador", 

21 "age": None, 

22 "id": 2, 

23 } 

24 assert calls[2][0] == { 1ijklmnopqrstuvwx

25 "name": "Rusty-Man", 

26 "secret_name": "Tommy Sharp", 

27 "age": 48, 

28 "id": 3, 

29 } 

30 

31 

32@pytest.fixture(name="module") 1abcdefgh

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

34 module = importlib.import_module(f"docs_src.tutorial.select.{request.param}") 1abcdefgh

35 module.sqlite_url = "sqlite://" 1abcdefgh

36 module.engine = create_engine(module.sqlite_url) 1abcdefgh

37 return module 1abcdefgh

38 

39 

40@pytest.mark.parametrize( 1abcdefgh

41 "module", 

42 [ 

43 pytest.param("tutorial001_py310"), 

44 ], 

45 indirect=True, 

46) 

47def test_tutorial_001(print_mock: PrintMock, module: ModuleType): 1abcdefgh

48 module.main() 1ikmoqsuw

49 check_calls(print_mock.calls) 1ikmoqsuw

50 

51 

52@pytest.mark.parametrize( 1abcdefgh

53 "module", 

54 [ 

55 pytest.param("tutorial002_py310"), 

56 ], 

57 indirect=True, 

58) 

59def test_tutorial_002(print_mock: PrintMock, module: ModuleType): 1abcdefgh

60 module.main() 1jlnprtvx

61 check_calls(print_mock.calls) 1jlnprtvx