Clone of official tools

Committer:
The Other Jimmy
Date:
Wed Feb 15 13:53:18 2017 -0600
Revision:
35:da9c89f8be7d
Parent:
31:8ea194f6145b
Update tools to mbed-os 5.3.5

Who changed what in which revision?

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