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 | |
| 11 | _CROS_VERSION_SAMPLES = ['cave-release/R57-9030.0.0'] |
| 12 | _ANDROID_VERSION_SAMPLES = ['git_mnc-release/shamu-userdebug/2457013'] |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 13 | |
Allen Li | 606673f | 2017-02-21 18:41:13 -0800 | [diff] [blame] | 14 | |
| 15 | class ActionTestCase(unittest.TestCase): |
| 16 | """Tests for Action functions.""" |
Richard Barnette | 17fa7c4 | 2018-04-26 00:33:11 +0000 | [diff] [blame] | 17 | #pylint:disable=missing-docstring |
Allen Li | 606673f | 2017-02-21 18:41:13 -0800 | [diff] [blame] | 18 | |
| 19 | def test__get_label_action_with_keyval_label(self): |
| 20 | got = provision._get_label_action('cros-version:foo') |
| 21 | self.assertEqual(got, provision._Action('cros-version', 'foo')) |
| 22 | |
| 23 | def test__get_label_action_with_plain_label(self): |
| 24 | got = provision._get_label_action('webcam') |
| 25 | self.assertEqual(got, provision._Action('webcam', None)) |
| 26 | |
| 27 | def test__get_label_action_with_empty_string(self): |
| 28 | got = provision._get_label_action('') |
| 29 | self.assertEqual(got, provision._Action('', None)) |
| 30 | |
| 31 | |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 32 | class ImageParsingTests(unittest.TestCase): |
| 33 | """Unit tests for `provision.get_version_label_prefix()`.""" |
| 34 | |
| 35 | def _do_test_prefixes(self, expected, version_samples): |
| 36 | for v in version_samples: |
| 37 | prefix = provision.get_version_label_prefix(v) |
| 38 | self.assertEqual(prefix, expected) |
| 39 | |
| 40 | def test_cros_prefix(self): |
| 41 | """Test handling of Chrome OS version strings.""" |
| 42 | self._do_test_prefixes(provision.CROS_VERSION_PREFIX, |
| 43 | _CROS_VERSION_SAMPLES) |
| 44 | |
| 45 | def test_android_prefix(self): |
| 46 | """Test handling of Android version strings.""" |
| 47 | self._do_test_prefixes(provision.ANDROID_BUILD_VERSION_PREFIX, |
| 48 | _ANDROID_VERSION_SAMPLES) |
| 49 | |
Richard Barnette | 6c2b70a | 2017-01-26 13:40:51 -0800 | [diff] [blame] | 50 | |
| 51 | if __name__ == '__main__': |
| 52 | unittest.main() |