26
26
)
27
27
28
28
29
- def test_odict ():
29
+ def test_odict () -> None :
30
30
assert odict (('a' , 1 ), ('b' , 2 )) == OrderedDict ([('a' , 1 ), ('b' , 2 )])
31
31
32
32
33
- def test_dict2kvlist ():
33
+ def test_dict2kvlist () -> None :
34
34
ret = list (dict2kvlist ({'a' : 1 , 'b' : 2 }))
35
35
assert set (ret ) == {'a' , 1 , 'b' , 2 }
36
36
37
37
38
- def test_generate_uuid ():
38
+ def test_generate_uuid () -> None :
39
39
u = generate_uuid ()
40
40
assert len (u ) == 22
41
41
assert isinstance (u , str )
42
42
43
43
44
- def test_random_seq ():
44
+ def test_random_seq () -> None :
45
45
assert [* get_random_seq (10 , 11 , 1 )] == [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
46
46
assert [* get_random_seq (10 , 6 , 2 )] == [0 , 2 , 4 , 6 , 8 , 10 ]
47
47
with pytest .raises (AssertionError ):
@@ -57,7 +57,7 @@ def test_random_seq():
57
57
assert x > last_x + 1
58
58
59
59
60
- def test_nmget ():
60
+ def test_nmget () -> None :
61
61
o = {'a' : {'b' : 1 }, 'x' : None }
62
62
assert nmget (o , 'a' , 0 ) == {'b' : 1 }
63
63
assert nmget (o , 'a.b' , 0 ) == 1
@@ -68,7 +68,7 @@ def test_nmget():
68
68
assert nmget (o , 'x' , 0 , null_as_default = False ) is None
69
69
70
70
71
- def test_readable_size_to_bytes ():
71
+ def test_readable_size_to_bytes () -> None :
72
72
assert readable_size_to_bytes (2 ) == 2
73
73
assert readable_size_to_bytes ('2' ) == 2
74
74
assert readable_size_to_bytes ('2K' ) == 2 * (2 ** 10 )
@@ -93,7 +93,7 @@ def test_readable_size_to_bytes():
93
93
readable_size_to_bytes ('TT' )
94
94
95
95
96
- def test_str_to_timedelta ():
96
+ def test_str_to_timedelta () -> None :
97
97
assert str_to_timedelta ('1d2h3m4s' ) == timedelta (days = 1 , hours = 2 , minutes = 3 , seconds = 4 )
98
98
assert str_to_timedelta ('1d2h3m' ) == timedelta (days = 1 , hours = 2 , minutes = 3 )
99
99
assert str_to_timedelta ('1d2h' ) == timedelta (days = 1 , hours = 2 )
@@ -128,7 +128,7 @@ def test_str_to_timedelta():
128
128
129
129
130
130
@pytest .mark .asyncio
131
- async def test_curl_returns_stripped_body (mocker ):
131
+ async def test_curl_returns_stripped_body (mocker ) -> None :
132
132
mock_get = mocker .patch .object (aiohttp .ClientSession , 'get' )
133
133
mock_resp = {'status' : 200 , 'text' : mock_corofunc (b'success ' )}
134
134
mock_get .return_value = AsyncContextManagerMock (** mock_resp )
@@ -140,7 +140,7 @@ async def test_curl_returns_stripped_body(mocker):
140
140
141
141
142
142
@pytest .mark .asyncio
143
- async def test_curl_returns_default_value_if_not_success (mocker ):
143
+ async def test_curl_returns_default_value_if_not_success (mocker ) -> None :
144
144
mock_get = mocker .patch .object (aiohttp .ClientSession , 'get' )
145
145
mock_resp = {'status' : 400 , 'text' : mock_corofunc (b'bad request' )}
146
146
mock_get .return_value = AsyncContextManagerMock (** mock_resp )
@@ -154,9 +154,11 @@ async def test_curl_returns_default_value_if_not_success(mocker):
154
154
assert resp == 'default'
155
155
156
156
157
- def test_string_set_flag ():
157
+ def test_string_set_flag () -> None :
158
158
159
- class MyFlags (StringSetFlag ):
159
+ # FIXME: Remove "type: ignore" when mypy gets released with
160
+ # python/mypy#11579.
161
+ class MyFlags (StringSetFlag ): # type: ignore
160
162
A = 'a'
161
163
B = 'b'
162
164
@@ -193,14 +195,14 @@ class MyFlags(StringSetFlag):
193
195
194
196
195
197
class TestAsyncBarrier :
196
- def test_async_barrier_initialization (self ):
198
+ def test_async_barrier_initialization (self ) -> None :
197
199
barrier = AsyncBarrier (num_parties = 5 )
198
200
199
201
assert barrier .num_parties == 5
200
202
assert barrier .cond is not None # default condition
201
203
202
204
@pytest .mark .asyncio
203
- async def test_wait_notify_all_if_cound_eq_num_parties (self , mocker ):
205
+ async def test_wait_notify_all_if_cound_eq_num_parties (self , mocker ) -> None :
204
206
mock_cond = mocker .patch .object (asyncio , 'Condition' )
205
207
mock_resp = {
206
208
'notify_all' : mock .Mock (),
@@ -214,8 +216,9 @@ async def test_wait_notify_all_if_cound_eq_num_parties(self, mocker):
214
216
await barrier .wait ()
215
217
216
218
assert barrier .count == 1
217
- mock_cond .return_value .notify_all .assert_called_once_with ()
218
- mock_cond .return_value .wait .assert_not_called ()
219
+ # The methods are added at runtime.
220
+ mock_cond .return_value .notify_all .assert_called_once_with () # type: ignore
221
+ mock_cond .return_value .wait .assert_not_called () # type: ignore
219
222
220
223
def test_async_barrier_reset (self ):
221
224
barrier = AsyncBarrier (num_parties = 5 )
@@ -227,7 +230,7 @@ def test_async_barrier_reset(self):
227
230
228
231
229
232
@pytest .mark .asyncio
230
- async def test_run_through ():
233
+ async def test_run_through () -> None :
231
234
232
235
i = 0
233
236
@@ -270,7 +273,7 @@ def do_sync():
270
273
271
274
272
275
@pytest .mark .asyncio
273
- async def test_async_file_writer_str ():
276
+ async def test_async_file_writer_str () -> None :
274
277
# 1. Get temporary filename
275
278
with NamedTemporaryFile () as temp_file :
276
279
file_name = temp_file .name
@@ -298,7 +301,7 @@ async def test_async_file_writer_str():
298
301
299
302
300
303
@pytest .mark .asyncio
301
- async def test_async_file_writer_bytes ():
304
+ async def test_async_file_writer_bytes () -> None :
302
305
# 1. Get temporary filename
303
306
with NamedTemporaryFile () as temp_file :
304
307
file_name = temp_file .name
0 commit comments