the other jimmy / mbed-sdk-tools

Fork of mbed-sdk-tools by mbed official

Committer:
The Other Jimmy
Date:
Wed Jan 04 11:58:24 2017 -0600
Revision:
31:182518299918
Update tools to follow mbed-os tools release 5.3.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
The Other Jimmy 31:182518299918 1 """
The Other Jimmy 31:182518299918 2 mbed SDK
The Other Jimmy 31:182518299918 3 Copyright (c) 2016 ARM Limited
The Other Jimmy 31:182518299918 4
The Other Jimmy 31:182518299918 5 Licensed under the Apache License, Version 2.0 (the "License");
The Other Jimmy 31:182518299918 6 you may not use this file except in compliance with the License.
The Other Jimmy 31:182518299918 7 You may obtain a copy of the License at
The Other Jimmy 31:182518299918 8
The Other Jimmy 31:182518299918 9 http://www.apache.org/licenses/LICENSE-2.0
The Other Jimmy 31:182518299918 10
The Other Jimmy 31:182518299918 11 Unless required by applicable law or agreed to in writing, software
The Other Jimmy 31:182518299918 12 distributed under the License is distributed on an "AS IS" BASIS,
The Other Jimmy 31:182518299918 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
The Other Jimmy 31:182518299918 14 See the License for the specific language governing permissions and
The Other Jimmy 31:182518299918 15 limitations under the License.
The Other Jimmy 31:182518299918 16 """
The Other Jimmy 31:182518299918 17
The Other Jimmy 31:182518299918 18 import unittest
The Other Jimmy 31:182518299918 19 from mock import patch
The Other Jimmy 31:182518299918 20 from tools.test_api import find_tests, build_tests
The Other Jimmy 31:182518299918 21
The Other Jimmy 31:182518299918 22 """
The Other Jimmy 31:182518299918 23 Tests for test_api.py
The Other Jimmy 31:182518299918 24 """
The Other Jimmy 31:182518299918 25
The Other Jimmy 31:182518299918 26 class TestApiTests(unittest.TestCase):
The Other Jimmy 31:182518299918 27 """
The Other Jimmy 31:182518299918 28 Test cases for Test Api
The Other Jimmy 31:182518299918 29 """
The Other Jimmy 31:182518299918 30
The Other Jimmy 31:182518299918 31 def setUp(self):
The Other Jimmy 31:182518299918 32 """
The Other Jimmy 31:182518299918 33 Called before each test case
The Other Jimmy 31:182518299918 34
The Other Jimmy 31:182518299918 35 :return:
The Other Jimmy 31:182518299918 36 """
The Other Jimmy 31:182518299918 37 self.base_dir = 'base_dir'
The Other Jimmy 31:182518299918 38 self.target = "K64F"
The Other Jimmy 31:182518299918 39 self.toolchain_name = "ARM"
The Other Jimmy 31:182518299918 40
The Other Jimmy 31:182518299918 41 def tearDown(self):
The Other Jimmy 31:182518299918 42 """
The Other Jimmy 31:182518299918 43 Called after each test case
The Other Jimmy 31:182518299918 44
The Other Jimmy 31:182518299918 45 :return:
The Other Jimmy 31:182518299918 46 """
The Other Jimmy 31:182518299918 47 pass
The Other Jimmy 31:182518299918 48
The Other Jimmy 31:182518299918 49 @patch('tools.test_api.scan_resources')
The Other Jimmy 31:182518299918 50 @patch('tools.test_api.prepare_toolchain')
The Other Jimmy 31:182518299918 51 def test_find_tests_app_config(self, mock_prepare_toolchain, mock_scan_resources):
The Other Jimmy 31:182518299918 52 """
The Other Jimmy 31:182518299918 53 Test find_tests for correct use of app_config
The Other Jimmy 31:182518299918 54
The Other Jimmy 31:182518299918 55 :param mock_prepare_toolchain: mock of function prepare_toolchain
The Other Jimmy 31:182518299918 56 :param mock_scan_resources: mock of function scan_resources
The Other Jimmy 31:182518299918 57 :return:
The Other Jimmy 31:182518299918 58 """
The Other Jimmy 31:182518299918 59 app_config = "app_config"
The Other Jimmy 31:182518299918 60 mock_scan_resources().inc_dirs.return_value = []
The Other Jimmy 31:182518299918 61
The Other Jimmy 31:182518299918 62 find_tests(self.base_dir, self.target, self.toolchain_name, app_config=app_config)
The Other Jimmy 31:182518299918 63
The Other Jimmy 31:182518299918 64 args = mock_prepare_toolchain.call_args
The Other Jimmy 31:182518299918 65 self.assertTrue('app_config' in args[1],
The Other Jimmy 31:182518299918 66 "prepare_toolchain was not called with app_config")
The Other Jimmy 31:182518299918 67 self.assertEqual(args[1]['app_config'], app_config,
The Other Jimmy 31:182518299918 68 "prepare_toolchain was called with an incorrect app_config")
The Other Jimmy 31:182518299918 69
The Other Jimmy 31:182518299918 70 @patch('tools.test_api.scan_resources')
The Other Jimmy 31:182518299918 71 @patch('tools.test_api.prepare_toolchain')
The Other Jimmy 31:182518299918 72 def test_find_tests_no_app_config(self, mock_prepare_toolchain, mock_scan_resources):
The Other Jimmy 31:182518299918 73 """
The Other Jimmy 31:182518299918 74 Test find_tests correctly deals with no app_config
The Other Jimmy 31:182518299918 75
The Other Jimmy 31:182518299918 76 :param mock_prepare_toolchain: mock of function prepare_toolchain
The Other Jimmy 31:182518299918 77 :param mock_scan_resources: mock of function scan_resources
The Other Jimmy 31:182518299918 78 :return:
The Other Jimmy 31:182518299918 79 """
The Other Jimmy 31:182518299918 80 mock_scan_resources().inc_dirs.return_value = []
The Other Jimmy 31:182518299918 81
The Other Jimmy 31:182518299918 82 find_tests(self.base_dir, self.target, self.toolchain_name)
The Other Jimmy 31:182518299918 83
The Other Jimmy 31:182518299918 84 args = mock_prepare_toolchain.call_args
The Other Jimmy 31:182518299918 85 self.assertTrue('app_config' in args[1],
The Other Jimmy 31:182518299918 86 "prepare_toolchain was not called with app_config")
The Other Jimmy 31:182518299918 87 self.assertEqual(args[1]['app_config'], None,
The Other Jimmy 31:182518299918 88 "prepare_toolchain was called with an incorrect app_config")
The Other Jimmy 31:182518299918 89
The Other Jimmy 31:182518299918 90 @patch('tools.test_api.scan_resources')
The Other Jimmy 31:182518299918 91 @patch('tools.test_api.build_project')
The Other Jimmy 31:182518299918 92 def test_build_tests_app_config(self, mock_build_project, mock_scan_resources):
The Other Jimmy 31:182518299918 93 """
The Other Jimmy 31:182518299918 94 Test build_tests for correct use of app_config
The Other Jimmy 31:182518299918 95
The Other Jimmy 31:182518299918 96 :param mock_prepare_toolchain: mock of function prepare_toolchain
The Other Jimmy 31:182518299918 97 :param mock_scan_resources: mock of function scan_resources
The Other Jimmy 31:182518299918 98 :return:
The Other Jimmy 31:182518299918 99 """
The Other Jimmy 31:182518299918 100 tests = {'test1': 'test1_path','test2': 'test2_path'}
The Other Jimmy 31:182518299918 101 src_paths = ['.']
The Other Jimmy 31:182518299918 102 build_path = "build_path"
The Other Jimmy 31:182518299918 103 app_config = "app_config"
The Other Jimmy 31:182518299918 104 mock_build_project.return_value = "build_project"
The Other Jimmy 31:182518299918 105
The Other Jimmy 31:182518299918 106 build_tests(tests, src_paths, build_path, self.target, self.toolchain_name,
The Other Jimmy 31:182518299918 107 app_config=app_config)
The Other Jimmy 31:182518299918 108
The Other Jimmy 31:182518299918 109 arg_list = mock_build_project.call_args_list
The Other Jimmy 31:182518299918 110 for args in arg_list:
The Other Jimmy 31:182518299918 111 self.assertTrue('app_config' in args[1],
The Other Jimmy 31:182518299918 112 "build_tests was not called with app_config")
The Other Jimmy 31:182518299918 113 self.assertEqual(args[1]['app_config'], app_config,
The Other Jimmy 31:182518299918 114 "build_tests was called with an incorrect app_config")
The Other Jimmy 31:182518299918 115
The Other Jimmy 31:182518299918 116 @patch('tools.test_api.scan_resources')
The Other Jimmy 31:182518299918 117 @patch('tools.test_api.build_project')
The Other Jimmy 31:182518299918 118 def test_build_tests_no_app_config(self, mock_build_project, mock_scan_resources):
The Other Jimmy 31:182518299918 119 """
The Other Jimmy 31:182518299918 120 Test build_tests correctly deals with no app_config
The Other Jimmy 31:182518299918 121
The Other Jimmy 31:182518299918 122 :param mock_prepare_toolchain: mock of function prepare_toolchain
The Other Jimmy 31:182518299918 123 :param mock_scan_resources: mock of function scan_resources
The Other Jimmy 31:182518299918 124 :return:
The Other Jimmy 31:182518299918 125 """
The Other Jimmy 31:182518299918 126 tests = {'test1': 'test1_path', 'test2': 'test2_path'}
The Other Jimmy 31:182518299918 127 src_paths = ['.']
The Other Jimmy 31:182518299918 128 build_path = "build_path"
The Other Jimmy 31:182518299918 129 mock_build_project.return_value = "build_project"
The Other Jimmy 31:182518299918 130
The Other Jimmy 31:182518299918 131 build_tests(tests, src_paths, build_path, self.target, self.toolchain_name)
The Other Jimmy 31:182518299918 132
The Other Jimmy 31:182518299918 133 arg_list = mock_build_project.call_args_list
The Other Jimmy 31:182518299918 134 for args in arg_list:
The Other Jimmy 31:182518299918 135 self.assertTrue('app_config' in args[1],
The Other Jimmy 31:182518299918 136 "build_tests was not called with app_config")
The Other Jimmy 31:182518299918 137 self.assertEqual(args[1]['app_config'], None,
The Other Jimmy 31:182518299918 138 "build_tests was called with an incorrect app_config")
The Other Jimmy 31:182518299918 139
The Other Jimmy 31:182518299918 140 if __name__ == '__main__':
The Other Jimmy 31:182518299918 141 unittest.main()