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/portage/util/, lib/portage/tests/util/
Date: Tue, 07 Jun 2022 23:48:51
Message-Id: 1654645676.e22cf80ec99c52c1192ecf99f6b66d1d892f3f86.floppym@gentoo
1 commit: e22cf80ec99c52c1192ecf99f6b66d1d892f3f86
2 Author: David Palao <david.palao <AT> gmail <DOT> com>
3 AuthorDate: Fri Jun 3 09:13:17 2022 +0000
4 Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
5 CommitDate: Tue Jun 7 23:47:56 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=e22cf80e
7
8 improvement(pylint/black): some formatting issues fixed
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/util/test_mtimedb.py | 126 ++++++++++++++-------------------
14 lib/portage/util/mtimedb.py | 14 ++--
15 2 files changed, 59 insertions(+), 81 deletions(-)
16
17 diff --git a/lib/portage/tests/util/test_mtimedb.py b/lib/portage/tests/util/test_mtimedb.py
18 index 09d72049f..d80b4f1da 100644
19 --- a/lib/portage/tests/util/test_mtimedb.py
20 +++ b/lib/portage/tests/util/test_mtimedb.py
21 @@ -9,7 +9,6 @@ from portage.tests import TestCase
22 import portage
23 from portage.data import portage_gid, uid
24 from portage.util.mtimedb import MtimeDB, _MTIMEDBKEYS
25 -from portage.exception import DigestException
26
27
28 # Some data for the fixtures:
29 @@ -210,15 +209,12 @@ class MtimeDBTestCase(TestCase):
30 _TWO_RESUME_LISTS_JSON,
31 )
32 for contents in all_fixtures:
33 - with patch(
34 - "portage.util.mtimedb.open", mock_open(read_data=contents)
35 - ):
36 + with patch("portage.util.mtimedb.open", mock_open(read_data=contents)):
37 mtimedb = MtimeDB("/path/to/mtimedb")
38 self.assertLessEqual(set(mtimedb.keys()), _MTIMEDBKEYS)
39
40 def test_default_values(self):
41 - with patch("portage.util.mtimedb.open",
42 - mock_open(read_data=_EMPTY_FILE)):
43 + with patch("portage.util.mtimedb.open", mock_open(read_data=_EMPTY_FILE)):
44 mtimedb = MtimeDB("/some/path/mtimedb")
45 self.assertEqual(mtimedb["starttime"], 0)
46 self.assertEqual(mtimedb["version"], "")
47 @@ -227,88 +223,75 @@ class MtimeDBTestCase(TestCase):
48 self.assertEqual(mtimedb["updates"], {})
49
50 def test_instances_keep_a_deepcopy_of_clean_data(self):
51 - with patch("portage.util.mtimedb.open",
52 - mock_open(read_data=_ONE_RESUME_LIST_JSON)):
53 + with patch(
54 + "portage.util.mtimedb.open", mock_open(read_data=_ONE_RESUME_LIST_JSON)
55 + ):
56 mtimedb = MtimeDB("/some/path/mtimedb")
57 self.assertEqual(dict(mtimedb), dict(mtimedb._clean_data))
58 self.assertIsNot(mtimedb, mtimedb._clean_data)
59
60 def test_load_data_called_at_instance_creation_time(self):
61 - with patch("portage.util.mtimedb.open",
62 - mock_open(read_data=_ONE_RESUME_LIST_JSON)):
63 + with patch(
64 + "portage.util.mtimedb.open", mock_open(read_data=_ONE_RESUME_LIST_JSON)
65 + ):
66 mtimedb = MtimeDB("/some/path/mtimedb")
67 self.assertEqual(
68 mtimedb["info"],
69 {
70 - "/usr/share/binutils-data/x86_64-pc-linux-gnu/2.37/info": (
71 - 1711787325),
72 - "/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.0/info": (
73 - 1735158257),
74 - "/usr/share/info": 1650633847
75 - }
76 + "/usr/share/binutils-data/x86_64-pc-linux-gnu/2.37/info": (1711787325),
77 + "/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.0/info": (1735158257),
78 + "/usr/share/info": 1650633847,
79 + },
80 )
81 self.assertEqual(
82 mtimedb["ldpath"],
83 {
84 - "/lib": 1748456830,
85 - "/lib64": 1750523381,
86 - "/usr/lib": 1750461195,
87 - "/usr/lib/llvm/13/lib64": 1747003135,
88 - "/usr/lib/rust/lib": 1750461173,
89 - "/usr/lib64": 1750881821,
90 - "/usr/local/lib": 1711784303,
91 - "/usr/local/lib64": 1711784303
92 - }
93 + "/lib": 1748456830,
94 + "/lib64": 1750523381,
95 + "/usr/lib": 1750461195,
96 + "/usr/lib/llvm/13/lib64": 1747003135,
97 + "/usr/lib/rust/lib": 1750461173,
98 + "/usr/lib64": 1750881821,
99 + "/usr/local/lib": 1711784303,
100 + "/usr/local/lib64": 1711784303,
101 + },
102 )
103 self.assertEqual(
104 mtimedb["resume"],
105 {
106 - "favorites": [
107 - "@world"
108 - ],
109 - "mergelist": [
110 - [
111 - "ebuild",
112 - "/",
113 - "some-cat/some-package-1.2.3-r4",
114 - "merge"
115 - ],
116 - [
117 - "ebuild",
118 - "/",
119 - "another-cat/another-package-4.3.2-r1",
120 - "merge"
121 - ]
122 - ],
123 - "myopts": {
124 - "--buildpkg": True,
125 - "--deep": True,
126 - "--getbinpkg": True,
127 - "--keep-going": True,
128 - "--newuse": True,
129 - "--quiet": True,
130 - "--regex-search-auto": "y",
131 - "--update": True,
132 - "--usepkg": True,
133 - "--verbose": True
134 - }
135 - }
136 + "favorites": ["@world"],
137 + "mergelist": [
138 + ["ebuild", "/", "some-cat/some-package-1.2.3-r4", "merge"],
139 + ["ebuild", "/", "another-cat/another-package-4.3.2-r1", "merge"],
140 + ],
141 + "myopts": {
142 + "--buildpkg": True,
143 + "--deep": True,
144 + "--getbinpkg": True,
145 + "--keep-going": True,
146 + "--newuse": True,
147 + "--quiet": True,
148 + "--regex-search-auto": "y",
149 + "--update": True,
150 + "--usepkg": True,
151 + "--verbose": True,
152 + },
153 + },
154 )
155 self.assertEqual(mtimedb["starttime"], 0)
156 self.assertEqual(
157 mtimedb["updates"],
158 {
159 - "/var/db/repos/gentoo/profiles/updates/1Q-2022": 1747854791,
160 - "/var/db/repos/gentoo/profiles/updates/2Q-2022": 1752846209,
161 - "/var/db/repos/gentoo/profiles/updates/4Q-2021": 1742787797
162 - }
163 + "/var/db/repos/gentoo/profiles/updates/1Q-2022": 1747854791,
164 + "/var/db/repos/gentoo/profiles/updates/2Q-2022": 1752846209,
165 + "/var/db/repos/gentoo/profiles/updates/4Q-2021": 1742787797,
166 + },
167 )
168 self.assertEqual(mtimedb["version"], "3.0.30")
169
170 @patch("portage.util.mtimedb.MtimeDB._MtimeDB__write_to_disk")
171 def test_commit_writes_to_disk_if_needed_and_possible(self, pwrite2disk):
172 - with patch("portage.util.mtimedb.open",
173 - mock_open(read_data=_EMPTY_FILE)):
174 + with patch("portage.util.mtimedb.open", mock_open(read_data=_EMPTY_FILE)):
175 mtimedb = MtimeDB("/some/path/mtimedb")
176 mtimedb.commit()
177 pwrite2disk.assert_not_called()
178 @@ -320,8 +303,7 @@ class MtimeDBTestCase(TestCase):
179
180 @patch("portage.util.mtimedb.MtimeDB._MtimeDB__write_to_disk")
181 def test_commit_does_not_write_to_disk_if_no_file(self, pwrite2disk):
182 - with patch("portage.util.mtimedb.open",
183 - mock_open(read_data=_EMPTY_FILE)):
184 + with patch("portage.util.mtimedb.open", mock_open(read_data=_EMPTY_FILE)):
185 mtimedb = MtimeDB("/some/path/mtimedb")
186 mtimedb["updates"]["/long/path/1Q-2021"] = 1739992409
187 mtimedb.filename = None
188 @@ -330,15 +312,15 @@ class MtimeDBTestCase(TestCase):
189
190 @patch("portage.util.mtimedb.MtimeDB._MtimeDB__write_to_disk")
191 def test_commit_does_not_write_to_disk_if_no_changes(self, pwrite2disk):
192 - with patch("portage.util.mtimedb.open",
193 - mock_open(read_data=_EMPTY_FILE)):
194 + with patch("portage.util.mtimedb.open", mock_open(read_data=_EMPTY_FILE)):
195 mtimedb = MtimeDB("/some/path/mtimedb")
196 mtimedb.commit()
197 pwrite2disk.assert_not_called()
198
199 def test_is_readonly_attribute(self):
200 - with patch("portage.util.mtimedb.open",
201 - mock_open(read_data=_ONE_RESUME_LIST_JSON)):
202 + with patch(
203 + "portage.util.mtimedb.open", mock_open(read_data=_ONE_RESUME_LIST_JSON)
204 + ):
205 mtimedb = MtimeDB("/some/path/mtimedb")
206 self.assertFalse(mtimedb.is_readonly)
207
208 @@ -349,8 +331,9 @@ class MtimeDBTestCase(TestCase):
209 self.assertFalse(mtimedb.is_readonly)
210
211 def test_make_readonly(self):
212 - with patch("portage.util.mtimedb.open",
213 - mock_open(read_data=_ONE_RESUME_LIST_JSON)):
214 + with patch(
215 + "portage.util.mtimedb.open", mock_open(read_data=_ONE_RESUME_LIST_JSON)
216 + ):
217 mtimedb = MtimeDB("/some/path/mtimedb")
218 mtimedb.make_readonly()
219 self.assertTrue(mtimedb.is_readonly)
220 @@ -359,8 +342,9 @@ class MtimeDBTestCase(TestCase):
221 @patch("portage.util.mtimedb.apply_secpass_permissions")
222 @patch("portage.util.mtimedb.atomic_ofstream")
223 def test_write_to_disk(self, matomic_ofstream, mapply_perms):
224 - with patch("portage.util.mtimedb.open",
225 - mock_open(read_data=_ONE_RESUME_LIST_JSON)):
226 + with patch(
227 + "portage.util.mtimedb.open", mock_open(read_data=_ONE_RESUME_LIST_JSON)
228 + ):
229 mtimedb = MtimeDB("/some/path/mtimedb")
230 d = {"z": "zome", "a": "AAA"}
231 encoding = portage._encodings["repo.content"]
232
233 diff --git a/lib/portage/util/mtimedb.py b/lib/portage/util/mtimedb.py
234 index 497c01e05..098350526 100644
235 --- a/lib/portage/util/mtimedb.py
236 +++ b/lib/portage/util/mtimedb.py
237 @@ -71,9 +71,7 @@ class MtimeDB(dict):
238 if getattr(e, "errno", None) in (errno.ENOENT, errno.EACCES):
239 pass
240 else:
241 - writemsg(
242 - _(f"!!! Error loading '{filename}': {e}\n"), noiselevel=-1
243 - )
244 + writemsg(_(f"!!! Error loading '{filename}': {e}\n"), noiselevel=-1)
245 finally:
246 if f is not None:
247 f.close()
248 @@ -83,8 +81,7 @@ class MtimeDB(dict):
249 try:
250 d = json.loads(
251 _unicode_decode(
252 - content, encoding=_encodings["repo.content"],
253 - errors="strict"
254 + content, encoding=_encodings["repo.content"], errors="strict"
255 )
256 )
257 except SystemExit:
258 @@ -101,10 +98,7 @@ class MtimeDB(dict):
259 except SystemExit:
260 raise
261 except Exception:
262 - writemsg(
263 - _(f"!!! Error loading '{filename}': {e}\n"),
264 - noiselevel=-1
265 - )
266 + writemsg(_(f"!!! Error loading '{filename}': {e}\n"), noiselevel=-1)
267
268 if "old" in d:
269 d["updates"] = d["old"]
270 @@ -117,7 +111,7 @@ class MtimeDB(dict):
271 for k in ("info", "ldpath", "updates"):
272 d.setdefault(k, {})
273
274 - for k in (set(d.keys())-_MTIMEDBKEYS):
275 + for k in set(d.keys()) - _MTIMEDBKEYS:
276 writemsg(_(f"Deleting invalid mtimedb key: {k}\n"))
277 del d[k]
278 self.update(d)