Skip to content

Commit

Permalink
Merge pull request #242 from ARMmbed/f-invalid-target-json
Browse files Browse the repository at this point in the history
Remove traceback from parsing invalid keywords
  • Loading branch information
theotherjimmy authored Oct 25, 2017
2 parents 9818bb0 + 241e50e commit 747460c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
23 changes: 7 additions & 16 deletions mbed_greentea/mbed_target_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,25 +252,16 @@ def get_mbed_targets_from_yotta_local_module(mbed_classic_name, yotta_targets_pa
return result

def parse_mbed_target_from_target_json(mbed_classic_name, target_json_data):
if not target_json_data:
return None

if not 'keywords' in target_json_data:
if (not target_json_data or
'keywords' not in target_json_data or
'name' not in target_json_data):
return None

for keyword in target_json_data['keywords']:
if not keyword.startswith('mbed-target:'):
continue

mbed_target, mbed_name = keyword.split(':')

if mbed_name.lower() != mbed_classic_name.lower():
continue

if 'name' not in target_json_data:
continue

return target_json_data['name']
target, _, name = keyword.partition(':')
if (target == "mbed-target" and
name.lower() == mbed_classic_name.lower()):
return target_json_data['name']

return None

Expand Down
44 changes: 35 additions & 9 deletions test/mbed_gt_target_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,43 @@ def test_parse_yotta_search_cmd_output_with_ssl_errors(self):
self.assertIn("frdm-k64f-armcc", result)
self.assertEqual(2, len(result))

def test_parse_mbed_target_from_target_json_no_keywords(self):
target_json_data = {
"name": "frdm-k64f-armcc",
"version": "0.1.4",
}

self.assertIsNone(mbed_target_info.parse_mbed_target_from_target_json('k64f', target_json_data))
self.assertIsNone(mbed_target_info.parse_mbed_target_from_target_json('K64F', target_json_data))

def test_parse_mbed_target_from_target_json_no_name(self):
target_json_data = {
"version": "0.1.4",
"keywords": [
"mbed-target:k64f",
"mbed-target::garbage",
"mbed-official",
"k64f",
"frdm-k64f",
"armcc"
],
}

self.assertIsNone(mbed_target_info.parse_mbed_target_from_target_json('k64f', target_json_data))
self.assertIsNone(mbed_target_info.parse_mbed_target_from_target_json('K64F', target_json_data))

def test_parse_mbed_target_from_target_json(self):
target_json_data = {
"name": "frdm-k64f-armcc",
"version": "0.1.4",
"keywords": [
"mbed-target:k64f",
"mbed-official",
"k64f",
"frdm-k64f",
"armcc"
],
"name": "frdm-k64f-armcc",
"version": "0.1.4",
"keywords": [
"mbed-target:k64f",
"mbed-target::garbage",
"mbed-official",
"k64f",
"frdm-k64f",
"armcc"
],
}

# Positive tests
Expand Down

0 comments on commit 747460c

Please sign in to comment.