Skip to content

Add test for missing retarget coverage #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion test/mbedls_toolsbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import errno
import logging
import re
from mock import patch
import json
from io import StringIO
from mock import patch, mock_open
from copy import deepcopy

from mbed_lstools.lstools_base import MbedLsToolsBase, FSInteraction
Expand Down Expand Up @@ -188,5 +190,40 @@ def test_fs_before(self):
self.assertIsNone(ret)
_read_htm.assert_called_with(device['mount_point'])

class RetargetTestCase(unittest.TestCase):
""" Test cases that makes use of retargetting
"""

def setUp(self):
retarget_data = {
'0240DEADBEEF': {
'serial_port' : 'valid'
}
}

_open = mock_open(read_data=json.dumps(retarget_data))

with patch('os.path.isfile') as _isfile,\
patch('mbed_lstools.lstools_base.open', _open):
self.base = DummyLsTools()
_open.assert_called()

def tearDown(self):
pass

def test_list_mbeds_valid_platform(self):
self.base.return_value = [{'mount_point': 'dummy_mount_point',
'target_id_usb_id': u'0240DEADBEEF',
'serial_port': None}]
with patch('mbed_lstools.lstools_base.MbedLsToolsBase._read_htm_ids') as _read_htm,\
patch('mbed_lstools.lstools_base.MbedLsToolsBase.mount_point_ready') as _mpr,\
patch('mbed_lstools.lstools_base.PlatformDatabase.get') as _get:
_mpr.return_value = True
_read_htm.return_value = (u'0240DEADBEEF', {})
_get.return_value = 'foo_target'
to_check = self.base.list_mbeds()
self.assertEqual(len(to_check), 1)
self.assertEqual(to_check[0]['serial_port'], 'valid')

if __name__ == '__main__':
unittest.main()