Home | History | Annotate | Download | only in cros
      1 #!/usr/bin/python2.7
      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 = [
     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 
     22 
     23 class ActionTestCase(unittest.TestCase):
     24     """Tests for Action functions."""
     25     #pylint:disable=missing-docstring
     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 
     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 
     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 
     58 
     59 if __name__ == '__main__':
     60     unittest.main()
     61