1
1
#!/usr/bin/env python
2
+ import asyncio
2
3
import sys
3
4
import unittest
5
+ from argparse import ArgumentTypeError
4
6
from io import StringIO
7
+ from test .utils import TEST_REQUIREMENTS_PATH , get_environment_requirements_list_monkey
5
8
from unittest .mock import patch
6
- from argparse import ArgumentTypeError
7
- from updatable .console import (
8
- _str_to_bool ,
9
- _list_updates ,
10
- _list_package_updates ,
11
- _updatable ,
12
- _argument_parser ,
13
- )
14
- from test .utils import get_environment_requirements_list_monkey , TEST_REQUIREMENTS_PATH
9
+
10
+ from updatable .console import _argument_parser , _list_package_updates , _list_updates , _str_to_bool , _updatable
15
11
16
12
17
13
class Capture (list ):
@@ -83,7 +79,7 @@ def test_with_updates_in_list(self):
83
79
84
80
85
81
class TestListPackageUpdates (unittest .TestCase ):
86
- def _mock_get_package_update_list (* args , ** kwargs ):
82
+ async def _mock_get_package_update_list (* args , ** kwargs ):
87
83
88
84
# No updates, no prereeases, no non semantic version
89
85
if args [1 ] == "package1" :
@@ -219,11 +215,11 @@ def test_with_no_available_updates(self):
219
215
side_effect = self ._mock_get_package_update_list ,
220
216
):
221
217
with Capture () as output :
222
- _list_package_updates ("package1" , "1.0.0" , False )
218
+ asyncio . run ( _list_package_updates ("package1" , "1.0.0" , False ) )
223
219
self .assertListEqual (output , [])
224
220
225
221
with Capture () as output :
226
- _list_package_updates ("package1" , "1.0.0" , True )
222
+ asyncio . run ( _list_package_updates ("package1" , "1.0.0" , True ) )
227
223
self .assertListEqual (output , [])
228
224
229
225
def test_with_updates_and_no_prereleases (self ):
@@ -232,7 +228,7 @@ def test_with_updates_and_no_prereleases(self):
232
228
side_effect = self ._mock_get_package_update_list ,
233
229
):
234
230
with Capture () as output :
235
- _list_package_updates ("package2" , "1.0.0" , False )
231
+ asyncio . run ( _list_package_updates ("package2" , "1.0.0" , False ) )
236
232
self .assertListEqual (
237
233
output ,
238
234
[
@@ -250,7 +246,7 @@ def test_with_updates_and_no_prereleases(self):
250
246
)
251
247
252
248
with Capture () as output :
253
- _list_package_updates ("package2" , "1.0.0" , True )
249
+ asyncio . run ( _list_package_updates ("package2" , "1.0.0" , True ) )
254
250
self .assertListEqual (
255
251
output ,
256
252
[
@@ -273,7 +269,7 @@ def test_with_updates_and_no_prereleases_and_non_semantic_versions(self):
273
269
side_effect = self ._mock_get_package_update_list ,
274
270
):
275
271
with Capture () as output :
276
- _list_package_updates ("package3" , "1.0.0" , False )
272
+ asyncio . run ( _list_package_updates ("package3" , "1.0.0" , False ) )
277
273
self .assertListEqual (
278
274
output ,
279
275
[
@@ -287,7 +283,7 @@ def test_with_updates_and_no_prereleases_and_non_semantic_versions(self):
287
283
)
288
284
289
285
with Capture () as output :
290
- _list_package_updates ("package3" , "1.0.0" , True )
286
+ asyncio . run ( _list_package_updates ("package3" , "1.0.0" , True ) )
291
287
self .assertListEqual (
292
288
output ,
293
289
[
@@ -306,7 +302,7 @@ def test_with_updates_and_prereleases_and_non_semantic_versions(self):
306
302
side_effect = self ._mock_get_package_update_list ,
307
303
):
308
304
with Capture () as output :
309
- _list_package_updates ("package4" , "1.0.0" , False )
305
+ asyncio . run ( _list_package_updates ("package4" , "1.0.0" , False ) )
310
306
self .assertListEqual (
311
307
output ,
312
308
[
@@ -320,7 +316,7 @@ def test_with_updates_and_prereleases_and_non_semantic_versions(self):
320
316
)
321
317
322
318
with Capture () as output :
323
- _list_package_updates ("package4" , "1.0.0" , True )
319
+ asyncio . run ( _list_package_updates ("package4" , "1.0.0" , True ) )
324
320
self .assertListEqual (
325
321
output ,
326
322
[
@@ -341,11 +337,11 @@ def test_with_prereleases_and_non_semantic_versions(self):
341
337
side_effect = self ._mock_get_package_update_list ,
342
338
):
343
339
with Capture () as output :
344
- _list_package_updates ("package5" , "1.0.0" , False )
340
+ asyncio . run ( _list_package_updates ("package5" , "1.0.0" , False ) )
345
341
self .assertListEqual (output , [])
346
342
347
343
with Capture () as output :
348
- _list_package_updates ("package5" , "1.0.0" , True )
344
+ asyncio . run ( _list_package_updates ("package5" , "1.0.0" , True ) )
349
345
self .assertListEqual (
350
346
output ,
351
347
[
@@ -362,11 +358,11 @@ def test_with_prereleases(self):
362
358
side_effect = self ._mock_get_package_update_list ,
363
359
):
364
360
with Capture () as output :
365
- _list_package_updates ("package6" , "1.0.0" , False )
361
+ asyncio . run ( _list_package_updates ("package6" , "1.0.0" , False ) )
366
362
self .assertListEqual (output , [])
367
363
368
364
with Capture () as output :
369
- _list_package_updates ("package6" , "1.0.0" , True )
365
+ asyncio . run ( _list_package_updates ("package6" , "1.0.0" , True ) )
370
366
self .assertListEqual (
371
367
output ,
372
368
[
@@ -383,23 +379,21 @@ def test_with_non_semantic_versions(self):
383
379
side_effect = self ._mock_get_package_update_list ,
384
380
):
385
381
with Capture () as output :
386
- _list_package_updates ("package7" , "1.0.0" , False )
382
+ asyncio . run ( _list_package_updates ("package7" , "1.0.0" , False ) )
387
383
self .assertListEqual (output , [])
388
384
389
385
with Capture () as output :
390
- _list_package_updates ("package7" , "1.0.0" , True )
386
+ asyncio . run ( _list_package_updates ("package7" , "1.0.0" , True ) )
391
387
self .assertListEqual (output , [])
392
388
393
389
def test_updatable_call (self ):
394
- with patch (
395
- "updatable.console._argument_parser" , side_effect = self ._mock_argument_parser
396
- ):
390
+ with patch ("updatable.console._argument_parser" , side_effect = self ._mock_argument_parser ):
397
391
with patch (
398
392
"updatable.utils.get_package_update_list" ,
399
393
side_effect = self ._mock_get_package_update_list ,
400
394
):
401
395
with Capture () as output :
402
- _updatable ()
396
+ asyncio . run ( _updatable () )
403
397
404
398
self .assertListEqual (
405
399
output ,
@@ -518,7 +512,7 @@ def test_argument_parser_pre_file(self):
518
512
"package2==1.0\n " ,
519
513
"package3==2\n " ,
520
514
"package4==2.4\n " ,
521
- "package5==3.0.0" ,
515
+ "package5==3.0.0\n " ,
522
516
],
523
517
)
524
518
@@ -535,7 +529,7 @@ def test_argument_parser_pre_file(self):
535
529
"package2==1.0\n " ,
536
530
"package3==2\n " ,
537
531
"package4==2.4\n " ,
538
- "package5==3.0.0" ,
532
+ "package5==3.0.0\n " ,
539
533
],
540
534
)
541
535
0 commit comments