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/tests/util/, lib/portage/util/
Date: Tue, 07 Jun 2022 23:48:48
Message-Id: 1654645675.cd6a9fa4338a2444c02ece8ff9fb59971a4fe98d.floppym@gentoo
1 commit: cd6a9fa4338a2444c02ece8ff9fb59971a4fe98d
2 Author: David Palao <david.palao <AT> gmail <DOT> com>
3 AuthorDate: Wed May 25 13:29:54 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=cd6a9fa4
7
8 test(mtimedb): added two more UTs about MtimeDB instances creation
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 | 23 ++++++++++++++++++++---
14 lib/portage/util/mtimedb.py | 6 ++++--
15 2 files changed, 24 insertions(+), 5 deletions(-)
16
17 diff --git a/lib/portage/tests/util/test_mtimedb.py b/lib/portage/tests/util/test_mtimedb.py
18 index 6ec009c38..e6ddf5b80 100644
19 --- a/lib/portage/tests/util/test_mtimedb.py
20 +++ b/lib/portage/tests/util/test_mtimedb.py
21 @@ -126,7 +126,7 @@ _PARTIAL_FILE_JSON = b"""{
22 }
23 """
24
25 -_TWO_RESUME_LIST_JSON = b"""{
26 +_TWO_RESUME_LISTS_JSON = b"""{
27 "info": {
28 "/usr/share/binutils-data/x86_64-pc-linux-gnu/2.34/info": 1711787325,
29 "/usr/share/gcc-data/x86_64-pc-linux-gnu/11.2.0/info": 1735158257,
30 @@ -213,12 +213,12 @@ _TWO_RESUME_LIST_JSON = b"""{
31 class MtimeDBTestCase(TestCase):
32 text = b"Unit tests for MtimeDB"
33
34 - def test_has_only_allowed_keys(self):
35 + def test_instance_created_with_only_expected_keys(self):
36 all_fixtures = (
37 _ONE_RESUME_LIST_JSON,
38 _EMPTY_FILE,
39 _PARTIAL_FILE_JSON,
40 - _TWO_RESUME_LIST_JSON,
41 + _TWO_RESUME_LISTS_JSON,
42 )
43 for contents in all_fixtures:
44 with patch(
45 @@ -226,3 +226,20 @@ class MtimeDBTestCase(TestCase):
46 ):
47 mtimedb = MtimeDB("/path/to/mtimedb")
48 self.assertLessEqual(set(mtimedb.keys()), _MTIMEDBKEYS)
49 +
50 + def test_instance_has_default_values(self):
51 + with patch('portage.util.mtimedb.open',
52 + mock_open(read_data=_EMPTY_FILE)):
53 + mtimedb = MtimeDB("/some/path/mtimedb")
54 + self.assertEqual(mtimedb["starttime"], 0)
55 + self.assertEqual(mtimedb["version"], "")
56 + self.assertEqual(mtimedb["info"], {})
57 + self.assertEqual(mtimedb["ldpath"], {})
58 + self.assertEqual(mtimedb["updates"], {})
59 +
60 + def test_instance_has_a_deepcopy_of_clean_data(self):
61 + with patch('portage.util.mtimedb.open',
62 + mock_open(read_data=_ONE_RESUME_LIST_JSON)):
63 + mtimedb = MtimeDB("/some/path/mtimedb")
64 + self.assertEqual(dict(mtimedb), dict(mtimedb._clean_data))
65 + self.assertIsNot(mtimedb, mtimedb._clean_data)
66
67 diff --git a/lib/portage/util/mtimedb.py b/lib/portage/util/mtimedb.py
68 index 37afba7c8..3aab0b90b 100644
69 --- a/lib/portage/util/mtimedb.py
70 +++ b/lib/portage/util/mtimedb.py
71 @@ -73,7 +73,8 @@ class MtimeDB(dict):
72 try:
73 d = json.loads(
74 _unicode_decode(
75 - content, encoding=_encodings["repo.content"], errors="strict"
76 + content, encoding=_encodings["repo.content"],
77 + errors="strict"
78 )
79 )
80 except SystemExit:
81 @@ -91,7 +92,8 @@ class MtimeDB(dict):
82 raise
83 except Exception:
84 writemsg(
85 - _(f"!!! Error loading '{filename}': {e}\n"), noiselevel=-1
86 + _(f"!!! Error loading '{filename}': {e}\n"),
87 + noiselevel=-1
88 )
89
90 if "old" in d: