@@ -68,7 +68,7 @@ def test_list_mbeds_valid_platform(self):
68
68
_listdir .return_value = []
69
69
to_check = self .base .list_mbeds ()
70
70
_read_htm .assert_called_once_with ('dummy_mount_point' )
71
- _get .assert_called_once_with ('0241' , device_type = 'daplink' , verbose_data = True )
71
+ _get .assert_any_call ('0241' , device_type = 'daplink' , verbose_data = True )
72
72
self .assertEqual (len (to_check ), 1 )
73
73
self .assertEqual (to_check [0 ]['target_id' ], "0241BEEFDEAD" )
74
74
self .assertEqual (to_check [0 ]['platform_name' ], 'foo_target' )
@@ -78,7 +78,7 @@ def test_list_mbeds_invalid_tid(self):
78
78
'target_id_usb_id' : u'0240DEADBEEF' ,
79
79
'serial_port' : "dummy_serial_port" },
80
80
{'mount_point' : 'dummy_mount_point' ,
81
- 'target_id_usb_id' : None ,
81
+ 'target_id_usb_id' : "" ,
82
82
'serial_port' : 'not_valid' }]
83
83
with patch ("mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids" ) as _read_htm ,\
84
84
patch ("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready" ) as _mpr ,\
@@ -91,11 +91,11 @@ def test_list_mbeds_invalid_tid(self):
91
91
}
92
92
_listdir .return_value = []
93
93
to_check = self .base .list_mbeds ()
94
- _get .assert_called_once_with ('0241' , device_type = 'daplink' , verbose_data = True )
94
+ _get .assert_any_call ('0241' , device_type = 'daplink' , verbose_data = True )
95
95
self .assertEqual (len (to_check ), 2 )
96
96
self .assertEqual (to_check [0 ]['target_id' ], "0241BEEFDEAD" )
97
97
self .assertEqual (to_check [0 ]['platform_name' ], 'foo_target' )
98
- self .assertEqual (to_check [1 ]['target_id' ], None )
98
+ self .assertEqual (to_check [1 ]['target_id' ], "" )
99
99
self .assertEqual (to_check [1 ]['platform_name' ], None )
100
100
101
101
def test_list_mbeds_invalid_platform (self ):
@@ -113,7 +113,7 @@ def test_list_mbeds_invalid_platform(self):
113
113
_listdir .return_value = []
114
114
to_check = self .base .list_mbeds ()
115
115
_read_htm .assert_called_once_with ('dummy_mount_point' )
116
- _get .assert_called_once_with ('not_' , device_type = 'daplink' , verbose_data = True )
116
+ _get .assert_any_call ('not_' , device_type = 'daplink' , verbose_data = True )
117
117
self .assertEqual (len (to_check ), 1 )
118
118
self .assertEqual (to_check [0 ]['target_id' ], "not_in_target_db" )
119
119
self .assertEqual (to_check [0 ]['platform_name' ], None )
@@ -142,6 +142,7 @@ def test_list_mbeds_unmount_mid_read_list_unmounted(self):
142
142
self .assertEqual (len (to_check ), 1 )
143
143
self .assertEqual (to_check [0 ]['mount_point' ], None )
144
144
self .assertEqual (to_check [0 ]['device_type' ], 'unknown' )
145
+ self .assertEqual (to_check [0 ]['platform_name' ], 'K64F' )
145
146
146
147
def test_list_manufacture_ids (self ):
147
148
table_str = self .base .list_manufacture_ids ()
@@ -246,28 +247,36 @@ def test_fs_never(self):
246
247
'mount_point' : 'invalid_mount_point' ,
247
248
'serial_port' : 'invalid_serial_port'
248
249
}
249
- with patch ("mbed_lstools.lstools_base.MbedLsToolsBase._update_device_from_fs" ) as _up_fs :
250
+ self .base .return_value = [device ]
251
+ with patch ("mbed_lstools.lstools_base.MbedLsToolsBase._update_device_from_fs" ) as _up_fs ,\
252
+ patch ("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready" ) as mount_point_ready :
253
+ mount_point_ready .return_value = True
254
+
250
255
filter = None
251
- ret = self .base ._fs_never (deepcopy (device ), filter , False )
252
- ret_with_details = self .base ._fs_never (deepcopy (device ), filter , True )
253
- self .assertIsNotNone (ret )
254
- self .assertIsNotNone (ret_with_details )
255
- self .assertEqual (ret ['target_id' ], ret ['target_id_usb_id' ])
256
- self .assertEqual (ret , ret_with_details )
256
+ ret = self .base .list_mbeds (FSInteraction .Never , filter , read_details_txt = False )
257
+ ret_with_details = self .base .list_mbeds (FSInteraction .Never , filter , read_details_txt = True )
258
+ self .assertIsNotNone (ret [0 ])
259
+ self .assertIsNotNone (ret_with_details [0 ])
260
+ self .assertEqual (ret [0 ]['target_id' ], ret [0 ]['target_id_usb_id' ])
261
+ self .assertEqual (ret [0 ]['platform_name' ], "K64F" )
262
+ self .assertEqual (ret [0 ], ret_with_details [0 ])
257
263
_up_fs .assert_not_called ()
258
264
259
265
filter_in = lambda m : m ['platform_name' ] == 'K64F'
260
- ret = self .base ._fs_never (deepcopy (device ), filter_in , False )
261
- ret_with_details = self .base ._fs_never (deepcopy (device ), filter_in , True )
262
- self .assertIsNotNone (ret )
263
- self .assertIsNotNone (ret_with_details )
264
- self .assertEqual (ret , ret_with_details )
266
+ ret = self .base .list_mbeds (FSInteraction .Never , filter_in , read_details_txt = False )
267
+ ret_with_details = self .base .list_mbeds (FSInteraction .Never , filter_in , read_details_txt = True )
268
+ self .assertIsNotNone (ret [0 ])
269
+ self .assertIsNotNone (ret_with_details [0 ])
270
+ self .assertEqual (ret [0 ]['target_id' ], ret [0 ]['target_id_usb_id' ])
271
+ self .assertEqual (ret [0 ]['platform_name' ], "K64F" )
272
+ self .assertEqual (ret [0 ], ret_with_details [0 ])
265
273
_up_fs .assert_not_called ()
266
274
267
275
filter_out = lambda m : m ['platform_name' ] != 'K64F'
268
- ret = self .base ._fs_never (deepcopy (device ), filter_out , False )
269
- ret_with_details = self .base ._fs_never (deepcopy (device ), filter_out , True )
270
- self .assertIsNone (ret )
276
+ ret = self .base .list_mbeds (FSInteraction .Never , filter_out , read_details_txt = False )
277
+ ret_with_details = self .base .list_mbeds (FSInteraction .Never , filter_out , read_details_txt = True )
278
+ _up_fs .assert_not_called ()
279
+ self .assertEqual (ret , [])
271
280
self .assertEqual (ret , ret_with_details )
272
281
_up_fs .assert_not_called ()
273
282
@@ -279,23 +288,28 @@ def test_fs_after(self):
279
288
}
280
289
with patch ("mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids" ) as _read_htm ,\
281
290
patch ("mbed_lstools.lstools_base.MbedLsToolsBase._details_txt" ) as _up_details ,\
291
+ patch ("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready" ) as mount_point_ready ,\
282
292
patch ('os.listdir' ) as _listdir :
283
293
new_device_id = "00017531642046"
284
294
_read_htm .return_value = (new_device_id , {})
285
295
_listdir .return_value = []
286
296
_up_details .return_value = {
287
297
'automation_allowed' : '0'
288
298
}
299
+ mount_point_ready .return_value = True
300
+
289
301
filter = None
290
- ret = self .base ._fs_after_id_check (deepcopy (device ), filter , False )
302
+ self .base .return_value = [deepcopy (device )]
303
+ ret = self .base .list_mbeds (FSInteraction .AfterFilter , filter , False , False )
291
304
_up_details .assert_not_called ()
292
- ret_with_details = self .base ._fs_after_id_check (deepcopy (device ), filter , True )
293
-
294
- self .assertIsNotNone (ret )
295
- self .assertIsNotNone (ret_with_details )
296
- self .assertEqual (ret ['target_id' ], new_device_id )
297
- self .assertEqual (ret_with_details ['daplink_automation_allowed' ], '0' )
298
- self .assertDictContainsSubset (ret , ret_with_details )
305
+ self .base .return_value = [deepcopy (device )]
306
+ ret_with_details = self .base .list_mbeds (FSInteraction .AfterFilter , filter , False , True )
307
+
308
+ self .assertIsNotNone (ret [0 ])
309
+ self .assertIsNotNone (ret_with_details [0 ])
310
+ self .assertEqual (ret [0 ]['target_id' ], new_device_id )
311
+ self .assertEqual (ret_with_details [0 ]['daplink_automation_allowed' ], '0' )
312
+ self .assertDictContainsSubset (ret [0 ], ret_with_details [0 ])
299
313
_read_htm .assert_called_with (device ['mount_point' ])
300
314
_up_details .assert_called_with (device ['mount_point' ])
301
315
@@ -305,14 +319,16 @@ def test_fs_after(self):
305
319
filter_in = lambda m : m ['target_id' ] == device ['target_id_usb_id' ]
306
320
filter_details = lambda m : m .get ('daplink_automation_allowed' , None ) == '0'
307
321
308
- ret = self .base ._fs_after_id_check (deepcopy (device ), filter_in , False )
309
- ret_with_details = self .base ._fs_after_id_check (deepcopy (device ),
310
- filter_details ,
311
- True )
322
+ self .base .return_value = [deepcopy (device )]
323
+ ret = self .base .list_mbeds (
324
+ FSInteraction .AfterFilter , filter_in , False , False )
325
+ self .base .return_value = [deepcopy (device )]
326
+ ret_with_details = self .base .list_mbeds (
327
+ FSInteraction .AfterFilter , filter_details , False , True )
312
328
313
- self .assertIsNotNone (ret )
314
- self .assertIsNone (ret_with_details )
315
- self .assertEqual (ret ['target_id' ], new_device_id )
329
+ self .assertIsNotNone (ret [ 0 ] )
330
+ self .assertEqual (ret_with_details , [] )
331
+ self .assertEqual (ret [0 ][ 'target_id' ], new_device_id )
316
332
_read_htm .assert_called_with (device ['mount_point' ])
317
333
_up_details .assert_not_called ()
318
334
@@ -321,13 +337,15 @@ def test_fs_after(self):
321
337
322
338
filter_out = lambda m : m ['target_id' ] == new_device_id
323
339
324
- ret = self .base ._fs_after_id_check (deepcopy (device ), filter_out , False )
325
- ret_with_details = self .base ._fs_after_id_check (deepcopy (device ),
326
- filter_details ,
327
- True )
340
+ self .base .return_value = [deepcopy (device )]
341
+ ret = self .base .list_mbeds (
342
+ FSInteraction .AfterFilter , filter_out , False , False )
343
+ self .base .return_value = [deepcopy (device )]
344
+ ret_with_details = self .base .list_mbeds (
345
+ FSInteraction .AfterFilter , filter_out , False , True )
328
346
329
- self .assertIsNone (ret )
330
- self .assertIsNone (ret_with_details )
347
+ self .assertEqual (ret , [] )
348
+ self .assertEqual (ret_with_details , [] )
331
349
_read_htm .assert_not_called ()
332
350
_up_details .assert_not_called ()
333
351
@@ -339,24 +357,30 @@ def test_fs_before(self):
339
357
}
340
358
with patch ("mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids" ) as _read_htm ,\
341
359
patch ("mbed_lstools.lstools_base.MbedLsToolsBase._details_txt" ) as _up_details ,\
360
+ patch ("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready" ) as mount_point_ready ,\
342
361
patch ('os.listdir' ) as _listdir :
343
362
new_device_id = u'00017575430420'
344
363
_read_htm .return_value = (new_device_id , {})
345
364
_listdir .return_value = []
346
365
_up_details .return_value = {
347
366
'automation_allowed' : '0'
348
367
}
368
+ mount_point_ready .return_value = True
349
369
350
370
filter = None
351
- ret = self .base ._fs_before_id_check (deepcopy (device ), filter , False )
371
+ self .base .return_value = [deepcopy (device )]
372
+ ret = self .base .list_mbeds (
373
+ FSInteraction .BeforeFilter , filter , False , False )
352
374
_up_details .assert_not_called ()
353
375
354
- ret_with_details = self .base ._fs_before_id_check (deepcopy (device ), filter , True )
355
- self .assertIsNotNone (ret )
356
- self .assertIsNotNone (ret_with_details )
357
- self .assertEqual (ret ['target_id' ], new_device_id )
358
- self .assertEqual (ret_with_details ['daplink_automation_allowed' ], '0' )
359
- self .assertDictContainsSubset (ret , ret_with_details )
376
+ self .base .return_value = [deepcopy (device )]
377
+ ret_with_details = self .base .list_mbeds (
378
+ FSInteraction .BeforeFilter , filter , False , True )
379
+ self .assertIsNotNone (ret [0 ])
380
+ self .assertIsNotNone (ret_with_details [0 ])
381
+ self .assertEqual (ret [0 ]['target_id' ], new_device_id )
382
+ self .assertEqual (ret_with_details [0 ]['daplink_automation_allowed' ], '0' )
383
+ self .assertDictContainsSubset (ret [0 ], ret_with_details [0 ])
360
384
_read_htm .assert_called_with (device ['mount_point' ])
361
385
_up_details .assert_called_with (device ['mount_point' ])
362
386
@@ -365,17 +389,20 @@ def test_fs_before(self):
365
389
366
390
filter_in = lambda m : m ['target_id' ] == '00017575430420'
367
391
filter_in_details = lambda m : m ['daplink_automation_allowed' ] == '0'
368
- ret = self .base ._fs_before_id_check (deepcopy (device ), filter_in , False )
392
+ self .base .return_value = [deepcopy (device )]
393
+ ret = self .base .list_mbeds (
394
+ FSInteraction .BeforeFilter , filter_in , False , False )
369
395
_up_details .assert_not_called ()
370
396
371
- ret_with_details = self .base ._fs_before_id_check (deepcopy (device ),
372
- filter_in_details ,
373
- True )
374
- self .assertIsNotNone (ret )
375
- self .assertIsNotNone (ret_with_details )
376
- self .assertEqual (ret ['target_id' ], new_device_id )
377
- self .assertEqual (ret_with_details ['daplink_automation_allowed' ], '0' )
378
- self .assertDictContainsSubset (ret , ret_with_details )
397
+ self .base .return_value = [deepcopy (device )]
398
+ ret_with_details = self .base .list_mbeds (
399
+ FSInteraction .BeforeFilter , filter_in_details , False , True )
400
+
401
+ self .assertIsNotNone (ret [0 ])
402
+ self .assertIsNotNone (ret_with_details [0 ])
403
+ self .assertEqual (ret [0 ]['target_id' ], new_device_id )
404
+ self .assertEqual (ret_with_details [0 ]['daplink_automation_allowed' ], '0' )
405
+ self .assertDictContainsSubset (ret [0 ], ret_with_details [0 ])
379
406
_read_htm .assert_called_with (device ['mount_point' ])
380
407
_up_details .assert_called_with (device ['mount_point' ])
381
408
@@ -384,14 +411,16 @@ def test_fs_before(self):
384
411
385
412
filter_out = lambda m : m ['target_id' ] == '024075309420ABCE'
386
413
filter_out_details = lambda m : m ['daplink_automation_allowed' ] == '1'
387
- ret = self .base ._fs_before_id_check (deepcopy (device ), filter_out , False )
414
+ ret = self .base .list_mbeds (
415
+ FSInteraction .BeforeFilter , filter_out , False , False )
388
416
_up_details .assert_not_called ()
389
417
390
- ret_with_details = self .base ._fs_before_id_check (deepcopy (device ),
391
- filter_out_details ,
392
- True )
393
- self .assertIsNone (ret )
394
- self .assertIsNone (ret_with_details )
418
+ self .base .return_value = [deepcopy (device )]
419
+ ret_with_details = self .base .list_mbeds (
420
+ FSInteraction .BeforeFilter , filter_out_details , False , True )
421
+
422
+ self .assertEqual (ret , [])
423
+ self .assertEqual (ret_with_details , [])
395
424
_read_htm .assert_called_with (device ['mount_point' ])
396
425
397
426
class RetargetTestCase (unittest .TestCase ):
0 commit comments