From f26d1276a48cbdcafa77aeea44eb253b1b5147c9 Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Fri, 29 Sep 2017 10:59:46 -0500 Subject: [PATCH 1/3] Test for invalid formatted keywords in targets.json --- test/mbed_gt_target_info.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/mbed_gt_target_info.py b/test/mbed_gt_target_info.py index e3f0a6aa..a3cbd0a4 100644 --- a/test/mbed_gt_target_info.py +++ b/test/mbed_gt_target_info.py @@ -185,15 +185,16 @@ def test_parse_yotta_search_cmd_output_with_ssl_errors(self): 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 From 687b11bc0db74ffd01e64c4e8fe6cb44e10113db Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Fri, 29 Sep 2017 11:08:22 -0500 Subject: [PATCH 2/3] Remove exception from target json data parsing --- mbed_greentea/mbed_target_info.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/mbed_greentea/mbed_target_info.py b/mbed_greentea/mbed_target_info.py index d6a79494..547858db 100644 --- a/mbed_greentea/mbed_target_info.py +++ b/mbed_greentea/mbed_target_info.py @@ -241,25 +241,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 From 241e50edb5daa00e0e4d5fefd66595867ab24e5d Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Wed, 25 Oct 2017 10:04:51 -0500 Subject: [PATCH 3/3] Test for no name or keywords arguments --- test/mbed_gt_target_info.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/mbed_gt_target_info.py b/test/mbed_gt_target_info.py index a3cbd0a4..1b5205a7 100644 --- a/test/mbed_gt_target_info.py +++ b/test/mbed_gt_target_info.py @@ -183,6 +183,31 @@ 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",