| # -*- coding: utf-8 -*- |
| # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Packages service tests.""" |
| |
| from __future__ import print_function |
| |
| from chromite.lib import build_target_util |
| from chromite.lib import cros_test_lib |
| from chromite.lib import portage_util |
| from chromite.lib.chroot_lib import Chroot |
| from chromite.service import packages |
| |
| |
| class UprevBuildTargetsTest(cros_test_lib.RunCommandTestCase): |
| """uprev_build_targets tests.""" |
| |
| def test_invalid_type_fails(self): |
| """Test invalid type fails.""" |
| with self.assertRaises(AssertionError): |
| packages.uprev_build_targets([build_target_util.BuildTarget('foo')], |
| 'invalid') |
| |
| def test_none_type_fails(self): |
| """Test None type fails.""" |
| with self.assertRaises(AssertionError): |
| packages.uprev_build_targets([build_target_util.BuildTarget('foo')], |
| None) |
| |
| |
| class UprevsVersionedPackageTest(cros_test_lib.MockTestCase): |
| """uprevs_versioned_package decorator test.""" |
| |
| @packages.uprevs_versioned_package('category/package') |
| def uprev_category_package(self, *args, **kwargs): |
| """Registered function for testing.""" |
| |
| def test_calls_function(self): |
| """Test calling a registered function.""" |
| patch = self.PatchObject(self, 'uprev_category_package') |
| |
| cpv = portage_util.SplitCPV('category/package', strict=False) |
| packages.uprev_versioned_package(cpv, [], [], Chroot()) |
| |
| patch.assert_called() |
| |
| def test_unregistered_package(self): |
| """Test calling with an unregistered package.""" |
| cpv = portage_util.SplitCPV('does-not/exist', strict=False) |
| |
| with self.assertRaises(packages.UnknownPackageError): |
| packages.uprev_versioned_package(cpv, [], [], Chroot()) |
| |
| |
| class GetBestVisibleTest(cros_test_lib.MockTestCase): |
| """get_best_visible tests.""" |
| |
| def test_empty_atom_fails(self): |
| with self.assertRaises(AssertionError): |
| packages.get_best_visible('') |