Fixed call to deprecated get_details_txt

pull/5715/head
David Walters 2017-12-15 15:31:36 +00:00
parent 4d81eadb25
commit faec0c3ce5
2 changed files with 73 additions and 55 deletions

View File

@ -112,15 +112,14 @@ def get_interface_version(mount_point):
""" """
if get_module_avail('mbed_lstools'): if get_module_avail('mbed_lstools'):
try : try :
mbeds = mbed_lstools.create() mbedls = mbed_lstools.create()
details_txt = mbeds.get_details_txt(mount_point) mbeds = mbedls.list_mbeds(unique_names=True, read_details_txt=True)
if 'Interface Version' in details_txt: for mbed in mbeds:
return details_txt['Interface Version'] if mbed['mount_point'] == mount_point:
elif 'Version' in details_txt:
return details_txt['Version']
if 'daplink_version' in mbed:
return mbed['daplink_version']
except : except :
return 'unknown' return 'unknown'

View File

@ -28,42 +28,60 @@ class MbedLsToolsMock():
def __init__(self, test_type): def __init__(self, test_type):
self.interface_test_type = test_type self.interface_test_type = test_type
def get_details_txt(self, mount_point): def list_mbeds(self, unique_names=False, read_details_txt=False):
return self.details_txt_types[self.interface_test_type]; return self.mbed_types[self.interface_test_type];
# Static details.txt types. # Static details.txt types.
details_txt_types = { mbed_types = {
'details_valid_interface_version' : { 'details_valid_interface_version' : [{
'Unique ID': '0226000029164e45002f0012706e0006f301000097969900', 'daplink_hic_id': u'97969900',
'HIF ID': '97969900', 'daplink_version': u'0244',
'Auto Reset': '0', 'target_id': u'0240000034544e45001500048e41001b8321000097969900',
'Automation allowed': '0', 'serial_port': u'COM3',
'Daplink Mode': 'Interface', 'target_id_usb_id': u'0240000034544e45001500048e41001b8321000097969900',
'Interface Version': '0240', 'daplink_auto_reset': u'0',
'Git SHA': 'c765cbb590f57598756683254ca38b211693ae5e', 'daplink_git_sha': u'392f85aa88a41125dec0b963ce73c6795b8bdd0d',
'Local Mods': '0', 'daplink_interface_version': u'0244',
'USB Interfaces': 'MSD, CDC, HID', 'daplink_overflow_detection': u'0',
'Interface CRC': '0x26764ebf' 'daplink_daplink_mode': u'Interface',
}, 'target_id_mbed_htm': u'0240000034544e45001500048e41001b8321000097969900',
'details_valid_version' : { 'mount_point': 'D:',
'Version': '0226', 'daplink_automation_allowed': u'0',
'Build': 'Aug 24 2015 17:06:30', 'daplink_interface_crc': u'0xc525d856',
'Git Commit SHA': '27a236b9fe39c674a703c5c89655fbd26b8e27e1', 'daplink_local_mods': u'0',
'Git Local mods': 'Yes' 'daplink_unique_id': u'0240000034544e45001500048e41001b8321000097969900',
}, 'daplink_remount_count': u'0',
'details_missing_interface_version' : { 'daplink_bootloader_crc': u'0xc4ebf65c',
'Unique ID': '0226000033514e450044500585d4001de981000097969900', 'platform_name': u'K64F',
'HIC ID': '97969900', 'platform_name_unique': u'K64F[0]',
'Auto Reset': '0', 'daplink_bootloader_version': u'0244',
'Automation allowed': '0', 'daplink_usb_interfaces': u'MSD, CDC, HID'
'Overflow detection': '0',
'Daplink Mode': 'Interface', }],
'Git SHA': 'b403a07e3696cee1e116d44cbdd64446e056ce38', 'details_missing_interface_version' : [{
'Local Mods': '0', 'daplink_hic_id': u'97969900',
'USB Interfaces': 'MSD, CDC, HID', 'target_id': u'0240000034544e45001500048e41001b8321000097969900',
'Interface CRC': '0x4d98bf7e', 'serial_port': u'COM3',
'Remount count': '0' 'target_id_usb_id': u'0240000034544e45001500048e41001b8321000097969900',
}, 'daplink_auto_reset': u'0',
'daplink_git_sha': u'392f85aa88a41125dec0b963ce73c6795b8bdd0d',
'daplink_interface_version': u'0244',
'daplink_overflow_detection': u'0',
'daplink_daplink_mode': u'Interface',
'target_id_mbed_htm': u'0240000034544e45001500048e41001b8321000097969900',
'mount_point': 'D:',
'daplink_automation_allowed': u'0',
'daplink_interface_crc': u'0xc525d856',
'daplink_local_mods': u'0',
'daplink_unique_id': u'0240000034544e45001500048e41001b8321000097969900',
'daplink_remount_count': u'0',
'daplink_bootloader_crc': u'0xc4ebf65c',
'platform_name': u'K64F',
'platform_name_unique': u'K64F[0]',
'daplink_bootloader_version': u'0244',
'daplink_usb_interfaces': u'MSD, CDC, HID'
}],
'details_invalid_none' : None 'details_invalid_none' : None
} }
@ -84,6 +102,7 @@ class DetectTargetsTest(unittest.TestCase):
""" """
self.missing_mount_point = None self.missing_mount_point = None
self.mount_point = "D:" self.mount_point = "D:"
self.invalid_mount_point = "F:"
def tearDown(self): def tearDown(self):
""" """
@ -104,19 +123,7 @@ class DetectTargetsTest(unittest.TestCase):
""" """
interface_version = get_interface_version(self.mount_point) interface_version = get_interface_version(self.mount_point)
assert interface_version == '0240' assert interface_version == '0244'
@patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_valid_version'))
def test_version_valid(self, mbed_lstools_mock):
"""
Test that checks function returns correctly when given a valid Version
:param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
:return
"""
interface_version = get_interface_version(self.mount_point)
assert interface_version == '0226'
@patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_missing_interface_version')) @patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_missing_interface_version'))
def test_interface_version_missing_interface_version(self, mbed_lstools_mock): def test_interface_version_missing_interface_version(self, mbed_lstools_mock):
@ -144,6 +151,18 @@ class DetectTargetsTest(unittest.TestCase):
interface_version = get_interface_version(self.mount_point) interface_version = get_interface_version(self.mount_point)
assert interface_version == 'unknown' assert interface_version == 'unknown'
@patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_valid_interface_version'))
def test_interface_version_wrong_mount_point(self, mbed_lstools_mock):
"""
Test that checks function returns correctly when there is no board attached to supplied mount point.
:param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
:return
"""
interface_version = get_interface_version(self.invalid_mount_point)
assert interface_version == 'unknown'
@patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_invalid_none')) @patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_invalid_none'))
def test_interface_version_missing_mount_point(self, mbed_lstools_mock): def test_interface_version_missing_mount_point(self, mbed_lstools_mock):
""" """