File: test_example_mypy.py

package info (click to toggle)
pytest-check 2.7.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 480 kB
  • sloc: python: 2,220; sh: 17; makefile: 6
file content (184 lines) | stat: -rw-r--r-- 3,901 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"""
Used by mypy to make sure that the type annotations are correct.

Normally you would import the check functions like this:
    from pytest_check import check

We're testing that an old form of import also works:
    import pytest_check as check

However, please be aware that this method of importing is deprecated and
support may be removed in future versions.

The original content of this file is from test_example_functions_pass.py.
But I've also added more tests to check for anything I want to get
tested with `mypy --strict`.
"""

import math
import importlib
from typing import Any
import pytest
import pytest_check as check

try:
    np: Any = importlib.import_module("numpy")
except ModuleNotFoundError:
    np = None


def test_equal() -> None:
    check.equal(1, 1)


def test_not_equal() -> None:
    check.not_equal(1, 2)


def test_is() -> None:
    x = ["foo"]
    y = x
    check.is_(x, y)


def test_is_nan() -> None:
    check.is_nan(math.nan)


def test_is_not_nan() -> None:
    check.is_not_nan(0)


def test_is_not() -> None:
    x = ["foo"]
    y = ["foo"]
    check.is_not(x, y)


def test_is_true() -> None:
    check.is_true(True)


def test_is_false() -> None:
    check.is_false(False)


def test_is_none() -> None:
    a = None
    check.is_none(a)


def test_is_not_none() -> None:
    a = 1
    check.is_not_none(a)


def test_is_in() -> None:
    check.is_in(2, [1, 2, 3])


def test_is_not_in() -> None:
    check.is_not_in(4, [1, 2, 3])


def test_is_instance() -> None:
    check.is_instance(1, int)


def test_is_not_instance() -> None:
    check.is_not_instance(1, str)


def test_almost_equal() -> None:
    check.almost_equal(1, 1)
    check.almost_equal(1, 1.1, abs=0.2)
    check.almost_equal(2, 1, rel=1)


def test_not_almost_equal() -> None:
    check.not_almost_equal(1, 2)
    check.not_almost_equal(1, 2.1, abs=0.1)
    check.not_almost_equal(3, 1, rel=1)


def test_greater() -> None:
    check.greater(2, 1)


def test_greater_equal() -> None:
    check.greater_equal(2, 1)
    check.greater_equal(1, 1)


def test_int_float() -> None:
    check.greater(2, 1.9)
    check.greater_equal(2, 1.9)
    check.less(1.9, 2)
    check.less_equal(1.9, 2)
    check.between(10, 4.5, 20)


def test_less() -> None:
    check.less(1, 2)


def test_less_equal() -> None:
    check.less_equal(1, 2)
    check.less_equal(1, 1)


def test_between() -> None:
    check.between(10, 0, 20)


def test_between_ge() -> None:
    check.between(10, 0, 20, ge=True)
    check.between(0, 0, 20, ge=True)


def test_between_le() -> None:
    check.between(10, 0, 20, le=True)
    check.between(20, 0, 20, le=True)


def test_between_ge_le() -> None:
    check.between(0, 0, 20, ge=True, le=True)
    check.between(10, 0, 20, ge=True, le=True)
    check.between(20, 0, 20, ge=True, le=True)


def test_between_equal() -> None:
    check.between_equal(0, 0, 20)
    check.between_equal(10, 0, 20)
    check.between_equal(20, 0, 20)


@pytest.mark.skipif(np is None, reason="numpy is not installed")
def test_greater_equal_max_int() -> None:
    if np is not None:
        check.greater_equal(np.iinfo(np.int32).max, 0)


@pytest.mark.skipif(np is None, reason="numpy is not installed")
def test_greater_equal_max_float() -> None:
    if np is not None:
        check.greater_equal(np.finfo(np.float32).max, 0)


@pytest.mark.skipif(np is None, reason="numpy is not installed")
def test_greater_max_int() -> None:
    if np is not None:
        check.greater(np.iinfo(np.int32).max, 0)


@pytest.mark.skipif(np is None, reason="numpy is not installed")
def test_less_min_float() -> None:
    if np is not None:
        check.less(np.finfo(np.float32).min, 0)


@pytest.mark.skipif(np is None, reason="numpy is not installed")
def test_less_equal_max_float() -> None:
    if np is not None:
        max_f32 = np.finfo(np.float32).max
        check.less_equal(max_f32, max_f32)