commit:     7fe37c7bbf6c42fb0b5ea5d8a431abf677df5822
Author:     David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri Sep 16 13:48:39 2022 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Sun Sep 25 19:10:01 2022 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=7fe37c7b

test(actions): requiring that run_action calls binarytree.populate correctly

...which means that since this is the first time, populate uses
getbinpkg_refresh=True explicitly.

This step is a preparation for a follow-up little change in the API of
binarytree.populate

Bug: https://bugs.gentoo.org/864259
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>

 lib/_emerge/actions.py                   |  4 ++-
 lib/portage/tests/emerge/test_actions.py | 45 ++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/lib/_emerge/actions.py b/lib/_emerge/actions.py
index 26120ad6d..fbfc561ec 100644
--- a/lib/_emerge/actions.py
+++ b/lib/_emerge/actions.py
@@ -3510,7 +3510,9 @@ def run_action(emerge_config):
 
             try:
                 mytrees["bintree"].populate(
-                    getbinpkgs="--getbinpkg" in emerge_config.opts, **kwargs
+                    getbinpkgs="--getbinpkg" in emerge_config.opts,
+                    getbinpkg_refresh=True,
+                    **kwargs
                 )
             except ParseError as e:
                 writemsg(

diff --git a/lib/portage/tests/emerge/test_actions.py 
b/lib/portage/tests/emerge/test_actions.py
new file mode 100644
index 000000000..014d39dd9
--- /dev/null
+++ b/lib/portage/tests/emerge/test_actions.py
@@ -0,0 +1,45 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+from unittest.mock import MagicMock, patch
+
+from _emerge.actions import run_action
+from portage.tests import TestCase
+
+
+class RunActionTestCase(TestCase):
+    """This class' purpose is to encompass UTs for ``actions.run_action``.
+    Since that function is extremely long (at least on Sep. 2022;
+    hopefully the situation gets better with the time), the tests in this
+    ``TestCase`` contain plenty of mocks/patches.
+    Hopefully, with time and effort, the ``run_action`` function (and others
+    in the module) are refactored to make testing easier and more robust.
+
+    A side effect of the mocking approach is a strong dependency on the
+    details of the implementation. That can be improved if functions
+    are smaller and do a well defined small set of tasks. Another call to
+    refactoring...
+    If the implementation changes, the mocks can be adjusted to play its
+    role.
+    """
+    @patch("_emerge.actions.profile_check")
+    @patch("_emerge.actions.adjust_configs")
+    @patch("_emerge.actions.apply_priorities")
+    def test_binary_trees_populate_called(
+            self,
+            papply,
+            padjust,
+            profile_ckeck):
+        config = MagicMock()
+        config.action = None
+        config.opts = {"--quiet": True, "--usepkg": True}
+        bt = MagicMock()
+        tree = {"bintree": bt}
+        trees = {"first": tree}
+        config.trees = trees
+
+        run_action(config)
+
+        bt.populate.assert_called_once_with(
+            getbinpkgs=False, getbinpkg_refresh=True
+        )

Reply via email to