Allen Li | 606673f | 2017-02-21 18:41:13 -0800 | [diff] [blame] | 1 | #!/usr/bin/python2.7 |
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 | ] |
| 21 | _ANDROID_VERSION_SAMPLES = [ |
| 22 | 'git_mnc-release/shamu-userdebug/2457013' |
| 23 | ] |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 24 | |
Allen Li | 606673f | 2017-02-21 18:41:13 -0800 | [diff] [blame] | 25 | |
| 26 | class ActionTestCase(unittest.TestCase): |
| 27 | """Tests for Action functions.""" |
Richard Barnette | 17fa7c4 | 2018-04-26 00:33:11 +0000 | [diff] [blame] | 28 | #pylint:disable=missing-docstring |
Allen Li | 606673f | 2017-02-21 18:41:13 -0800 | [diff] [blame] | 29 | |
| 30 | def test__get_label_action_with_keyval_label(self): |
| 31 | got = provision._get_label_action('cros-version:foo') |
| 32 | self.assertEqual(got, provision._Action('cros-version', 'foo')) |
| 33 | |
| 34 | def test__get_label_action_with_plain_label(self): |
| 35 | got = provision._get_label_action('webcam') |
| 36 | self.assertEqual(got, provision._Action('webcam', None)) |
| 37 | |
| 38 | def test__get_label_action_with_empty_string(self): |
| 39 | got = provision._get_label_action('') |
| 40 | self.assertEqual(got, provision._Action('', None)) |
| 41 | |
| 42 | |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 43 | class ImageParsingTests(unittest.TestCase): |
| 44 | """Unit tests for `provision.get_version_label_prefix()`.""" |
| 45 | |
| 46 | def _do_test_prefixes(self, expected, version_samples): |
| 47 | for v in version_samples: |
| 48 | prefix = provision.get_version_label_prefix(v) |
| 49 | self.assertEqual(prefix, expected) |
| 50 | |
| 51 | def test_cros_prefix(self): |
| 52 | """Test handling of Chrome OS version strings.""" |
| 53 | self._do_test_prefixes(provision.CROS_VERSION_PREFIX, |
| 54 | _CROS_VERSION_SAMPLES) |
| 55 | |
Richard Barnette | 7203e18 | 2018-07-10 11:22:20 -0700 | [diff] [blame^] | 56 | def test_cros_android_prefix(self): |
| 57 | """Test handling of Chrome OS version strings.""" |
| 58 | self._do_test_prefixes(provision.CROS_ANDROID_VERSION_PREFIX, |
| 59 | _CROS_ANDROID_VERSION_SAMPLES) |
| 60 | |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 61 | def test_android_prefix(self): |
| 62 | """Test handling of Android version strings.""" |
| 63 | self._do_test_prefixes(provision.ANDROID_BUILD_VERSION_PREFIX, |
| 64 | _ANDROID_VERSION_SAMPLES) |
| 65 | |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 66 | |
| 67 | if __name__ == '__main__': |
| 68 | unittest.main() |