Skip to content

Commit 3db1404

Browse files
committed
Update tests to work with mbed-os-tools package
1 parent 8a6b2cd commit 3db1404

File tree

5 files changed

+59
-268
lines changed

5 files changed

+59
-268
lines changed

legacy/mbed-ls/test/mbedls_toolsbase.py

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def test_list_mbeds_valid_platform(self):
5858
'serial_port': 'not_valid'}]
5959
with patch("mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids") as _read_htm,\
6060
patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
61-
patch("mbed_lstools.lstools_base.PlatformDatabase.get") as _get,\
62-
patch('os.listdir') as _listdir:
61+
patch("mbed_os_tools.detect.platform_database.PlatformDatabase.get") as _get,\
62+
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
6363
_mpr.return_value = True
6464
_read_htm.return_value = (u'0241BEEFDEAD', {})
6565
_get.return_value = {
@@ -82,8 +82,8 @@ def test_list_mbeds_invalid_tid(self):
8282
'serial_port': 'not_valid'}]
8383
with patch("mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids") as _read_htm,\
8484
patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
85-
patch("mbed_lstools.lstools_base.PlatformDatabase.get") as _get,\
86-
patch('os.listdir') as _listdir:
85+
patch("mbed_os_tools.detect.platform_database.PlatformDatabase.get") as _get,\
86+
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
8787
_mpr.return_value = True
8888
_read_htm.side_effect = [(u'0241BEEFDEAD', {}), (None, {})]
8989
_get.return_value = {
@@ -103,10 +103,10 @@ def test_list_mbeds_invalid_platform(self):
103103
'target_id_usb_id': u'not_in_target_db',
104104
'serial_port': "dummy_serial_port"}]
105105
for qos in [FSInteraction.BeforeFilter, FSInteraction.AfterFilter]:
106-
with patch("mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids") as _read_htm,\
107-
patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
108-
patch("mbed_lstools.lstools_base.PlatformDatabase.get") as _get,\
109-
patch('os.listdir') as _listdir:
106+
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._read_htm_ids") as _read_htm,\
107+
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as _mpr,\
108+
patch("mbed_os_tools.detect.platform_database.PlatformDatabase.get") as _get,\
109+
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
110110
_mpr.return_value = True
111111
_read_htm.return_value = (u'not_in_target_db', {})
112112
_get.return_value = None
@@ -122,8 +122,8 @@ def test_list_mbeds_unmount_mid_read(self):
122122
self.base.return_value = [{'mount_point': 'dummy_mount_point',
123123
'target_id_usb_id': u'0240DEADBEEF',
124124
'serial_port': "dummy_serial_port"}]
125-
with patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
126-
patch('os.listdir') as _listdir:
125+
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as _mpr,\
126+
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
127127
_mpr.return_value = True
128128
_listdir.side_effect = OSError
129129
to_check = self.base.list_mbeds()
@@ -134,9 +134,9 @@ def _test(mock):
134134
self.base.return_value = [{'mount_point': 'dummy_mount_point',
135135
'target_id_usb_id': u'0240DEADBEEF',
136136
'serial_port': "dummy_serial_port"}]
137-
with patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
138-
patch('os.listdir') as _listdir,\
139-
patch('mbed_lstools.lstools_base.open', mock, create=True):
137+
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as _mpr,\
138+
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir,\
139+
patch('mbed_os_tools.detect.lstools_base.open', mock, create=True):
140140
_mpr.return_value = True
141141
_listdir.return_value = ['MBED.HTM', 'DETAILS.TXT']
142142
to_check = self.base.list_mbeds()
@@ -180,9 +180,9 @@ def _handle_open(*args, **kwargs):
180180
return DEFAULT
181181

182182
m = mock_open(read_data=details_txt_contents)
183-
with patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
184-
patch('os.listdir') as _listdir,\
185-
patch('mbed_lstools.lstools_base.open', m, create=True) as mocked_open:
183+
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as _mpr,\
184+
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir,\
185+
patch('mbed_os_tools.detect.lstools_base.open', m, create=True) as mocked_open:
186186
mocked_open.side_effect = _handle_open
187187
_mpr.return_value = True
188188
_listdir.return_value = ['PRODINFO.HTM', 'DETAILS.TXT']
@@ -196,10 +196,10 @@ def _test(mock):
196196
self.base.return_value = [{'mount_point': 'dummy_mount_point',
197197
'target_id_usb_id': u'0240DEADBEEF',
198198
'serial_port': "dummy_serial_port"}]
199-
with patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
200-
patch('os.listdir') as _listdir,\
201-
patch("mbed_lstools.lstools_base.MbedLsToolsBase._update_device_from_htm") as _htm,\
202-
patch('mbed_lstools.lstools_base.open', mock, create=True):
199+
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as _mpr,\
200+
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir,\
201+
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._update_device_from_htm") as _htm,\
202+
patch('mbed_os_tools.detect.lstools_base.open', mock, create=True):
203203
_mpr.return_value = True
204204
_htm.side_effect = None
205205
_listdir.return_value = ['MBED.HTM', 'DETAILS.TXT']
@@ -220,8 +220,8 @@ def test_list_mbeds_unmount_mid_read_list_unmounted(self):
220220
self.base.return_value = [{'mount_point': 'dummy_mount_point',
221221
'target_id_usb_id': u'0240DEADBEEF',
222222
'serial_port': "dummy_serial_port"}]
223-
with patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as _mpr,\
224-
patch('os.listdir') as _listdir:
223+
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as _mpr,\
224+
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
225225
_mpr.return_value = True
226226
_listdir.side_effect = OSError
227227
to_check = self.base.list_mbeds()
@@ -277,7 +277,7 @@ def test_update_device_from_fs_mid_unmount(self):
277277
'mount_point': dummy_mount
278278
}
279279

280-
with patch('os.listdir') as _listdir:
280+
with patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
281281
_listdir.side_effect = OSError
282282
self.base._update_device_from_fs(device, False)
283283
self.assertEqual(device['mount_point'], None)
@@ -305,8 +305,8 @@ def test_device_type_unmounted(self):
305305
'serial_port': "dummy_serial_port",
306306
'vendor_id': '0d28',
307307
'product_id': '0204'}]
308-
with patch("mbed_lstools.lstools_base.PlatformDatabase.get") as _get,\
309-
patch('os.listdir') as _listdir:
308+
with patch("mbed_os_tools.detect.platform_database.PlatformDatabase.get") as _get,\
309+
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
310310
_get.return_value = {
311311
'platform_name': 'foo_target'
312312
}
@@ -327,7 +327,7 @@ def test_update_device_details_jlink(self):
327327
'mount_point': dummy_mount_point
328328
}
329329

330-
with patch('mbed_lstools.lstools_base.open', _open, create=True):
330+
with patch('mbed_os_tools.detect.lstools_base.open', _open, create=True):
331331
device = deepcopy(base_device)
332332
device['directory_entries'] = ['Board.html', 'User Guide.html']
333333
self.base._update_device_details_jlink(device, False)
@@ -358,8 +358,8 @@ def test_fs_never(self):
358358
'serial_port': 'invalid_serial_port'
359359
}
360360
self.base.return_value = [device]
361-
with patch("mbed_lstools.lstools_base.MbedLsToolsBase._update_device_from_fs") as _up_fs,\
362-
patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as mount_point_ready:
361+
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._update_device_from_fs") as _up_fs,\
362+
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as mount_point_ready:
363363
mount_point_ready.return_value = True
364364

365365
filter = None
@@ -396,10 +396,10 @@ def test_fs_after(self):
396396
'mount_point': 'invalid_mount_point',
397397
'serial_port': 'invalid_serial_port'
398398
}
399-
with patch("mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids") as _read_htm,\
400-
patch("mbed_lstools.lstools_base.MbedLsToolsBase._details_txt") as _up_details,\
401-
patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as mount_point_ready,\
402-
patch('os.listdir') as _listdir:
399+
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._read_htm_ids") as _read_htm,\
400+
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._details_txt") as _up_details,\
401+
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as mount_point_ready,\
402+
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
403403
new_device_id = "00017531642046"
404404
_read_htm.return_value = (new_device_id, {})
405405
_listdir.return_value = ['mbed.htm', 'details.txt']
@@ -470,10 +470,10 @@ def test_fs_before(self):
470470
'mount_point': 'invalid_mount_point',
471471
'serial_port': 'invalid_serial_port'
472472
}
473-
with patch("mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids") as _read_htm,\
474-
patch("mbed_lstools.lstools_base.MbedLsToolsBase._details_txt") as _up_details,\
475-
patch("mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready") as mount_point_ready,\
476-
patch('os.listdir') as _listdir:
473+
with patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._read_htm_ids") as _read_htm,\
474+
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase._details_txt") as _up_details,\
475+
patch("mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready") as mount_point_ready,\
476+
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
477477
new_device_id = u'00017575430420'
478478
_read_htm.return_value = (new_device_id, {})
479479
_listdir.return_value = ['mbed.htm', 'details.txt']
@@ -552,7 +552,9 @@ def setUp(self):
552552
_open = mock_open(read_data=json.dumps(retarget_data))
553553

554554
with patch('os.path.isfile') as _isfile,\
555-
patch('mbed_lstools.lstools_base.open', _open, create=True):
555+
patch('mbed_os_tools.detect.lstools_base.isfile') as _isfile,\
556+
patch('mbed_os_tools.detect.lstools_base.open', _open, create=True):
557+
_isfile.return_value = True
556558
self.base = DummyLsTools()
557559
_open.assert_called()
558560

@@ -563,10 +565,10 @@ def test_list_mbeds_valid_platform(self):
563565
self.base.return_value = [{'mount_point': 'dummy_mount_point',
564566
'target_id_usb_id': u'0240DEADBEEF',
565567
'serial_port': None}]
566-
with patch('mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids') as _read_htm,\
567-
patch('mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready') as _mpr,\
568-
patch('mbed_lstools.lstools_base.PlatformDatabase.get') as _get,\
569-
patch('os.listdir') as _listdir:
568+
with patch('mbed_lstools.lstools_base.MbedDetectLsToolsBase._read_htm_ids') as _read_htm,\
569+
patch('mbed_lstools.lstools_base.MbedDetectLsToolsBase.mount_point_ready') as _mpr,\
570+
patch('mbed_os_tools.detect.platform_database.PlatformDatabase.get') as _get,\
571+
patch("mbed_os_tools.detect.lstools_base.listdir") as _listdir:
570572
_mpr.return_value = True
571573
_read_htm.return_value = (u'0240DEADBEEF', {})
572574
_get.return_value = {

legacy/mbed-ls/test/os_linux_generic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ def do_open(path, mode='r'):
9393
with patch('mbed_lstools.linux.MbedLsToolsLinuxGeneric._run_cli_process') as _cliproc,\
9494
patch('os.readlink') as _readlink,\
9595
patch('os.listdir') as _listdir,\
96-
patch('mbed_lstools.linux.abspath') as _abspath,\
97-
patch('mbed_lstools.linux.open', do_open) as _,\
98-
patch('mbed_lstools.linux.isdir') as _isdir:
96+
patch('os.path.abspath') as _abspath,\
97+
patch('mbed_os_tools.detect.linux.open', do_open) as _,\
98+
patch('os.path.isdir') as _isdir:
9999
_isdir.return_value = True
100100
_cliproc.return_value = (b'\n'.join(mount_list), None, 0)
101101
def do_readlink(link):

0 commit comments

Comments
 (0)