Derek Beckett | 25616cc | 2021-08-24 13:04:02 -0700 | [diff] [blame] | 1 | #!/usr/bin/python3 |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 2 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | import unittest |
| 7 | |
| 8 | import common |
| 9 | from autotest_lib.server.cros import provision |
| 10 | |
Richard Barnette | 7203e18 | 2018-07-10 11:22:20 -0700 | [diff] [blame] | 11 | _CROS_VERSION_SAMPLES = [ |
| 12 | 'cave-release/R57-9030.0.0', |
| 13 | 'grunt-llvm-next-toolchain-tryjob/R69-10851.0.0-b2726174' |
| 14 | 'eve-tot-chrome-pfq-informational/R69-10822.0.0-b2700960', |
| 15 | ] |
| 16 | _CROS_ANDROID_VERSION_SAMPLES = [ |
| 17 | 'git_nyc-mr1-arc/cheets_arm-user/4866647', |
| 18 | 'git_nyc-mr1-arc/cheets_arm-user/P6244267', |
| 19 | 'git_nyc-mr1-arc/cheets_x86-user/P6256537', |
| 20 | ] |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 21 | |
Allen Li | 606673f | 2017-02-21 18:41:13 -0800 | [diff] [blame] | 22 | |
| 23 | class ActionTestCase(unittest.TestCase): |
| 24 | """Tests for Action functions.""" |
Richard Barnette | 17fa7c4 | 2018-04-26 00:33:11 +0000 | [diff] [blame] | 25 | #pylint:disable=missing-docstring |
Allen Li | 606673f | 2017-02-21 18:41:13 -0800 | [diff] [blame] | 26 | |
| 27 | def test__get_label_action_with_keyval_label(self): |
| 28 | got = provision._get_label_action('cros-version:foo') |
| 29 | self.assertEqual(got, provision._Action('cros-version', 'foo')) |
| 30 | |
| 31 | def test__get_label_action_with_plain_label(self): |
| 32 | got = provision._get_label_action('webcam') |
| 33 | self.assertEqual(got, provision._Action('webcam', None)) |
| 34 | |
| 35 | def test__get_label_action_with_empty_string(self): |
| 36 | got = provision._get_label_action('') |
| 37 | self.assertEqual(got, provision._Action('', None)) |
| 38 | |
| 39 | |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 40 | class ImageParsingTests(unittest.TestCase): |
| 41 | """Unit tests for `provision.get_version_label_prefix()`.""" |
| 42 | |
| 43 | def _do_test_prefixes(self, expected, version_samples): |
| 44 | for v in version_samples: |
| 45 | prefix = provision.get_version_label_prefix(v) |
| 46 | self.assertEqual(prefix, expected) |
| 47 | |
| 48 | def test_cros_prefix(self): |
| 49 | """Test handling of Chrome OS version strings.""" |
| 50 | self._do_test_prefixes(provision.CROS_VERSION_PREFIX, |
| 51 | _CROS_VERSION_SAMPLES) |
| 52 | |
Richard Barnette | 7203e18 | 2018-07-10 11:22:20 -0700 | [diff] [blame] | 53 | def test_cros_android_prefix(self): |
| 54 | """Test handling of Chrome OS version strings.""" |
| 55 | self._do_test_prefixes(provision.CROS_ANDROID_VERSION_PREFIX, |
| 56 | _CROS_ANDROID_VERSION_SAMPLES) |
| 57 | |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 58 | |
| 59 | if __name__ == '__main__': |
| 60 | unittest.main() |