Xixuan Wu | 51bb710 | 2019-03-18 14:51:44 -0700 | [diff] [blame] | 1 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Xixuan Wu | 51bb710 | 2019-03-18 14:51:44 -0700 | [diff] [blame] | 5 | """Module for task config reader unittests.""" |
Xixuan Wu | 5ff0fac | 2019-01-07 10:06:35 -0800 | [diff] [blame] | 6 | # pylint: disable=g-missing-super-call |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 7 | |
| 8 | import unittest |
| 9 | |
| 10 | import config_reader |
Xixuan Wu | 244e0ec | 2018-05-23 14:49:55 -0700 | [diff] [blame] | 11 | |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 12 | |
| 13 | class LabReaderTestCase(unittest.TestCase): |
| 14 | |
| 15 | def setUp(self): |
| 16 | self.config = config_reader.ConfigReader(None) |
Xixuan Wu | 26d06e0 | 2017-09-20 14:50:28 -0700 | [diff] [blame] | 17 | self.config.add_section(config_reader.ANDROID_SETTINGS) |
Xixuan Wu | 6fb1627 | 2017-10-19 13:16:00 -0700 | [diff] [blame] | 18 | self.config.add_section(config_reader.CROS_SETTINGS) |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 19 | |
| 20 | def testGetAndroidBoardList(self): |
| 21 | """Ensure android board list can be correctly fetched.""" |
Xixuan Wu | 26d06e0 | 2017-09-20 14:50:28 -0700 | [diff] [blame] | 22 | self.config.set(config_reader.ANDROID_SETTINGS, 'board_list', |
| 23 | '\nabox_edge,\nandroid-angler-1,\nangler-6') |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 24 | lab_config = config_reader.LabConfig(self.config) |
| 25 | self.assertEqual(lab_config.get_android_board_list(), |
| 26 | set(['abox_edge', 'android-angler', 'angler'])) |
| 27 | |
| 28 | def testGetInvalidAndroidBoardListEntry(self): |
| 29 | """Ensure ValueError is raised if no valid board list entry.""" |
Xixuan Wu | 26d06e0 | 2017-09-20 14:50:28 -0700 | [diff] [blame] | 30 | self.config.set(config_reader.ANDROID_SETTINGS, 'invalid_board_list', |
| 31 | '\nabox_edge,\nandroid-angler-1,\nangler-6') |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 32 | lab_config = config_reader.LabConfig(self.config) |
| 33 | self.assertRaises(ValueError, lab_config.get_android_board_list) |
| 34 | |
| 35 | def testGetEmptyAndroidBoardListEntry(self): |
| 36 | """Ensure ValueError is raised if no android board list is found.""" |
| 37 | lab_config = config_reader.LabConfig(self.config) |
| 38 | self.assertRaises(ValueError, lab_config.get_android_board_list) |
| 39 | |
Xixuan Wu | 6fb1627 | 2017-10-19 13:16:00 -0700 | [diff] [blame] | 40 | def testGetCrOSBoardList(self): |
| 41 | """Ensure android board list can be correctly fetched.""" |
| 42 | self.config.set(config_reader.CROS_SETTINGS, 'board_list', |
| 43 | '\nlink,\nandroid-angler-1,\nangler-6') |
| 44 | self.config.set(config_reader.ANDROID_SETTINGS, 'board_list', |
| 45 | '\nandroid-angler-1,\nangler-6') |
| 46 | lab_config = config_reader.LabConfig(self.config) |
| 47 | self.assertEqual(lab_config.get_cros_board_list(), |
| 48 | set(['link'])) |
| 49 | |
C Shapiro | 7f24a00 | 2017-12-05 14:25:09 -0700 | [diff] [blame] | 50 | def testGetCrOSModelMap(self): |
| 51 | """Ensure cros_model_map can be correctly fetched.""" |
| 52 | self.config.set(config_reader.CROS_SETTINGS, 'model_list', |
| 53 | '\ncoral_astronaut,\ncoral_robo360') |
| 54 | lab_config = config_reader.LabConfig(self.config) |
| 55 | result = lab_config.get_cros_model_map() |
| 56 | self.assertEqual(len(result), 1) |
| 57 | self.assertEqual(result['coral'], ['astronaut', 'robo360']) |
| 58 | |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 59 | def testGetEmptyCrOSModelMap(self): |
| 60 | """Ensure cros_model_map can be correctly fetched.""" |
| 61 | lab_config = config_reader.LabConfig(self.config) |
| 62 | self.assertEqual(lab_config.get_cros_model_map(), {}) |
| 63 | |
| 64 | |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 65 | if __name__ == '__main__': |
| 66 | unittest.main() |