File: test_checker_infinite.py

package info (click to toggle)
python-typepy 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 624 kB
  • sloc: python: 2,886; makefile: 78; sh: 7
file content (44 lines) | stat: -rw-r--r-- 1,195 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""

import itertools
import sys
from decimal import Decimal

import pytest

from typepy import Infinity, StrictLevel, Typecode


nan = float("nan")
inf = float("inf")


class Test_Infinity_is_type:
    @pytest.mark.parametrize(
        ["value", "strict_level", "expected"],
        list(
            itertools.product(
                [0.0, sys.maxsize, "0", nan, None], [StrictLevel.MIN, StrictLevel.MAX], [False]
            )
        )
        + list(
            itertools.product(
                [inf, Decimal("infinity")], [StrictLevel.MIN, StrictLevel.MAX], [True]
            )
        )
        + [
            ["inf", StrictLevel.MIN, True],
            ["inf", StrictLevel.MAX, False],
            ["-infinity", StrictLevel.MIN, True],
            ["-infinity", StrictLevel.MAX, False],
            ["INF", StrictLevel.MIN, True],
            ["INF", StrictLevel.MAX, False],
        ],
    )
    def test_normal(self, value, strict_level, expected):
        type_checker = Infinity(value, strict_level)

        assert type_checker.is_type() == expected
        assert type_checker.typecode == Typecode.INFINITY