Gentoo Archives: gentoo-commits

From: Mike Gilbert <floppym@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/_emerge/, lib/portage/tests/emerge/
Date: Sun, 25 Sep 2022 19:12:35
Message-Id: 1664133001.7fe37c7bbf6c42fb0b5ea5d8a431abf677df5822.floppym@gentoo
1 commit: 7fe37c7bbf6c42fb0b5ea5d8a431abf677df5822
2 Author: David Palao <david.palao <AT> gmail <DOT> com>
3 AuthorDate: Fri Sep 16 13:48:39 2022 +0000
4 Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
5 CommitDate: Sun Sep 25 19:10:01 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=7fe37c7b
7
8 test(actions): requiring that run_action calls binarytree.populate correctly
9
10 ...which means that since this is the first time, populate uses
11 getbinpkg_refresh=True explicitly.
12
13 This step is a preparation for a follow-up little change in the API of
14 binarytree.populate
15
16 Bug: https://bugs.gentoo.org/864259
17 Signed-off-by: David Palao <david.palao <AT> gmail.com>
18 Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
19
20 lib/_emerge/actions.py | 4 ++-
21 lib/portage/tests/emerge/test_actions.py | 45 ++++++++++++++++++++++++++++++++
22 2 files changed, 48 insertions(+), 1 deletion(-)
23
24 diff --git a/lib/_emerge/actions.py b/lib/_emerge/actions.py
25 index 26120ad6d..fbfc561ec 100644
26 --- a/lib/_emerge/actions.py
27 +++ b/lib/_emerge/actions.py
28 @@ -3510,7 +3510,9 @@ def run_action(emerge_config):
29
30 try:
31 mytrees["bintree"].populate(
32 - getbinpkgs="--getbinpkg" in emerge_config.opts, **kwargs
33 + getbinpkgs="--getbinpkg" in emerge_config.opts,
34 + getbinpkg_refresh=True,
35 + **kwargs
36 )
37 except ParseError as e:
38 writemsg(
39
40 diff --git a/lib/portage/tests/emerge/test_actions.py b/lib/portage/tests/emerge/test_actions.py
41 new file mode 100644
42 index 000000000..014d39dd9
43 --- /dev/null
44 +++ b/lib/portage/tests/emerge/test_actions.py
45 @@ -0,0 +1,45 @@
46 +# Copyright 2022 Gentoo Authors
47 +# Distributed under the terms of the GNU General Public License v2
48 +
49 +from unittest.mock import MagicMock, patch
50 +
51 +from _emerge.actions import run_action
52 +from portage.tests import TestCase
53 +
54 +
55 +class RunActionTestCase(TestCase):
56 + """This class' purpose is to encompass UTs for ``actions.run_action``.
57 + Since that function is extremely long (at least on Sep. 2022;
58 + hopefully the situation gets better with the time), the tests in this
59 + ``TestCase`` contain plenty of mocks/patches.
60 + Hopefully, with time and effort, the ``run_action`` function (and others
61 + in the module) are refactored to make testing easier and more robust.
62 +
63 + A side effect of the mocking approach is a strong dependency on the
64 + details of the implementation. That can be improved if functions
65 + are smaller and do a well defined small set of tasks. Another call to
66 + refactoring...
67 + If the implementation changes, the mocks can be adjusted to play its
68 + role.
69 + """
70 + @patch("_emerge.actions.profile_check")
71 + @patch("_emerge.actions.adjust_configs")
72 + @patch("_emerge.actions.apply_priorities")
73 + def test_binary_trees_populate_called(
74 + self,
75 + papply,
76 + padjust,
77 + profile_ckeck):
78 + config = MagicMock()
79 + config.action = None
80 + config.opts = {"--quiet": True, "--usepkg": True}
81 + bt = MagicMock()
82 + tree = {"bintree": bt}
83 + trees = {"first": tree}
84 + config.trees = trees
85 +
86 + run_action(config)
87 +
88 + bt.populate.assert_called_once_with(
89 + getbinpkgs=False, getbinpkg_refresh=True
90 + )