mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

UserRevisionLine numberNew contents of line
be_bryan 0:b74591d5ab33 1 """
be_bryan 0:b74591d5ab33 2 mbed SDK
be_bryan 0:b74591d5ab33 3 Copyright (c) 2016 ARM Limited
be_bryan 0:b74591d5ab33 4
be_bryan 0:b74591d5ab33 5 Licensed under the Apache License, Version 2.0 (the "License");
be_bryan 0:b74591d5ab33 6 you may not use this file except in compliance with the License.
be_bryan 0:b74591d5ab33 7 You may obtain a copy of the License at
be_bryan 0:b74591d5ab33 8
be_bryan 0:b74591d5ab33 9 http://www.apache.org/licenses/LICENSE-2.0
be_bryan 0:b74591d5ab33 10
be_bryan 0:b74591d5ab33 11 Unless required by applicable law or agreed to in writing, software
be_bryan 0:b74591d5ab33 12 distributed under the License is distributed on an "AS IS" BASIS,
be_bryan 0:b74591d5ab33 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
be_bryan 0:b74591d5ab33 14 See the License for the specific language governing permissions and
be_bryan 0:b74591d5ab33 15 limitations under the License.
be_bryan 0:b74591d5ab33 16 """
be_bryan 0:b74591d5ab33 17
be_bryan 0:b74591d5ab33 18 import pytest
be_bryan 0:b74591d5ab33 19 from mock import patch
be_bryan 0:b74591d5ab33 20 from tools.targets import set_targets_json_location
be_bryan 0:b74591d5ab33 21 from tools.test_api import find_tests, build_tests
be_bryan 0:b74591d5ab33 22
be_bryan 0:b74591d5ab33 23 """
be_bryan 0:b74591d5ab33 24 Tests for test_api.py
be_bryan 0:b74591d5ab33 25 """
be_bryan 0:b74591d5ab33 26
be_bryan 0:b74591d5ab33 27 def setUp(self):
be_bryan 0:b74591d5ab33 28 """
be_bryan 0:b74591d5ab33 29 Called before each test case
be_bryan 0:b74591d5ab33 30
be_bryan 0:b74591d5ab33 31 :return:
be_bryan 0:b74591d5ab33 32 """
be_bryan 0:b74591d5ab33 33 self.base_dir = 'base_dir'
be_bryan 0:b74591d5ab33 34 self.target = "K64F"
be_bryan 0:b74591d5ab33 35 self.toolchain_name = "ARM"
be_bryan 0:b74591d5ab33 36
be_bryan 0:b74591d5ab33 37 @pytest.mark.parametrize("base_dir", ["base_dir"])
be_bryan 0:b74591d5ab33 38 @pytest.mark.parametrize("target", ["K64F"])
be_bryan 0:b74591d5ab33 39 @pytest.mark.parametrize("toolchain_name", ["ARM"])
be_bryan 0:b74591d5ab33 40 @pytest.mark.parametrize("app_config", ["app_config", None])
be_bryan 0:b74591d5ab33 41 def test_find_tests_app_config(base_dir, target, toolchain_name, app_config):
be_bryan 0:b74591d5ab33 42 """
be_bryan 0:b74591d5ab33 43 Test find_tests for correct use of app_config
be_bryan 0:b74591d5ab33 44
be_bryan 0:b74591d5ab33 45 :param base_dir: dummy value for the test base directory
be_bryan 0:b74591d5ab33 46 :param target: the target to "test" for
be_bryan 0:b74591d5ab33 47 :param toolchain_name: the toolchain to use for "testing"
be_bryan 0:b74591d5ab33 48 :param app_config: Application configuration parameter to find tests
be_bryan 0:b74591d5ab33 49 """
be_bryan 0:b74591d5ab33 50 set_targets_json_location()
be_bryan 0:b74591d5ab33 51 with patch('tools.test_api.scan_resources') as mock_scan_resources,\
be_bryan 0:b74591d5ab33 52 patch('tools.test_api.prepare_toolchain') as mock_prepare_toolchain:
be_bryan 0:b74591d5ab33 53 mock_scan_resources().inc_dirs.return_value = []
be_bryan 0:b74591d5ab33 54
be_bryan 0:b74591d5ab33 55 find_tests(base_dir, target, toolchain_name, app_config=app_config)
be_bryan 0:b74591d5ab33 56
be_bryan 0:b74591d5ab33 57 args = mock_prepare_toolchain.call_args
be_bryan 0:b74591d5ab33 58 assert 'app_config' in args[1],\
be_bryan 0:b74591d5ab33 59 "prepare_toolchain was not called with app_config"
be_bryan 0:b74591d5ab33 60 assert args[1]['app_config'] == app_config,\
be_bryan 0:b74591d5ab33 61 "prepare_toolchain was called with an incorrect app_config"
be_bryan 0:b74591d5ab33 62
be_bryan 0:b74591d5ab33 63
be_bryan 0:b74591d5ab33 64 @pytest.mark.parametrize("build_path", ["build_path"])
be_bryan 0:b74591d5ab33 65 @pytest.mark.parametrize("target", ["K64F"])
be_bryan 0:b74591d5ab33 66 @pytest.mark.parametrize("toolchain_name", ["ARM"])
be_bryan 0:b74591d5ab33 67 @pytest.mark.parametrize("app_config", ["app_config", None])
be_bryan 0:b74591d5ab33 68 def test_find_tests_app_config(build_path, target, toolchain_name, app_config):
be_bryan 0:b74591d5ab33 69 """
be_bryan 0:b74591d5ab33 70 Test find_tests for correct use of app_config
be_bryan 0:b74591d5ab33 71
be_bryan 0:b74591d5ab33 72 :param base_dir: dummy value for the test base directory
be_bryan 0:b74591d5ab33 73 :param target: the target to "test" for
be_bryan 0:b74591d5ab33 74 :param toolchain_name: the toolchain to use for "testing"
be_bryan 0:b74591d5ab33 75 :param app_config: Application configuration parameter to find tests
be_bryan 0:b74591d5ab33 76 """
be_bryan 0:b74591d5ab33 77 tests = {'test1': 'test1_path','test2': 'test2_path'}
be_bryan 0:b74591d5ab33 78 src_paths = ['.']
be_bryan 0:b74591d5ab33 79 set_targets_json_location()
be_bryan 0:b74591d5ab33 80 with patch('tools.test_api.scan_resources') as mock_scan_resources,\
be_bryan 0:b74591d5ab33 81 patch('tools.test_api.build_project') as mock_build_project:
be_bryan 0:b74591d5ab33 82 mock_build_project.return_value = "build_project"
be_bryan 0:b74591d5ab33 83 mock_scan_resources().inc_dirs.return_value = []
be_bryan 0:b74591d5ab33 84
be_bryan 0:b74591d5ab33 85 build_tests(tests, src_paths, build_path, target, toolchain_name,
be_bryan 0:b74591d5ab33 86 app_config=app_config)
be_bryan 0:b74591d5ab33 87
be_bryan 0:b74591d5ab33 88 arg_list = mock_build_project.call_args_list
be_bryan 0:b74591d5ab33 89 for args in arg_list:
be_bryan 0:b74591d5ab33 90 assert 'app_config' in args[1],\
be_bryan 0:b74591d5ab33 91 "build_tests was not called with app_config"
be_bryan 0:b74591d5ab33 92 assert args[1]['app_config'] == app_config,\
be_bryan 0:b74591d5ab33 93 "build_tests was called with an incorrect app_config"