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

23 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-16 00:02 +0000

1import importlib 1abcdefghijklm

2from types import ModuleType 1abcdefghijklm

3from typing import Any 1abcdefghijklm

4 

5import pytest 1abcdefghijklm

6from sqlalchemy import Engine 1abcdefghijklm

7 

8from ...conftest import PrintMock 1abcdefghijklm

9 

10 

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

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

13 "name": "Deadpond", 

14 "secret_name": "Dive Wilson", 

15 "age": None, 

16 "id": 1, 

17 } 

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

19 "name": "Spider-Boy", 

20 "secret_name": "Pedro Parqueador", 

21 "age": None, 

22 "id": 2, 

23 } 

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

25 "name": "Rusty-Man", 

26 "secret_name": "Tommy Sharp", 

27 "age": 48, 

28 "id": 3, 

29 } 

30 

31 

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

33def get_module(request: pytest.FixtureRequest, database_engine: Engine) -> ModuleType: 1abcdefghijklm

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

35 module.engine = database_engine 1abcdefghijklm

36 return module 1abcdefghijklm

37 

38 

39@pytest.mark.parametrize( 1abcdefghijklm

40 "module", 

41 [ 

42 pytest.param("tutorial001"), 

43 ], 

44 indirect=True, 

45) 

46def test_tutorial_001(print_mock: PrintMock, module: ModuleType): 1abcdefghijklm

47 module.main() 1nprtvxzBDFHJL

48 check_calls(print_mock.calls) 1nprtvxzBDFHJL

49 

50 

51@pytest.mark.parametrize( 1abcdefghijklm

52 "module", 

53 [ 

54 pytest.param("tutorial002"), 

55 ], 

56 indirect=True, 

57) 

58def test_tutorial_002(print_mock: PrintMock, module: ModuleType): 1abcdefghijklm

59 module.main() 1oqsuwyACEGIKM

60 check_calls(print_mock.calls) 1oqsuwyACEGIKM