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

15 statements  

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

1import importlib 1abcdefghi

2from decimal import Decimal 1abcdefghi

3from types import ModuleType 1abcdefghi

4 

5import pytest 1abcdefghi

6from sqlalchemy import Engine 1abcdefghi

7 

8from ...conftest import PrintMock 1abcdefghi

9 

10 

11@pytest.fixture( 1abcdefghi

12 name="mod", 

13 params=[ 

14 pytest.param("tutorial001_py310"), 

15 ], 

16) 

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

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

19 mod.engine = database_engine 1abcdefghi

20 return mod 1abcdefghi

21 

22 

23expected_calls = [ 1abcdefghi

24 [ 

25 "Hero 1:", 

26 { 

27 "name": "Deadpond", 

28 "age": None, 

29 "id": 1, 

30 "secret_name": "Dive Wilson", 

31 "money": Decimal("1.100"), 

32 }, 

33 ], 

34 [ 

35 "Hero 2:", 

36 { 

37 "name": "Rusty-Man", 

38 "age": 48, 

39 "id": 3, 

40 "secret_name": "Tommy Sharp", 

41 "money": Decimal("2.200"), 

42 }, 

43 ], 

44 ["Total money: 3.300"], 

45] 

46 

47 

48def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefghi

49 mod.main() 1jklmnopqr

50 assert print_mock.calls == expected_calls 1jklmnopqr