8
8
9
9
# stdlib
10
10
from math import isclose
11
+ from typing import List , Tuple , Type
11
12
12
13
# 3rd party
13
14
import pytest
28
29
Size_mm ,
29
30
Size_pica ,
30
31
Size_um ,
32
+ Unit ,
31
33
cm ,
32
34
convert_from ,
33
35
inch ,
65
67
),
66
68
],
67
69
)
68
- def test_repr (obj , expects ):
70
+ def test_repr (obj : Unit , expects : str ):
69
71
assert repr (obj ) == expects
70
72
71
73
@@ -78,12 +80,12 @@ def test_repr(obj, expects):
78
80
(Size_pica (12 , 34 ), "Size_pica(width=12, height=34)" ),
79
81
],
80
82
)
81
- def test_str (obj , expects ):
83
+ def test_str (obj : Unit , expects : str ):
82
84
assert str (obj ) == expects
83
85
84
86
85
87
@pytest .mark .parametrize ("size" , [A6 , A5 , A4 , A3 , A2 , A1 , A0 ])
86
- def test_orientation (size ):
88
+ def test_orientation (size : BaseSize ):
87
89
assert size .is_portrait ()
88
90
assert size .portrait ().is_portrait ()
89
91
assert size .landscape ().portrait ().is_portrait ()
@@ -106,7 +108,7 @@ def test_is_square():
106
108
107
109
108
110
@pytest .mark .parametrize ("unit" , [pt , inch , cm , mm , um , pc ])
109
- def test_convert_size (unit ):
111
+ def test_convert_size (unit : Unit ):
110
112
size = PageSize (12 , 34 , unit )
111
113
unit_str = unit .name
112
114
if unit_str == "µm" :
@@ -176,7 +178,7 @@ def test_convert_size(unit):
176
178
pytest .param (2 , 5 , 10 , id = "not isinstance(from_, Unit)" ),
177
179
],
178
180
)
179
- def test_convert_from (value , unit , expects ):
181
+ def test_convert_from (value : List [ int ] , unit , expects : Tuple [ float , ...] ):
180
182
assert convert_from (value , unit ) == expects
181
183
182
184
@@ -187,7 +189,7 @@ def test_convert_from(value, unit, expects):
187
189
((12 , 34 ), Size_mm (12 , 34 ), Size_mm ),
188
190
],
189
191
)
190
- def test_from_size (size , expected , class_ ):
192
+ def test_from_size (size : Tuple [ int , int ], expected : Unit , class_ : Type [ BaseSize ] ):
191
193
print (class_ .from_size (size ))
192
194
assert class_ .from_size (size ) == expected
193
195
@@ -210,7 +212,7 @@ def test_from_size(size, expected, class_):
210
212
("10μm" , [("10" , "μm" )]),
211
213
],
212
214
)
213
- def test_measurement_re (string , expects ):
215
+ def test_measurement_re (string : str , expects : Unit ):
214
216
assert _measurement_re .findall (string ) == expects
215
217
216
218
@@ -261,5 +263,5 @@ def test_parse_measurement_errors():
261
263
("5in" , 5 * inch ),
262
264
],
263
265
)
264
- def test_parse_measurement (string , expects ):
266
+ def test_parse_measurement (string : str , expects : Unit ):
265
267
assert parse_measurement (string ) == expects
0 commit comments