Greg Steiert / pegasus_dev

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Nov 11 20:59:50 2016 +0000
Revision:
0:5c4d7b2438d3
Initial commit

Who changed what in which revision?

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