1 |
commit: 419f5ae0d9f0ca55279f1ad60a7dc83d8da777d6 |
2 |
Author: David Palao <david.palao <AT> gmail <DOT> com> |
3 |
AuthorDate: Fri Sep 9 17:12:17 2022 +0000 |
4 |
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Sep 25 19:07:52 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=419f5ae0 |
7 |
|
8 |
test(bintree): added UTs for binarytree.populate |
9 |
|
10 |
Signed-off-by: David Palao <david.palao <AT> gmail.com> |
11 |
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org> |
12 |
|
13 |
lib/portage/tests/dbapi/test_bintree.py | 68 ++++++++++++++++++++++++++++++++- |
14 |
1 file changed, 66 insertions(+), 2 deletions(-) |
15 |
|
16 |
diff --git a/lib/portage/tests/dbapi/test_bintree.py b/lib/portage/tests/dbapi/test_bintree.py |
17 |
index 14b89dfc0..d0bfa306e 100644 |
18 |
--- a/lib/portage/tests/dbapi/test_bintree.py |
19 |
+++ b/lib/portage/tests/dbapi/test_bintree.py |
20 |
@@ -1,11 +1,14 @@ |
21 |
-# Copyright 2020-2022 Gentoo Authors |
22 |
+# Copyright 2022 Gentoo Authors |
23 |
# Distributed under the terms of the GNU General Public License v2 |
24 |
|
25 |
-from unittest.mock import MagicMock |
26 |
+from unittest.mock import MagicMock, patch, call |
27 |
+import os |
28 |
|
29 |
from portage.tests import TestCase |
30 |
|
31 |
from portage.dbapi.bintree import binarytree |
32 |
+from portage.localization import _ |
33 |
+from portage.const import BINREPOS_CONF_FILE |
34 |
|
35 |
|
36 |
class BinarytreeTestCase(TestCase): |
37 |
@@ -52,3 +55,64 @@ class BinarytreeTestCase(TestCase): |
38 |
# The next attribute is the difference between multi instance |
39 |
# and no multi instance: |
40 |
getattr(multi_instance_bt, "_allocate_filename") |
41 |
+ |
42 |
+ @patch("portage.dbapi.bintree.binarytree._populate_local") |
43 |
+ def test_populate_without_updates_repos_nor_getbinspkgs( |
44 |
+ self, ppopulate_local): |
45 |
+ bt = binarytree(pkgdir="/tmp", settings=MagicMock()) |
46 |
+ ppopulate_local.return_value = {} |
47 |
+ bt.populate() |
48 |
+ ppopulate_local.assert_called_once_with(reindex=True) |
49 |
+ self.assertFalse(bt._populating) |
50 |
+ self.assertTrue(bt.populated) |
51 |
+ |
52 |
+ @patch("portage.dbapi.bintree.binarytree._populate_local") |
53 |
+ def test_populate_calls_twice_populate_local_if_updates( |
54 |
+ self, ppopulate_local): |
55 |
+ bt = binarytree(pkgdir="/tmp", settings=MagicMock()) |
56 |
+ bt.populate() |
57 |
+ self.assertIn(call(reindex=True), ppopulate_local.mock_calls) |
58 |
+ self.assertIn(call(), ppopulate_local.mock_calls) |
59 |
+ self.assertEqual(ppopulate_local.call_count, 2) |
60 |
+ |
61 |
+ @patch("portage.dbapi.bintree.binarytree._populate_additional") |
62 |
+ @patch("portage.dbapi.bintree.binarytree._populate_local") |
63 |
+ def test_populate_with_repos( |
64 |
+ self, ppopulate_local, ppopulate_additional): |
65 |
+ repos = ("one", "two") |
66 |
+ bt = binarytree(pkgdir="/tmp", settings=MagicMock()) |
67 |
+ bt.populate(add_repos=repos) |
68 |
+ ppopulate_additional.assert_called_once_with(repos) |
69 |
+ |
70 |
+ @patch("portage.dbapi.bintree.BinRepoConfigLoader") |
71 |
+ @patch("portage.dbapi.bintree.binarytree._populate_remote") |
72 |
+ @patch("portage.dbapi.bintree.binarytree._populate_local") |
73 |
+ def test_populate_with_getbinpkgs( |
74 |
+ self, ppopulate_local, ppopulate_remote, pBinRepoConfigLoader): |
75 |
+ refresh = "something" |
76 |
+ settings = MagicMock() |
77 |
+ settings.__getitem__.return_value = "/some/path" |
78 |
+ bt = binarytree(pkgdir="/tmp", settings=settings) |
79 |
+ bt.populate(getbinpkgs=True, getbinpkg_refresh=refresh) |
80 |
+ ppopulate_remote.assert_called_once_with(getbinpkg_refresh=refresh) |
81 |
+ |
82 |
+ @patch("portage.dbapi.bintree.writemsg") |
83 |
+ @patch("portage.dbapi.bintree.BinRepoConfigLoader") |
84 |
+ @patch("portage.dbapi.bintree.binarytree._populate_remote") |
85 |
+ @patch("portage.dbapi.bintree.binarytree._populate_local") |
86 |
+ def test_populate_with_getbinpkgs_and_not_BinRepoConfigLoader( |
87 |
+ self, ppopulate_local, ppopulate_remote, pBinRepoConfigLoader, |
88 |
+ pwritemsg): |
89 |
+ refresh = "something" |
90 |
+ settings = MagicMock() |
91 |
+ portage_root = "/some/path" |
92 |
+ settings.__getitem__.return_value = portage_root |
93 |
+ pBinRepoConfigLoader.return_value = None |
94 |
+ conf_file = os.path.join(portage_root, BINREPOS_CONF_FILE) |
95 |
+ bt = binarytree(pkgdir="/tmp", settings=settings) |
96 |
+ bt.populate(getbinpkgs=True, getbinpkg_refresh=refresh) |
97 |
+ ppopulate_remote.assert_not_called() |
98 |
+ pwritemsg.assert_called_once_with( |
99 |
+ _(f"!!! {conf_file} is missing (or PORTAGE_BINHOST is unset)" |
100 |
+ ", but use is requested.\n"), noiselevel=-1 |
101 |
+ ) |