Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

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