Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2019 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 | """Packages service tests.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 10 | from chromite.lib import build_target_util |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 11 | from chromite.lib import cros_test_lib |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame^] | 12 | from chromite.lib import portage_util |
| 13 | from chromite.lib.chroot_lib import Chroot |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 14 | from chromite.service import packages |
| 15 | |
| 16 | |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 17 | class UprevBuildTargetsTest(cros_test_lib.RunCommandTestCase): |
| 18 | """uprev_build_targets tests.""" |
| 19 | |
| 20 | def test_invalid_type_fails(self): |
| 21 | """Test invalid type fails.""" |
| 22 | with self.assertRaises(AssertionError): |
| 23 | packages.uprev_build_targets([build_target_util.BuildTarget('foo')], |
| 24 | 'invalid') |
| 25 | |
| 26 | def test_none_type_fails(self): |
| 27 | """Test None type fails.""" |
| 28 | with self.assertRaises(AssertionError): |
| 29 | packages.uprev_build_targets([build_target_util.BuildTarget('foo')], |
| 30 | None) |
| 31 | |
| 32 | |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame^] | 33 | class UprevsVersionedPackageTest(cros_test_lib.MockTestCase): |
| 34 | """uprevs_versioned_package decorator test.""" |
| 35 | |
| 36 | @packages.uprevs_versioned_package('category/package') |
| 37 | def uprev_category_package(self, *args, **kwargs): |
| 38 | """Registered function for testing.""" |
| 39 | |
| 40 | def test_calls_function(self): |
| 41 | """Test calling a registered function.""" |
| 42 | patch = self.PatchObject(self, 'uprev_category_package') |
| 43 | |
| 44 | cpv = portage_util.SplitCPV('category/package', strict=False) |
| 45 | packages.uprev_versioned_package(cpv, [], [], Chroot()) |
| 46 | |
| 47 | patch.assert_called() |
| 48 | |
| 49 | def test_unregistered_package(self): |
| 50 | """Test calling with an unregistered package.""" |
| 51 | cpv = portage_util.SplitCPV('does-not/exist', strict=False) |
| 52 | |
| 53 | with self.assertRaises(packages.UnknownPackageError): |
| 54 | packages.uprev_versioned_package(cpv, [], [], Chroot()) |
| 55 | |
| 56 | |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 57 | class GetBestVisibleTest(cros_test_lib.MockTestCase): |
| 58 | """get_best_visible tests.""" |
| 59 | |
| 60 | def test_empty_atom_fails(self): |
| 61 | with self.assertRaises(AssertionError): |
| 62 | packages.get_best_visible('') |