File: test_integer.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 (149 lines) | stat: -rw-r--r-- 6,169 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""

import pytest

import typepy

from ._common import convert_wrapper


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


class Test_Integer:
    @pytest.mark.parametrize(
        ["method", "strict_level", "value", "expected"],
        [
            ["convert", 0, 1, 1],
            ["convert", 0, 1.0, 1],
            ["convert", 0, 1.1, 1],
            ["convert", 0, "0", 0],
            ["convert", 0, "1.0", 1],
            ["convert", 0, "1.1", 1],
            ["convert", 0, 9223372036854775807, 9223372036854775807],
            ["convert", 0, "1,000,000,000,000", 1000000000000],
            ["convert", 0, True, 1],
            ["convert", 0, None, "E"],
            ["convert", 0, inf, "E"],
            ["convert", 0, nan, "E"],
            ["convert", 0, "test", "E"],
            ["convert", 0, "", "E"],
            ["convert", 1, 1, 1],
            ["convert", 1, 1.0, 1],
            ["convert", 1, 1.1, "E"],
            ["convert", 1, "0", 0],
            ["convert", 1, "1.0", 1],
            ["convert", 1, "1.1", "E"],
            ["convert", 1, 9223372036854775807, 9223372036854775807],
            ["convert", 1, "1,000,000,000,000", 1000000000000],
            ["convert", 1, True, "E"],
            ["convert", 1, None, "E"],
            ["convert", 1, inf, "E"],
            ["convert", 1, nan, "E"],
            ["convert", 1, "test", "E"],
            ["convert", 1, "", "E"],
            ["convert", 2, 1, 1],
            ["convert", 2, 1.0, "E"],
            ["convert", 2, 1.1, "E"],
            ["convert", 2, "0", "E"],
            ["convert", 2, "1.0", "E"],
            ["convert", 2, "1.1", "E"],
            ["convert", 2, 9223372036854775807, 9223372036854775807],
            ["convert", 2, "1,000,000,000,000", "E"],
            ["convert", 2, True, "E"],
            ["convert", 2, None, "E"],
            ["convert", 2, inf, "E"],
            ["convert", 2, nan, "E"],
            ["convert", 2, "test", "E"],
            ["convert", 2, "", "E"],
            ["try_convert", 0, 1, 1],
            ["try_convert", 0, 1.0, 1],
            ["try_convert", 0, 1.1, 1],
            ["try_convert", 0, "0", 0],
            ["try_convert", 0, "1.0", 1],
            ["try_convert", 0, "1.1", 1],
            ["try_convert", 0, 9223372036854775807, 9223372036854775807],
            ["try_convert", 0, "1,000,000,000,000", 1000000000000],
            ["try_convert", 0, True, 1],
            ["try_convert", 0, None, None],
            ["try_convert", 0, inf, None],
            ["try_convert", 0, nan, None],
            ["try_convert", 0, "test", None],
            ["try_convert", 0, "", None],
            ["try_convert", 1, 1, 1],
            ["try_convert", 1, 1.0, 1],
            ["try_convert", 1, 1.1, None],
            ["try_convert", 1, "0", 0],
            ["try_convert", 1, "1.0", 1],
            ["try_convert", 1, "1.1", None],
            ["try_convert", 1, 9223372036854775807, 9223372036854775807],
            ["try_convert", 1, "1,000,000,000,000", 1000000000000],
            ["try_convert", 1, True, None],
            ["try_convert", 1, None, None],
            ["try_convert", 1, inf, None],
            ["try_convert", 1, nan, None],
            ["try_convert", 1, "test", None],
            ["try_convert", 1, "", None],
            ["try_convert", 2, 1, 1],
            ["try_convert", 2, 1.0, None],
            ["try_convert", 2, 1.1, None],
            ["try_convert", 2, "0", None],
            ["try_convert", 2, "1.0", None],
            ["try_convert", 2, "1.1", None],
            ["try_convert", 2, 9223372036854775807, 9223372036854775807],
            ["try_convert", 2, "1,000,000,000,000", None],
            ["try_convert", 2, True, None],
            ["try_convert", 2, None, None],
            ["try_convert", 2, inf, None],
            ["try_convert", 2, nan, None],
            ["try_convert", 2, "test", None],
            ["try_convert", 2, "", None],
            ["force_convert", 0, 1, 1],
            ["force_convert", 0, 1.0, 1],
            ["force_convert", 0, 1.1, 1],
            ["force_convert", 0, "0", 0],
            ["force_convert", 0, "1.0", 1],
            ["force_convert", 0, "1.1", 1],
            ["force_convert", 0, 9223372036854775807, 9223372036854775807],
            ["force_convert", 0, "1,000,000,000,000", 1000000000000],
            ["force_convert", 0, True, 1],
            ["force_convert", 0, None, "E"],
            ["force_convert", 0, inf, "E"],
            ["force_convert", 0, nan, "E"],
            ["force_convert", 0, "test", "E"],
            ["force_convert", 0, "", "E"],
            ["force_convert", 1, 1, 1],
            ["force_convert", 1, 1.0, 1],
            ["force_convert", 1, 1.1, 1],
            ["force_convert", 1, "0", 0],
            ["force_convert", 1, "1.0", 1],
            ["force_convert", 1, "1.1", 1],
            ["force_convert", 1, 9223372036854775807, 9223372036854775807],
            ["force_convert", 1, "1,000,000,000,000", 1000000000000],
            ["force_convert", 1, True, 1],
            ["force_convert", 1, None, "E"],
            ["force_convert", 1, inf, "E"],
            ["force_convert", 1, nan, "E"],
            ["force_convert", 1, "test", "E"],
            ["force_convert", 1, "", "E"],
            ["force_convert", 2, 1, 1],
            ["force_convert", 2, 1.0, 1],
            ["force_convert", 2, 1.1, 1],
            ["force_convert", 2, "0", 0],
            ["force_convert", 2, "1.0", 1],
            ["force_convert", 2, "1.1", 1],
            ["force_convert", 2, 9223372036854775807, 9223372036854775807],
            ["force_convert", 2, "1,000,000,000,000", 1000000000000],
            ["force_convert", 2, True, 1],
            ["force_convert", 2, None, "E"],
            ["force_convert", 2, inf, "E"],
            ["force_convert", 2, nan, "E"],
            ["force_convert", 2, "test", "E"],
            ["force_convert", 2, "", "E"],
        ],
    )
    def test_normal(self, method, strict_level, value, expected):
        assert convert_wrapper(typepy.Integer(value, strict_level), method) == expected