Coverage for tests \ test_cast.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-12 14:00 +0200

1# ruff: noqa: S101, PLR0913 

2 

3from decimal import Decimal 

4 

5import pytest 

6from syriantaxes.cast import cast_to_decimal 

7from syriantaxes.types import Number 

8 

9 

10@pytest.mark.parametrize( 

11 "value, expected", 

12 [ 

13 (100, Decimal("100.00")), 

14 (-100, Decimal("-100.00")), 

15 (Decimal("100.00"), Decimal("100.00")), 

16 (Decimal("-100.00"), Decimal("-100.00")), 

17 ("100.00", Decimal("100.00")), 

18 ("-100.00", Decimal("-100.00")), 

19 (100.22, Decimal("100.22")), 

20 (-100.22, Decimal("-100.22")), 

21 ], 

22) 

23def test_cast_to_decimal_with_number_valid_inputs( 

24 value: Number, expected: Decimal 

25) -> None: 

26 assert isinstance(cast_to_decimal(value), Decimal) 

27 assert cast_to_decimal(value) == expected 

28 

29 

30@pytest.mark.parametrize( 

31 "value", 

32 [ 

33 {"a": 100}, 

34 [1, 2], 

35 (1, 3), 

36 {1, 2}, 

37 ], 

38) 

39def test_cast_to_decimal_with_number_invalid_inputs(value: Number) -> None: 

40 with pytest.raises(TypeError): 

41 cast_to_decimal(value) 

42 

43 

44@pytest.mark.parametrize( 

45 "value, lt, gt, lte, gte, expected", 

46 [ 

47 (100, 0, None, None, None, Decimal("100.00")), 

48 (0, 0, None, None, None, Decimal(0)), 

49 (1, 0, 1, None, None, Decimal(1)), 

50 (0.1, None, None, 0, 1, Decimal("0.1")), 

51 (50.01, None, None, 50, 100, Decimal("50.01")), 

52 (50.01, 50, 100, 50, 100, Decimal("50.01")), 

53 ], 

54) 

55def test_cast_to_decimal_with_validators_valid_inputs( 

56 value: Number, 

57 lt: Number | None, 

58 gt: Number | None, 

59 lte: Number | None, 

60 gte: Number | None, 

61 expected: Decimal, 

62) -> None: 

63 assert cast_to_decimal(value, lt=lt, gt=gt, lte=lte, gte=gte) == expected