|
21 | 21 | import errno
|
22 | 22 | import logging
|
23 | 23 | import re
|
24 |
| -from mock import patch |
| 24 | +import json |
| 25 | +from io import StringIO |
| 26 | +from mock import patch, mock_open |
25 | 27 | from copy import deepcopy
|
26 | 28 |
|
27 | 29 | from mbed_lstools.lstools_base import MbedLsToolsBase, FSInteraction
|
@@ -188,5 +190,40 @@ def test_fs_before(self):
|
188 | 190 | self.assertIsNone(ret)
|
189 | 191 | _read_htm.assert_called_with(device['mount_point'])
|
190 | 192 |
|
| 193 | +class RetargetTestCase(unittest.TestCase): |
| 194 | + """ Basic test cases checking trivial asserts |
| 195 | + """ |
| 196 | + |
| 197 | + def setUp(self): |
| 198 | + retarget_data = { |
| 199 | + '0240DEADBEEF': { |
| 200 | + 'serial_port' : 'valid' |
| 201 | + } |
| 202 | + } |
| 203 | + |
| 204 | + _open = mock_open(read_data=json.dumps(retarget_data)) |
| 205 | + |
| 206 | + with patch('os.path.isfile') as _isfile,\ |
| 207 | + patch('mbed_lstools.lstools_base.open', _open): |
| 208 | + self.base = DummyLsTools() |
| 209 | + _open.assert_called() |
| 210 | + |
| 211 | + def tearDown(self): |
| 212 | + pass |
| 213 | + |
| 214 | + def test_list_mbeds_valid_platform(self): |
| 215 | + self.base.return_value = [{'mount_point': 'dummy_mount_point', |
| 216 | + 'target_id_usb_id': u'0240DEADBEEF', |
| 217 | + 'serial_port': None}] |
| 218 | + with patch('mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids') as _read_htm,\ |
| 219 | + patch('mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready') as _mpr,\ |
| 220 | + patch('mbed_lstools.lstools_base.PlatformDatabase.get') as _get: |
| 221 | + _mpr.return_value = True |
| 222 | + _read_htm.return_value = (u'0240DEADBEEF', {}) |
| 223 | + _get.return_value = 'foo_target' |
| 224 | + to_check = self.base.list_mbeds() |
| 225 | + self.assertEqual(len(to_check), 1) |
| 226 | + self.assertEqual(to_check[0]['serial_port'], 'valid') |
| 227 | + |
191 | 228 | if __name__ == '__main__':
|
192 | 229 | unittest.main()
|
0 commit comments