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 os.path
dkato 0:f782d9c66c49 19 import unittest
dkato 0:f782d9c66c49 20 from mock import patch
dkato 0:f782d9c66c49 21 from tools.config import Config
dkato 0:f782d9c66c49 22
dkato 0:f782d9c66c49 23 """
dkato 0:f782d9c66c49 24 Tests for config.py
dkato 0:f782d9c66c49 25 """
dkato 0:f782d9c66c49 26
dkato 0:f782d9c66c49 27 class ConfigTests(unittest.TestCase):
dkato 0:f782d9c66c49 28 """
dkato 0:f782d9c66c49 29 Test cases for Config class
dkato 0:f782d9c66c49 30 """
dkato 0:f782d9c66c49 31
dkato 0:f782d9c66c49 32 def setUp(self):
dkato 0:f782d9c66c49 33 """
dkato 0:f782d9c66c49 34 Called before each test case
dkato 0:f782d9c66c49 35
dkato 0:f782d9c66c49 36 :return:
dkato 0:f782d9c66c49 37 """
dkato 0:f782d9c66c49 38 self.target = "K64F"
dkato 0:f782d9c66c49 39
dkato 0:f782d9c66c49 40 def tearDown(self):
dkato 0:f782d9c66c49 41 """
dkato 0:f782d9c66c49 42 Called after each test case
dkato 0:f782d9c66c49 43
dkato 0:f782d9c66c49 44 :return:
dkato 0:f782d9c66c49 45 """
dkato 0:f782d9c66c49 46 pass
dkato 0:f782d9c66c49 47
dkato 0:f782d9c66c49 48 @patch.object(Config, '_process_config_and_overrides')
dkato 0:f782d9c66c49 49 @patch('tools.config.json_file_to_dict')
dkato 0:f782d9c66c49 50 def test_init_app_config(self, mock_json_file_to_dict, _):
dkato 0:f782d9c66c49 51 """
dkato 0:f782d9c66c49 52 Test that the initialisation correctly uses app_config
dkato 0:f782d9c66c49 53
dkato 0:f782d9c66c49 54 :param mock_json_file_to_dict: mock of function json_file_to_dict
dkato 0:f782d9c66c49 55 :param _: mock of function _process_config_and_overrides (not tested)
dkato 0:f782d9c66c49 56 :return:
dkato 0:f782d9c66c49 57 """
dkato 0:f782d9c66c49 58 app_config = "app_config"
dkato 0:f782d9c66c49 59 mock_return = {'config': 'test'}
dkato 0:f782d9c66c49 60 mock_json_file_to_dict.return_value = mock_return
dkato 0:f782d9c66c49 61
dkato 0:f782d9c66c49 62 config = Config(self.target, app_config=app_config)
dkato 0:f782d9c66c49 63
dkato 0:f782d9c66c49 64 mock_json_file_to_dict.assert_called_with(app_config)
dkato 0:f782d9c66c49 65 self.assertEqual(config.app_config_data, mock_return,
dkato 0:f782d9c66c49 66 "app_config_data should be set to the returned value")
dkato 0:f782d9c66c49 67
dkato 0:f782d9c66c49 68 @patch.object(Config, '_process_config_and_overrides')
dkato 0:f782d9c66c49 69 @patch('tools.config.json_file_to_dict')
dkato 0:f782d9c66c49 70 def test_init_no_app_config(self, mock_json_file_to_dict, _):
dkato 0:f782d9c66c49 71 """
dkato 0:f782d9c66c49 72 Test that the initialisation works without app config
dkato 0:f782d9c66c49 73
dkato 0:f782d9c66c49 74 :param mock_json_file_to_dict: mock of function json_file_to_dict
dkato 0:f782d9c66c49 75 :param _: patch of function _process_config_and_overrides (not tested)
dkato 0:f782d9c66c49 76 :return:
dkato 0:f782d9c66c49 77 """
dkato 0:f782d9c66c49 78 config = Config(self.target)
dkato 0:f782d9c66c49 79
dkato 0:f782d9c66c49 80 mock_json_file_to_dict.assert_not_called()
dkato 0:f782d9c66c49 81 self.assertEqual(config.app_config_data, {},
dkato 0:f782d9c66c49 82 "app_config_data should be set an empty dictionary")
dkato 0:f782d9c66c49 83
dkato 0:f782d9c66c49 84 @patch.object(Config, '_process_config_and_overrides')
dkato 0:f782d9c66c49 85 @patch('os.path.isfile')
dkato 0:f782d9c66c49 86 @patch('tools.config.json_file_to_dict')
dkato 0:f782d9c66c49 87 def test_init_no_app_config_with_dir(self, mock_json_file_to_dict, mock_isfile, _):
dkato 0:f782d9c66c49 88 """
dkato 0:f782d9c66c49 89 Test that the initialisation works without app config and with a
dkato 0:f782d9c66c49 90 specified top level directory
dkato 0:f782d9c66c49 91
dkato 0:f782d9c66c49 92 :param mock_json_file_to_dict: mock of function json_file_to_dict
dkato 0:f782d9c66c49 93 :param _: patch of function _process_config_and_overrides (not tested)
dkato 0:f782d9c66c49 94 :return:
dkato 0:f782d9c66c49 95 """
dkato 0:f782d9c66c49 96 directory = '.'
dkato 0:f782d9c66c49 97 path = os.path.join('.', 'mbed_app.json')
dkato 0:f782d9c66c49 98 mock_return = {'config': 'test'}
dkato 0:f782d9c66c49 99 mock_json_file_to_dict.return_value = mock_return
dkato 0:f782d9c66c49 100 mock_isfile.return_value = True
dkato 0:f782d9c66c49 101
dkato 0:f782d9c66c49 102 config = Config(self.target, [directory])
dkato 0:f782d9c66c49 103
dkato 0:f782d9c66c49 104 mock_isfile.assert_called_with(path)
dkato 0:f782d9c66c49 105 mock_json_file_to_dict.assert_called_once_with(path)
dkato 0:f782d9c66c49 106 self.assertEqual(config.app_config_data, mock_return,
dkato 0:f782d9c66c49 107 "app_config_data should be set to the returned value")
dkato 0:f782d9c66c49 108
dkato 0:f782d9c66c49 109 @patch.object(Config, '_process_config_and_overrides')
dkato 0:f782d9c66c49 110 @patch('tools.config.json_file_to_dict')
dkato 0:f782d9c66c49 111 def test_init_override_app_config(self, mock_json_file_to_dict, _):
dkato 0:f782d9c66c49 112 """
dkato 0:f782d9c66c49 113 Test that the initialisation uses app_config instead of top_level_dir
dkato 0:f782d9c66c49 114 when both are specified
dkato 0:f782d9c66c49 115
dkato 0:f782d9c66c49 116 :param mock_json_file_to_dict: mock of function json_file_to_dict
dkato 0:f782d9c66c49 117 :param _: patch of function _process_config_and_overrides (not tested)
dkato 0:f782d9c66c49 118 :return:
dkato 0:f782d9c66c49 119 """
dkato 0:f782d9c66c49 120 app_config = "app_config"
dkato 0:f782d9c66c49 121 directory = '.'
dkato 0:f782d9c66c49 122 mock_return = {'config': 'test'}
dkato 0:f782d9c66c49 123 mock_json_file_to_dict.return_value = mock_return
dkato 0:f782d9c66c49 124
dkato 0:f782d9c66c49 125 config = Config(self.target, [directory], app_config=app_config)
dkato 0:f782d9c66c49 126
dkato 0:f782d9c66c49 127 mock_json_file_to_dict.assert_called_once_with(app_config)
dkato 0:f782d9c66c49 128 self.assertEqual(config.app_config_data, mock_return,
dkato 0:f782d9c66c49 129 "app_config_data should be set to the returned value")
dkato 0:f782d9c66c49 130
dkato 0:f782d9c66c49 131 if __name__ == '__main__':
dkato 0:f782d9c66c49 132 unittest.main()