the other jimmy / mbed-sdk-tools

Fork of mbed-sdk-tools by mbed official

Committer:
The Other Jimmy
Date:
Wed Jan 04 11:58:24 2017 -0600
Revision:
31:182518299918
Update tools to follow mbed-os tools release 5.3.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
The Other Jimmy 31:182518299918 1 """
The Other Jimmy 31:182518299918 2 mbed SDK
The Other Jimmy 31:182518299918 3 Copyright (c) 2016 ARM Limited
The Other Jimmy 31:182518299918 4
The Other Jimmy 31:182518299918 5 Licensed under the Apache License, Version 2.0 (the "License");
The Other Jimmy 31:182518299918 6 you may not use this file except in compliance with the License.
The Other Jimmy 31:182518299918 7 You may obtain a copy of the License at
The Other Jimmy 31:182518299918 8
The Other Jimmy 31:182518299918 9 http://www.apache.org/licenses/LICENSE-2.0
The Other Jimmy 31:182518299918 10
The Other Jimmy 31:182518299918 11 Unless required by applicable law or agreed to in writing, software
The Other Jimmy 31:182518299918 12 distributed under the License is distributed on an "AS IS" BASIS,
The Other Jimmy 31:182518299918 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
The Other Jimmy 31:182518299918 14 See the License for the specific language governing permissions and
The Other Jimmy 31:182518299918 15 limitations under the License.
The Other Jimmy 31:182518299918 16 """
The Other Jimmy 31:182518299918 17
The Other Jimmy 31:182518299918 18 import os.path
The Other Jimmy 31:182518299918 19 import unittest
The Other Jimmy 31:182518299918 20 from mock import patch
The Other Jimmy 31:182518299918 21 from tools.config import Config
The Other Jimmy 31:182518299918 22
The Other Jimmy 31:182518299918 23 """
The Other Jimmy 31:182518299918 24 Tests for config.py
The Other Jimmy 31:182518299918 25 """
The Other Jimmy 31:182518299918 26
The Other Jimmy 31:182518299918 27 class ConfigTests(unittest.TestCase):
The Other Jimmy 31:182518299918 28 """
The Other Jimmy 31:182518299918 29 Test cases for Config class
The Other Jimmy 31:182518299918 30 """
The Other Jimmy 31:182518299918 31
The Other Jimmy 31:182518299918 32 def setUp(self):
The Other Jimmy 31:182518299918 33 """
The Other Jimmy 31:182518299918 34 Called before each test case
The Other Jimmy 31:182518299918 35
The Other Jimmy 31:182518299918 36 :return:
The Other Jimmy 31:182518299918 37 """
The Other Jimmy 31:182518299918 38 self.target = "K64F"
The Other Jimmy 31:182518299918 39
The Other Jimmy 31:182518299918 40 def tearDown(self):
The Other Jimmy 31:182518299918 41 """
The Other Jimmy 31:182518299918 42 Called after each test case
The Other Jimmy 31:182518299918 43
The Other Jimmy 31:182518299918 44 :return:
The Other Jimmy 31:182518299918 45 """
The Other Jimmy 31:182518299918 46 pass
The Other Jimmy 31:182518299918 47
The Other Jimmy 31:182518299918 48 @patch.object(Config, '_process_config_and_overrides')
The Other Jimmy 31:182518299918 49 @patch('tools.config.json_file_to_dict')
The Other Jimmy 31:182518299918 50 def test_init_app_config(self, mock_json_file_to_dict, _):
The Other Jimmy 31:182518299918 51 """
The Other Jimmy 31:182518299918 52 Test that the initialisation correctly uses app_config
The Other Jimmy 31:182518299918 53
The Other Jimmy 31:182518299918 54 :param mock_json_file_to_dict: mock of function json_file_to_dict
The Other Jimmy 31:182518299918 55 :param _: mock of function _process_config_and_overrides (not tested)
The Other Jimmy 31:182518299918 56 :return:
The Other Jimmy 31:182518299918 57 """
The Other Jimmy 31:182518299918 58 app_config = "app_config"
The Other Jimmy 31:182518299918 59 mock_return = {'config': 'test'}
The Other Jimmy 31:182518299918 60 mock_json_file_to_dict.return_value = mock_return
The Other Jimmy 31:182518299918 61
The Other Jimmy 31:182518299918 62 config = Config(self.target, app_config=app_config)
The Other Jimmy 31:182518299918 63
The Other Jimmy 31:182518299918 64 mock_json_file_to_dict.assert_called_with(app_config)
The Other Jimmy 31:182518299918 65 self.assertEqual(config.app_config_data, mock_return,
The Other Jimmy 31:182518299918 66 "app_config_data should be set to the returned value")
The Other Jimmy 31:182518299918 67
The Other Jimmy 31:182518299918 68 @patch.object(Config, '_process_config_and_overrides')
The Other Jimmy 31:182518299918 69 @patch('tools.config.json_file_to_dict')
The Other Jimmy 31:182518299918 70 def test_init_no_app_config(self, mock_json_file_to_dict, _):
The Other Jimmy 31:182518299918 71 """
The Other Jimmy 31:182518299918 72 Test that the initialisation works without app config
The Other Jimmy 31:182518299918 73
The Other Jimmy 31:182518299918 74 :param mock_json_file_to_dict: mock of function json_file_to_dict
The Other Jimmy 31:182518299918 75 :param _: patch of function _process_config_and_overrides (not tested)
The Other Jimmy 31:182518299918 76 :return:
The Other Jimmy 31:182518299918 77 """
The Other Jimmy 31:182518299918 78 config = Config(self.target)
The Other Jimmy 31:182518299918 79
The Other Jimmy 31:182518299918 80 mock_json_file_to_dict.assert_not_called()
The Other Jimmy 31:182518299918 81 self.assertEqual(config.app_config_data, {},
The Other Jimmy 31:182518299918 82 "app_config_data should be set an empty dictionary")
The Other Jimmy 31:182518299918 83
The Other Jimmy 31:182518299918 84 @patch.object(Config, '_process_config_and_overrides')
The Other Jimmy 31:182518299918 85 @patch('os.path.isfile')
The Other Jimmy 31:182518299918 86 @patch('tools.config.json_file_to_dict')
The Other Jimmy 31:182518299918 87 def test_init_no_app_config_with_dir(self, mock_json_file_to_dict, mock_isfile, _):
The Other Jimmy 31:182518299918 88 """
The Other Jimmy 31:182518299918 89 Test that the initialisation works without app config and with a
The Other Jimmy 31:182518299918 90 specified top level directory
The Other Jimmy 31:182518299918 91
The Other Jimmy 31:182518299918 92 :param mock_json_file_to_dict: mock of function json_file_to_dict
The Other Jimmy 31:182518299918 93 :param _: patch of function _process_config_and_overrides (not tested)
The Other Jimmy 31:182518299918 94 :return:
The Other Jimmy 31:182518299918 95 """
The Other Jimmy 31:182518299918 96 directory = '.'
The Other Jimmy 31:182518299918 97 path = os.path.join('.', 'mbed_app.json')
The Other Jimmy 31:182518299918 98 mock_return = {'config': 'test'}
The Other Jimmy 31:182518299918 99 mock_json_file_to_dict.return_value = mock_return
The Other Jimmy 31:182518299918 100 mock_isfile.return_value = True
The Other Jimmy 31:182518299918 101
The Other Jimmy 31:182518299918 102 config = Config(self.target, [directory])
The Other Jimmy 31:182518299918 103
The Other Jimmy 31:182518299918 104 mock_isfile.assert_called_with(path)
The Other Jimmy 31:182518299918 105 mock_json_file_to_dict.assert_called_once_with(path)
The Other Jimmy 31:182518299918 106 self.assertEqual(config.app_config_data, mock_return,
The Other Jimmy 31:182518299918 107 "app_config_data should be set to the returned value")
The Other Jimmy 31:182518299918 108
The Other Jimmy 31:182518299918 109 @patch.object(Config, '_process_config_and_overrides')
The Other Jimmy 31:182518299918 110 @patch('tools.config.json_file_to_dict')
The Other Jimmy 31:182518299918 111 def test_init_override_app_config(self, mock_json_file_to_dict, _):
The Other Jimmy 31:182518299918 112 """
The Other Jimmy 31:182518299918 113 Test that the initialisation uses app_config instead of top_level_dir
The Other Jimmy 31:182518299918 114 when both are specified
The Other Jimmy 31:182518299918 115
The Other Jimmy 31:182518299918 116 :param mock_json_file_to_dict: mock of function json_file_to_dict
The Other Jimmy 31:182518299918 117 :param _: patch of function _process_config_and_overrides (not tested)
The Other Jimmy 31:182518299918 118 :return:
The Other Jimmy 31:182518299918 119 """
The Other Jimmy 31:182518299918 120 app_config = "app_config"
The Other Jimmy 31:182518299918 121 directory = '.'
The Other Jimmy 31:182518299918 122 mock_return = {'config': 'test'}
The Other Jimmy 31:182518299918 123 mock_json_file_to_dict.return_value = mock_return
The Other Jimmy 31:182518299918 124
The Other Jimmy 31:182518299918 125 config = Config(self.target, [directory], app_config=app_config)
The Other Jimmy 31:182518299918 126
The Other Jimmy 31:182518299918 127 mock_json_file_to_dict.assert_called_once_with(app_config)
The Other Jimmy 31:182518299918 128 self.assertEqual(config.app_config_data, mock_return,
The Other Jimmy 31:182518299918 129 "app_config_data should be set to the returned value")
The Other Jimmy 31:182518299918 130
The Other Jimmy 31:182518299918 131 if __name__ == '__main__':
The Other Jimmy 31:182518299918 132 unittest.main()