Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
test_api_test.py
00001 """ 00002 mbed SDK 00003 Copyright (c) 2016 ARM Limited 00004 00005 Licensed under the Apache License, Version 2.0 (the "License"); 00006 you may not use this file except in compliance with the License. 00007 You may obtain a copy of the License at 00008 00009 http://www.apache.org/licenses/LICENSE-2.0 00010 00011 Unless required by applicable law or agreed to in writing, software 00012 distributed under the License is distributed on an "AS IS" BASIS, 00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 See the License for the specific language governing permissions and 00015 limitations under the License. 00016 """ 00017 00018 import unittest 00019 from mock import patch 00020 from tools.test_api import find_tests, build_tests 00021 00022 """ 00023 Tests for test_api.py 00024 """ 00025 00026 class TestApiTests (unittest.TestCase): 00027 """ 00028 Test cases for Test Api 00029 """ 00030 00031 def setUp (self): 00032 """ 00033 Called before each test case 00034 00035 :return: 00036 """ 00037 self.base_dir = 'base_dir' 00038 self.target = "K64F" 00039 self.toolchain_name = "ARM" 00040 00041 def tearDown (self): 00042 """ 00043 Called after each test case 00044 00045 :return: 00046 """ 00047 pass 00048 00049 @patch('tools.test_api.scan_resources') 00050 @patch('tools.test_api.prepare_toolchain') 00051 def test_find_tests_app_config (self, mock_prepare_toolchain, mock_scan_resources): 00052 """ 00053 Test find_tests for correct use of app_config 00054 00055 :param mock_prepare_toolchain: mock of function prepare_toolchain 00056 :param mock_scan_resources: mock of function scan_resources 00057 :return: 00058 """ 00059 app_config = "app_config" 00060 mock_scan_resources().inc_dirs.return_value = [] 00061 00062 find_tests(self.base_dir , self.target , self.toolchain_name , app_config=app_config) 00063 00064 args = mock_prepare_toolchain.call_args 00065 self.assertTrue('app_config' in args[1], 00066 "prepare_toolchain was not called with app_config") 00067 self.assertEqual(args[1]['app_config'], app_config, 00068 "prepare_toolchain was called with an incorrect app_config") 00069 00070 @patch('tools.test_api.scan_resources') 00071 @patch('tools.test_api.prepare_toolchain') 00072 def test_find_tests_no_app_config (self, mock_prepare_toolchain, mock_scan_resources): 00073 """ 00074 Test find_tests correctly deals with no app_config 00075 00076 :param mock_prepare_toolchain: mock of function prepare_toolchain 00077 :param mock_scan_resources: mock of function scan_resources 00078 :return: 00079 """ 00080 mock_scan_resources().inc_dirs.return_value = [] 00081 00082 find_tests(self.base_dir , self.target , self.toolchain_name ) 00083 00084 args = mock_prepare_toolchain.call_args 00085 self.assertTrue('app_config' in args[1], 00086 "prepare_toolchain was not called with app_config") 00087 self.assertEqual(args[1]['app_config'], None, 00088 "prepare_toolchain was called with an incorrect app_config") 00089 00090 @patch('tools.test_api.scan_resources') 00091 @patch('tools.test_api.build_project') 00092 def test_build_tests_app_config (self, mock_build_project, mock_scan_resources): 00093 """ 00094 Test build_tests for correct use of app_config 00095 00096 :param mock_prepare_toolchain: mock of function prepare_toolchain 00097 :param mock_scan_resources: mock of function scan_resources 00098 :return: 00099 """ 00100 tests = {'test1': 'test1_path','test2': 'test2_path'} 00101 src_paths = ['.'] 00102 build_path = "build_path" 00103 app_config = "app_config" 00104 mock_build_project.return_value = "build_project" 00105 00106 build_tests(tests, src_paths, build_path, self.target , self.toolchain_name , 00107 app_config=app_config) 00108 00109 arg_list = mock_build_project.call_args_list 00110 for args in arg_list: 00111 self.assertTrue('app_config' in args[1], 00112 "build_tests was not called with app_config") 00113 self.assertEqual(args[1]['app_config'], app_config, 00114 "build_tests was called with an incorrect app_config") 00115 00116 @patch('tools.test_api.scan_resources') 00117 @patch('tools.test_api.build_project') 00118 def test_build_tests_no_app_config (self, mock_build_project, mock_scan_resources): 00119 """ 00120 Test build_tests correctly deals with no app_config 00121 00122 :param mock_prepare_toolchain: mock of function prepare_toolchain 00123 :param mock_scan_resources: mock of function scan_resources 00124 :return: 00125 """ 00126 tests = {'test1': 'test1_path', 'test2': 'test2_path'} 00127 src_paths = ['.'] 00128 build_path = "build_path" 00129 mock_build_project.return_value = "build_project" 00130 00131 build_tests(tests, src_paths, build_path, self.target , self.toolchain_name ) 00132 00133 arg_list = mock_build_project.call_args_list 00134 for args in arg_list: 00135 self.assertTrue('app_config' in args[1], 00136 "build_tests was not called with app_config") 00137 self.assertEqual(args[1]['app_config'], None, 00138 "build_tests was called with an incorrect app_config") 00139 00140 if __name__ == '__main__': 00141 unittest.main()
Generated on Tue Jul 12 2022 12:28:52 by
