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

16 statements  

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

1import importlib 1abcdefghi

2from decimal import Decimal 1abcdefghi

3from types import ModuleType 1abcdefghi

4 

5import pytest 1abcdefghi

6from sqlmodel import create_engine 1abcdefghi

7 

8from ...conftest import PrintMock, needs_py310 1abcdefghi

9 

10 

11@pytest.fixture( 1abcdefghi

12 name="mod", 

13 params=[ 

14 pytest.param("tutorial001_py39"), 

15 pytest.param("tutorial001_py310", marks=needs_py310), 

16 ], 

17) 

18def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghi

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

20 mod.sqlite_url = "sqlite://" 1abcdefghi

21 mod.engine = create_engine(mod.sqlite_url) 1abcdefghi

22 return mod 1abcdefghi

23 

24 

25expected_calls = [ 1abcdefghi

26 [ 

27 "Hero 1:", 

28 { 

29 "name": "Deadpond", 

30 "age": None, 

31 "id": 1, 

32 "secret_name": "Dive Wilson", 

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

34 }, 

35 ], 

36 [ 

37 "Hero 2:", 

38 { 

39 "name": "Rusty-Man", 

40 "age": 48, 

41 "id": 3, 

42 "secret_name": "Tommy Sharp", 

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

44 }, 

45 ], 

46 ["Total money: 3.300"], 

47] 

48 

49 

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

51 mod.main() 1jklmnopqr

52 assert print_mock.calls == expected_calls 1jklmnopqr