blob: ec320fe01805b00c5eda826dbe99e0604880a8e0 [file] [log] [blame]
Alex Kleineb77ffa2019-05-28 14:47:44 -06001# -*- 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
8from __future__ import print_function
9
Alex Kleineb77ffa2019-05-28 14:47:44 -060010from chromite.lib import build_target_util
Alex Kleineb77ffa2019-05-28 14:47:44 -060011from chromite.lib import cros_test_lib
Alex Klein87531182019-08-12 15:23:37 -060012from chromite.lib import portage_util
13from chromite.lib.chroot_lib import Chroot
Alex Kleineb77ffa2019-05-28 14:47:44 -060014from chromite.service import packages
15
16
Alex Kleineb77ffa2019-05-28 14:47:44 -060017class 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 Klein87531182019-08-12 15:23:37 -060033class 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 Burger1e0fe232019-07-01 14:52:07 -060057class 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('')