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

22 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 { 

14 "name": "Deadpond", 

15 "secret_name": "Dive Wilson", 

16 "age": None, 

17 "id": 1, 

18 }, 

19 { 

20 "name": "Spider-Boy", 

21 "secret_name": "Pedro Parqueador", 

22 "age": None, 

23 "id": 2, 

24 }, 

25 { 

26 "name": "Rusty-Man", 

27 "secret_name": "Tommy Sharp", 

28 "age": 48, 

29 "id": 3, 

30 }, 

31 ] 

32 

33 

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

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

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

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

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

39 return module 1abcdefgh

40 

41 

42@pytest.mark.parametrize( 1abcdefgh

43 "module", 

44 [ 

45 pytest.param("tutorial003_py310"), 

46 ], 

47 indirect=True, 

48) 

49def test_tutorial_003(print_mock: PrintMock, module: ModuleType): 1abcdefgh

50 module.main() 1ikmoqsuw

51 check_calls(print_mock.calls) 1ikmoqsuw

52 

53 

54@pytest.mark.parametrize( 1abcdefgh

55 "module", 

56 [ 

57 pytest.param("tutorial004_py310"), 

58 ], 

59 indirect=True, 

60) 

61def test_tutorial_004(print_mock: PrintMock, module: ModuleType): 1abcdefgh

62 module.main() 1jlnprtvx

63 check_calls(print_mock.calls) 1jlnprtvx