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 | self.config.add_section(config_reader.RELEASED_RO_BUILDS) |
| 20 | |
| 21 | def testGetAndroidBoardList(self): |
| 22 | """Ensure android board list can be correctly fetched.""" |
Xixuan Wu | 26d06e0 | 2017-09-20 14:50:28 -0700 | [diff] [blame] | 23 | self.config.set(config_reader.ANDROID_SETTINGS, 'board_list', |
| 24 | '\nabox_edge,\nandroid-angler-1,\nangler-6') |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 25 | lab_config = config_reader.LabConfig(self.config) |
| 26 | self.assertEqual(lab_config.get_android_board_list(), |
| 27 | set(['abox_edge', 'android-angler', 'angler'])) |
| 28 | |
| 29 | def testGetInvalidAndroidBoardListEntry(self): |
| 30 | """Ensure ValueError is raised if no valid board list entry.""" |
Xixuan Wu | 26d06e0 | 2017-09-20 14:50:28 -0700 | [diff] [blame] | 31 | self.config.set(config_reader.ANDROID_SETTINGS, 'invalid_board_list', |
| 32 | '\nabox_edge,\nandroid-angler-1,\nangler-6') |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 33 | lab_config = config_reader.LabConfig(self.config) |
| 34 | self.assertRaises(ValueError, lab_config.get_android_board_list) |
| 35 | |
| 36 | def testGetEmptyAndroidBoardListEntry(self): |
| 37 | """Ensure ValueError is raised if no android board list is found.""" |
| 38 | lab_config = config_reader.LabConfig(self.config) |
| 39 | self.assertRaises(ValueError, lab_config.get_android_board_list) |
| 40 | |
Xixuan Wu | 6fb1627 | 2017-10-19 13:16:00 -0700 | [diff] [blame] | 41 | def testGetCrOSBoardList(self): |
| 42 | """Ensure android board list can be correctly fetched.""" |
| 43 | self.config.set(config_reader.CROS_SETTINGS, 'board_list', |
| 44 | '\nlink,\nandroid-angler-1,\nangler-6') |
| 45 | self.config.set(config_reader.ANDROID_SETTINGS, 'board_list', |
| 46 | '\nandroid-angler-1,\nangler-6') |
| 47 | lab_config = config_reader.LabConfig(self.config) |
| 48 | self.assertEqual(lab_config.get_cros_board_list(), |
| 49 | set(['link'])) |
| 50 | |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 51 | def testGetFirmwareROBuildList(self): |
| 52 | """Ensure firmware ro build can be successfully found.""" |
| 53 | self.config.set(config_reader.RELEASED_RO_BUILDS, 'link', 'firmware') |
| 54 | lab_config = config_reader.LabConfig(self.config) |
| 55 | self.assertEqual(lab_config.get_firmware_ro_build_list('link'), |
| 56 | 'firmware') |
| 57 | |
| 58 | def testGetEmptyFirmwareROBuildList(self): |
| 59 | """Ensure ValueError is raised if no firmware ro build is found.""" |
| 60 | lab_config = config_reader.LabConfig(self.config) |
| 61 | self.assertRaises(ValueError, |
| 62 | lab_config.get_firmware_ro_build_list, 'link') |
| 63 | |
C Shapiro | 7f24a00 | 2017-12-05 14:25:09 -0700 | [diff] [blame] | 64 | def testGetCrOSModelMap(self): |
| 65 | """Ensure cros_model_map can be correctly fetched.""" |
| 66 | self.config.set(config_reader.CROS_SETTINGS, 'model_list', |
| 67 | '\ncoral_astronaut,\ncoral_robo360') |
| 68 | lab_config = config_reader.LabConfig(self.config) |
| 69 | result = lab_config.get_cros_model_map() |
| 70 | self.assertEqual(len(result), 1) |
| 71 | self.assertEqual(result['coral'], ['astronaut', 'robo360']) |
| 72 | |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 73 | def testGetEmptyCrOSModelMap(self): |
| 74 | """Ensure cros_model_map can be correctly fetched.""" |
| 75 | lab_config = config_reader.LabConfig(self.config) |
| 76 | self.assertEqual(lab_config.get_cros_model_map(), {}) |
| 77 | |
| 78 | |
| 79 | class MigrationReaderTestCase(unittest.TestCase): |
| 80 | |
| 81 | def setUp(self): |
| 82 | self.config = config_reader.ConfigReader(None) |
| 83 | self.config.add_section(config_reader.SKYLAB_SETTINGS) |
| 84 | |
Xixuan Wu | bb74a37 | 2018-08-21 17:37:08 -0700 | [diff] [blame] | 85 | def testGetSkylabBoardList(self): |
| 86 | """Ensure skylab_board_list can be correctly fetched.""" |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 87 | self.config.set(config_reader.SKYLAB_SETTINGS, 'board_list', |
Xixuan Wu | bb74a37 | 2018-08-21 17:37:08 -0700 | [diff] [blame] | 88 | '\nnyan_blaze,\nreef') |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 89 | lab_config = config_reader.MigrationConfig(self.config) |
Xixuan Wu | bb74a37 | 2018-08-21 17:37:08 -0700 | [diff] [blame] | 90 | result = lab_config.get_skylab_board_list() |
| 91 | self.assertEqual(len(result), 2) |
| 92 | self.assertIn('nyan_blaze', result) |
| 93 | self.assertIn('reef', result) |
| 94 | |
Xixuan Wu | 446b8ad | 2018-08-23 11:25:43 -0700 | [diff] [blame] | 95 | def testGetSkylabSuiteList(self): |
| 96 | """Ensure skylab_suite_list can be correctly fetched.""" |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 97 | self.config.set(config_reader.SKYLAB_SETTINGS, 'suite_list', |
Xixuan Wu | 446b8ad | 2018-08-23 11:25:43 -0700 | [diff] [blame] | 98 | '\nent-nightly,\nent-perbuild') |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 99 | lab_config = config_reader.MigrationConfig(self.config) |
Xixuan Wu | 446b8ad | 2018-08-23 11:25:43 -0700 | [diff] [blame] | 100 | result = lab_config.get_skylab_suite_list() |
| 101 | self.assertEqual(len(result), 2) |
| 102 | self.assertIn('ent-nightly', result) |
| 103 | self.assertIn('ent-perbuild', result) |
| 104 | |
Xixuan Wu | 5ff0fac | 2019-01-07 10:06:35 -0800 | [diff] [blame] | 105 | def testGetSkylabModelMap(self): |
| 106 | """Ensure skylab_board_list can be correctly fetched.""" |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 107 | self.config.set(config_reader.SKYLAB_SETTINGS, 'model_list', |
Xixuan Wu | 5ff0fac | 2019-01-07 10:06:35 -0800 | [diff] [blame] | 108 | '\ncoral_lava,\ncoral_santa') |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 109 | lab_config = config_reader.MigrationConfig(self.config) |
Xixuan Wu | 5ff0fac | 2019-01-07 10:06:35 -0800 | [diff] [blame] | 110 | result = lab_config.get_skylab_model_map() |
| 111 | self.assertEqual(len(result), 1) |
| 112 | self.assertEqual(result['coral'], ['lava', 'santa']) |
| 113 | |
Xixuan Wu | abbaa4c | 2017-08-23 17:31:49 -0700 | [diff] [blame] | 114 | |
| 115 | if __name__ == '__main__': |
| 116 | unittest.main() |