1 |
commit: f753c049d5ecd6b7d7b01b4efa678c59c49bcebc |
2 |
Author: David Palao <david.palao <AT> gmail <DOT> com> |
3 |
AuthorDate: Tue May 24 15:47:56 2022 +0000 |
4 |
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jun 7 23:47:55 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=f753c049 |
7 |
|
8 |
test(mtimedb): added first unit tests for MtimeDB |
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 | 228 +++++++++++++++++++++++++++++++++ |
14 |
lib/portage/util/mtimedb.py | 2 +- |
15 |
2 files changed, 229 insertions(+), 1 deletion(-) |
16 |
|
17 |
diff --git a/lib/portage/tests/util/test_mtimedb.py b/lib/portage/tests/util/test_mtimedb.py |
18 |
new file mode 100644 |
19 |
index 000000000..6ec009c38 |
20 |
--- /dev/null |
21 |
+++ b/lib/portage/tests/util/test_mtimedb.py |
22 |
@@ -0,0 +1,228 @@ |
23 |
+# Copyright 2022 Gentoo Foundation |
24 |
+# Distributed under the terms of the GNU General Public License v2 |
25 |
+ |
26 |
+from unittest.mock import patch, mock_open |
27 |
+ |
28 |
+from portage.tests import TestCase |
29 |
+ |
30 |
+from portage.util.mtimedb import MtimeDB, _MTIMEDBKEYS |
31 |
+from portage.exception import DigestException |
32 |
+ |
33 |
+ |
34 |
+_ONE_RESUME_LIST_JSON = b"""{ |
35 |
+ "info": { |
36 |
+ "/tmp/stage1root/usr/share/binutils-data/x86_64-pc-linux-gnu/2.34/info": 1711785090, |
37 |
+ "/tmp/stage1root/usr/share/gcc-data/x86_64-pc-linux-gnu/9.3.0/info": 1711785090, |
38 |
+ "/tmp/stage1root/usr/share/info": 1611785090, |
39 |
+ "/usr/share/binutils-data/x86_64-pc-linux-gnu/2.34/info": 1711787325, |
40 |
+ "/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.0/info": 1735158257, |
41 |
+ "/usr/share/gcc-data/x86_64-pc-linux-gnu/9.3.0/info": 1711787325, |
42 |
+ "/usr/share/info": 1650633847 |
43 |
+ }, |
44 |
+ "ldpath": { |
45 |
+ "/lib": 1748456830, |
46 |
+ "/lib64": 1750523381, |
47 |
+ "/usr/lib": 1750461195, |
48 |
+ "/usr/lib/llvm/11/lib64": 1723048948, |
49 |
+ "/usr/lib/llvm/12/lib64": 1730499781, |
50 |
+ "/usr/lib/llvm/13/lib64": 1747003135, |
51 |
+ "/usr/lib/rust/lib": 1750461173, |
52 |
+ "/usr/lib64": 1750881821, |
53 |
+ "/usr/local/lib": 1711784303, |
54 |
+ "/usr/local/lib64": 1711784303 |
55 |
+ }, |
56 |
+ "resume": { |
57 |
+ "favorites": [ |
58 |
+ "@world" |
59 |
+ ], |
60 |
+ "mergelist": [ |
61 |
+ [ |
62 |
+ "ebuild", |
63 |
+ "/", |
64 |
+ "some-cat/some-package-1.2.3-r4", |
65 |
+ "merge" |
66 |
+ ], |
67 |
+ [ |
68 |
+ "ebuild", |
69 |
+ "/", |
70 |
+ "another-cat/another-package-4.3.2-r1", |
71 |
+ "merge" |
72 |
+ ] |
73 |
+ ], |
74 |
+ "myopts": { |
75 |
+ "--buildpkg": true, |
76 |
+ "--deep": true, |
77 |
+ "--getbinpkg": true, |
78 |
+ "--keep-going": true, |
79 |
+ "--newuse": true, |
80 |
+ "--quiet": true, |
81 |
+ "--regex-search-auto": "y", |
82 |
+ "--update": true, |
83 |
+ "--usepkg": true, |
84 |
+ "--verbose": true |
85 |
+ } |
86 |
+ }, |
87 |
+ "starttime": 0, |
88 |
+ "updates": { |
89 |
+ "/var/db/repos/gentoo/profiles/updates/1Q-2021": 1739992409, |
90 |
+ "/var/db/repos/gentoo/profiles/updates/1Q-2022": 1747854791, |
91 |
+ "/var/db/repos/gentoo/profiles/updates/2Q-2021": 1724404379, |
92 |
+ "/var/db/repos/gentoo/profiles/updates/2Q-2022": 1752846209, |
93 |
+ "/var/db/repos/gentoo/profiles/updates/3Q-2021": 1741119203, |
94 |
+ "/var/db/repos/gentoo/profiles/updates/4Q-2020": 1709167362, |
95 |
+ "/var/db/repos/gentoo/profiles/updates/4Q-2021": 1742787797 |
96 |
+ }, |
97 |
+ "version": "3.0.30" |
98 |
+} |
99 |
+""" |
100 |
+ |
101 |
+_EMPTY_FILE = b"" |
102 |
+ |
103 |
+_PARTIAL_FILE_JSON = b"""{ |
104 |
+ "ldpath": { |
105 |
+ "/lib": 1748456830, |
106 |
+ "/lib64": 1750523381, |
107 |
+ "/usr/lib": 1750461195, |
108 |
+ "/usr/lib/llvm/11/lib64": 1723048948, |
109 |
+ "/usr/lib/llvm/12/lib64": 1730499781, |
110 |
+ "/usr/lib/llvm/13/lib64": 1747003135, |
111 |
+ "/usr/lib/rust/lib": 1750461173, |
112 |
+ "/usr/lib64": 1750881821, |
113 |
+ "/usr/local/lib": 1711784303, |
114 |
+ "/usr/local/lib64": 1711784303 |
115 |
+ }, |
116 |
+ "resume": { |
117 |
+ "favorites": [ |
118 |
+ "@world" |
119 |
+ ], |
120 |
+ "mergelist": [ |
121 |
+ [ |
122 |
+ "ebuild", |
123 |
+ "/", |
124 |
+ "some-cat/some-package-1.2.3-r4", |
125 |
+ "merge" |
126 |
+ ], |
127 |
+ [ |
128 |
+ "ebuild", |
129 |
+ "/", |
130 |
+ "another-cat/another-package-4.3.2-r1", |
131 |
+ "merge" |
132 |
+ ] |
133 |
+ ], |
134 |
+ "myopts": { |
135 |
+ "--buildpkg": true, |
136 |
+ "--deep": true, |
137 |
+ "--getbinpkg": true, |
138 |
+ "--keep-going": true, |
139 |
+ "--newuse": true, |
140 |
+ "--quiet": true, |
141 |
+ "--regex-search-auto": "y", |
142 |
+ "--update": true, |
143 |
+ "--usepkg": true, |
144 |
+ "--verbose": true |
145 |
+ } |
146 |
+ }, |
147 |
+ "starttime": 0, |
148 |
+} |
149 |
+""" |
150 |
+ |
151 |
+_TWO_RESUME_LIST_JSON = b"""{ |
152 |
+ "info": { |
153 |
+ "/usr/share/binutils-data/x86_64-pc-linux-gnu/2.34/info": 1711787325, |
154 |
+ "/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.0/info": 1735158257, |
155 |
+ "/usr/share/info": 1650633847 |
156 |
+ }, |
157 |
+ "ldpath": { |
158 |
+ "/lib": 1748456830, |
159 |
+ "/lib64": 1750523381, |
160 |
+ "/usr/lib": 1750461195, |
161 |
+ "/usr/lib/llvm/13/lib64": 1747003135, |
162 |
+ "/usr/lib/rust/lib": 1750461173, |
163 |
+ "/usr/lib64": 1750881821, |
164 |
+ }, |
165 |
+ "resume": { |
166 |
+ "favorites": [ |
167 |
+ "@world" |
168 |
+ ], |
169 |
+ "mergelist": [ |
170 |
+ [ |
171 |
+ "ebuild", |
172 |
+ "/", |
173 |
+ "some-cat/some-package-1.2.3-r4", |
174 |
+ "merge" |
175 |
+ ], |
176 |
+ [ |
177 |
+ "ebuild", |
178 |
+ "/", |
179 |
+ "another-cat/another-package-4.3.2-r1", |
180 |
+ "merge" |
181 |
+ ] |
182 |
+ ], |
183 |
+ "myopts": { |
184 |
+ "--buildpkg": true, |
185 |
+ "--deep": true, |
186 |
+ "--getbinpkg": true, |
187 |
+ "--keep-going": true, |
188 |
+ "--newuse": true, |
189 |
+ "--quiet": true, |
190 |
+ "--regex-search-auto": "y", |
191 |
+ "--update": true, |
192 |
+ "--usepkg": true, |
193 |
+ "--verbose": true |
194 |
+ } |
195 |
+ }, |
196 |
+ "resume_backup": { |
197 |
+ "favorites": [ |
198 |
+ "my-cat/cool" |
199 |
+ ], |
200 |
+ "mergelist": [ |
201 |
+ [ |
202 |
+ "ebuild", |
203 |
+ "/", |
204 |
+ "sys-apps/cool-dep-2.2.2", |
205 |
+ "merge" |
206 |
+ ], |
207 |
+ [ |
208 |
+ "binary", |
209 |
+ "/", |
210 |
+ "my-cat/cool-1.5.2", |
211 |
+ "merge" |
212 |
+ ] |
213 |
+ ], |
214 |
+ "myopts": { |
215 |
+ "--getbinpkg": true, |
216 |
+ "--regex-search-auto": "y", |
217 |
+ "--usepkg": true, |
218 |
+ } |
219 |
+ }, |
220 |
+ "starttime": 0, |
221 |
+ "updates": { |
222 |
+ "/var/db/repos/gentoo/profiles/updates/1Q-2021": 1739992409, |
223 |
+ "/var/db/repos/gentoo/profiles/updates/1Q-2022": 1747854791, |
224 |
+ "/var/db/repos/gentoo/profiles/updates/2Q-2021": 1724404379, |
225 |
+ "/var/db/repos/gentoo/profiles/updates/2Q-2022": 1752846209, |
226 |
+ "/var/db/repos/gentoo/profiles/updates/3Q-2021": 1741119203, |
227 |
+ "/var/db/repos/gentoo/profiles/updates/4Q-2020": 1709167362, |
228 |
+ "/var/db/repos/gentoo/profiles/updates/4Q-2021": 1742787797 |
229 |
+ }, |
230 |
+ "version": "3.0.30" |
231 |
+} |
232 |
+""" |
233 |
+ |
234 |
+ |
235 |
+class MtimeDBTestCase(TestCase): |
236 |
+ text = b"Unit tests for MtimeDB" |
237 |
+ |
238 |
+ def test_has_only_allowed_keys(self): |
239 |
+ all_fixtures = ( |
240 |
+ _ONE_RESUME_LIST_JSON, |
241 |
+ _EMPTY_FILE, |
242 |
+ _PARTIAL_FILE_JSON, |
243 |
+ _TWO_RESUME_LIST_JSON, |
244 |
+ ) |
245 |
+ for contents in all_fixtures: |
246 |
+ with patch( |
247 |
+ 'portage.util.mtimedb.open', mock_open(read_data=contents) |
248 |
+ ): |
249 |
+ mtimedb = MtimeDB("/path/to/mtimedb") |
250 |
+ self.assertLessEqual(set(mtimedb.keys()), _MTIMEDBKEYS) |
251 |
|
252 |
diff --git a/lib/portage/util/mtimedb.py b/lib/portage/util/mtimedb.py |
253 |
index df9bd494c..37afba7c8 100644 |
254 |
--- a/lib/portage/util/mtimedb.py |
255 |
+++ b/lib/portage/util/mtimedb.py |
256 |
@@ -105,7 +105,7 @@ class MtimeDB(dict): |
257 |
for k in ("info", "ldpath", "updates"): |
258 |
d.setdefault(k, {}) |
259 |
|
260 |
- for k in (d.keys()-_MTIMEDBKEYS): |
261 |
+ for k in (set(d.keys())-_MTIMEDBKEYS): |
262 |
writemsg(_(f"Deleting invalid mtimedb key: {k}\n")) |
263 |
del d[k] |
264 |
self.update(d) |