Skip to content

Commit faec0c3

Browse files
committed
Fixed call to deprecated get_details_txt
1 parent 4d81ead commit faec0c3

File tree

2 files changed

+73
-55
lines changed

2 files changed

+73
-55
lines changed

tools/detect_targets.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,14 @@ def get_interface_version(mount_point):
112112
"""
113113
if get_module_avail('mbed_lstools'):
114114
try :
115-
mbeds = mbed_lstools.create()
116-
details_txt = mbeds.get_details_txt(mount_point)
115+
mbedls = mbed_lstools.create()
116+
mbeds = mbedls.list_mbeds(unique_names=True, read_details_txt=True)
117117

118-
if 'Interface Version' in details_txt:
119-
return details_txt['Interface Version']
120-
121-
elif 'Version' in details_txt:
122-
return details_txt['Version']
118+
for mbed in mbeds:
119+
if mbed['mount_point'] == mount_point:
123120

121+
if 'daplink_version' in mbed:
122+
return mbed['daplink_version']
124123
except :
125124
return 'unknown'
126125

tools/test/detect_targets_test.py

Lines changed: 67 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,60 @@ class MbedLsToolsMock():
2828
def __init__(self, test_type):
2929
self.interface_test_type = test_type
3030

31-
def get_details_txt(self, mount_point):
32-
return self.details_txt_types[self.interface_test_type];
31+
def list_mbeds(self, unique_names=False, read_details_txt=False):
32+
return self.mbed_types[self.interface_test_type];
3333

3434
# Static details.txt types.
35-
details_txt_types = {
36-
'details_valid_interface_version' : {
37-
'Unique ID': '0226000029164e45002f0012706e0006f301000097969900',
38-
'HIF ID': '97969900',
39-
'Auto Reset': '0',
40-
'Automation allowed': '0',
41-
'Daplink Mode': 'Interface',
42-
'Interface Version': '0240',
43-
'Git SHA': 'c765cbb590f57598756683254ca38b211693ae5e',
44-
'Local Mods': '0',
45-
'USB Interfaces': 'MSD, CDC, HID',
46-
'Interface CRC': '0x26764ebf'
47-
},
48-
'details_valid_version' : {
49-
'Version': '0226',
50-
'Build': 'Aug 24 2015 17:06:30',
51-
'Git Commit SHA': '27a236b9fe39c674a703c5c89655fbd26b8e27e1',
52-
'Git Local mods': 'Yes'
53-
},
54-
'details_missing_interface_version' : {
55-
'Unique ID': '0226000033514e450044500585d4001de981000097969900',
56-
'HIC ID': '97969900',
57-
'Auto Reset': '0',
58-
'Automation allowed': '0',
59-
'Overflow detection': '0',
60-
'Daplink Mode': 'Interface',
61-
'Git SHA': 'b403a07e3696cee1e116d44cbdd64446e056ce38',
62-
'Local Mods': '0',
63-
'USB Interfaces': 'MSD, CDC, HID',
64-
'Interface CRC': '0x4d98bf7e',
65-
'Remount count': '0'
66-
},
35+
mbed_types = {
36+
'details_valid_interface_version' : [{
37+
'daplink_hic_id': u'97969900',
38+
'daplink_version': u'0244',
39+
'target_id': u'0240000034544e45001500048e41001b8321000097969900',
40+
'serial_port': u'COM3',
41+
'target_id_usb_id': u'0240000034544e45001500048e41001b8321000097969900',
42+
'daplink_auto_reset': u'0',
43+
'daplink_git_sha': u'392f85aa88a41125dec0b963ce73c6795b8bdd0d',
44+
'daplink_interface_version': u'0244',
45+
'daplink_overflow_detection': u'0',
46+
'daplink_daplink_mode': u'Interface',
47+
'target_id_mbed_htm': u'0240000034544e45001500048e41001b8321000097969900',
48+
'mount_point': 'D:',
49+
'daplink_automation_allowed': u'0',
50+
'daplink_interface_crc': u'0xc525d856',
51+
'daplink_local_mods': u'0',
52+
'daplink_unique_id': u'0240000034544e45001500048e41001b8321000097969900',
53+
'daplink_remount_count': u'0',
54+
'daplink_bootloader_crc': u'0xc4ebf65c',
55+
'platform_name': u'K64F',
56+
'platform_name_unique': u'K64F[0]',
57+
'daplink_bootloader_version': u'0244',
58+
'daplink_usb_interfaces': u'MSD, CDC, HID'
59+
60+
}],
61+
'details_missing_interface_version' : [{
62+
'daplink_hic_id': u'97969900',
63+
'target_id': u'0240000034544e45001500048e41001b8321000097969900',
64+
'serial_port': u'COM3',
65+
'target_id_usb_id': u'0240000034544e45001500048e41001b8321000097969900',
66+
'daplink_auto_reset': u'0',
67+
'daplink_git_sha': u'392f85aa88a41125dec0b963ce73c6795b8bdd0d',
68+
'daplink_interface_version': u'0244',
69+
'daplink_overflow_detection': u'0',
70+
'daplink_daplink_mode': u'Interface',
71+
'target_id_mbed_htm': u'0240000034544e45001500048e41001b8321000097969900',
72+
'mount_point': 'D:',
73+
'daplink_automation_allowed': u'0',
74+
'daplink_interface_crc': u'0xc525d856',
75+
'daplink_local_mods': u'0',
76+
'daplink_unique_id': u'0240000034544e45001500048e41001b8321000097969900',
77+
'daplink_remount_count': u'0',
78+
'daplink_bootloader_crc': u'0xc4ebf65c',
79+
'platform_name': u'K64F',
80+
'platform_name_unique': u'K64F[0]',
81+
'daplink_bootloader_version': u'0244',
82+
'daplink_usb_interfaces': u'MSD, CDC, HID'
83+
84+
}],
6785
'details_invalid_none' : None
6886
}
6987

@@ -84,6 +102,7 @@ def setUp(self):
84102
"""
85103
self.missing_mount_point = None
86104
self.mount_point = "D:"
105+
self.invalid_mount_point = "F:"
87106

88107
def tearDown(self):
89108
"""
@@ -102,21 +121,9 @@ def test_interface_version_valid(self, mbed_lstools_mock):
102121
:param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
103122
:return
104123
"""
105-
106-
interface_version = get_interface_version(self.mount_point)
107-
assert interface_version == '0240'
108124

109-
@patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_valid_version'))
110-
def test_version_valid(self, mbed_lstools_mock):
111-
"""
112-
Test that checks function returns correctly when given a valid Version
113-
114-
:param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
115-
:return
116-
"""
117-
118125
interface_version = get_interface_version(self.mount_point)
119-
assert interface_version == '0226'
126+
assert interface_version == '0244'
120127

121128
@patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_missing_interface_version'))
122129
def test_interface_version_missing_interface_version(self, mbed_lstools_mock):
@@ -143,7 +150,19 @@ def test_version_none(self, mbed_lstools_mock):
143150

144151
interface_version = get_interface_version(self.mount_point)
145152
assert interface_version == 'unknown'
146-
153+
154+
@patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_valid_interface_version'))
155+
def test_interface_version_wrong_mount_point(self, mbed_lstools_mock):
156+
"""
157+
Test that checks function returns correctly when there is no board attached to supplied mount point.
158+
159+
:param mbed_lstools_mock: Mocks Mbed LS tools with MbedLsToolsMock
160+
:return
161+
"""
162+
163+
interface_version = get_interface_version(self.invalid_mount_point)
164+
assert interface_version == 'unknown'
165+
147166
@patch("mbed_lstools.create", return_value=MbedLsToolsMock('details_invalid_none'))
148167
def test_interface_version_missing_mount_point(self, mbed_lstools_mock):
149168
"""

0 commit comments

Comments
 (0)