forked from fluentpython/example-code-2e
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdouble_test.py
More file actions
56 lines (45 loc) · 1.25 KB
/
double_test.py
File metadata and controls
56 lines (45 loc) · 1.25 KB
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
from typing import TYPE_CHECKING
import pytest
from double_protocol import double
def test_double_int() -> None:
given = 2
result = double(given)
assert result == given * 2
if TYPE_CHECKING:
reveal_type(given)
reveal_type(result)
def test_double_str() -> None:
given = 'A'
result = double(given)
assert result == given * 2
if TYPE_CHECKING:
reveal_type(given)
reveal_type(result)
def test_double_fraction() -> None:
from fractions import Fraction
given = Fraction(2, 5)
result = double(given)
assert result == given * 2
if TYPE_CHECKING:
reveal_type(given)
reveal_type(result)
def test_double_array() -> None:
from array import array
given = array('d', [1.0, 2.0, 3.14])
result = double(given)
if TYPE_CHECKING:
reveal_type(given)
reveal_type(result)
def test_double_nparray() -> None:
import numpy as np # type: ignore
given = np.array([[1, 2], [3, 4]])
result = double(given)
comparison = result == given * 2
assert comparison.all()
if TYPE_CHECKING:
reveal_type(given)
reveal_type(result)
def test_double_none() -> None:
given = None
with pytest.raises(TypeError):
double(given)