mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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