From: "Mike Gilbert" <floppym@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/util/, lib/portage/tests/util/
Date: Tue, 7 Jun 2022 23:48:15 +0000 (UTC) [thread overview]
Message-ID: <1654645675.4540f2b0a6529705343f493abb478370c15f101f.floppym@gentoo> (raw)
commit: 4540f2b0a6529705343f493abb478370c15f101f
Author: David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Mon May 30 07:00:32 2022 +0000
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Tue Jun 7 23:47:55 2022 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=4540f2b0
improvement(mtimedb): class has better API
New attribute ``is_readonly`` and new method ``make_readonly`` added.
Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
lib/portage/tests/util/test_mtimedb.py | 28 +++++++++++++++++++++++++---
lib/portage/util/mtimedb.py | 10 ++++++++++
2 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/lib/portage/tests/util/test_mtimedb.py b/lib/portage/tests/util/test_mtimedb.py
index a65a6be91..ecc0e7135 100644
--- a/lib/portage/tests/util/test_mtimedb.py
+++ b/lib/portage/tests/util/test_mtimedb.py
@@ -9,6 +9,8 @@ from portage.util.mtimedb import MtimeDB, _MTIMEDBKEYS
from portage.exception import DigestException
+# Some random data for the fixtures:
+
_ONE_RESUME_LIST_JSON = b"""{
"info": {
"/tmp/stage1root/usr/share/binutils-data/x86_64-pc-linux-gnu/2.34/info": 1711785090,
@@ -213,7 +215,7 @@ _TWO_RESUME_LISTS_JSON = b"""{
class MtimeDBTestCase(TestCase):
text = b"Unit tests for MtimeDB"
- def test_instance_created_with_only_expected_keys(self):
+ def test_instances_are_created_with_only_expected_keys(self):
all_fixtures = (
_ONE_RESUME_LIST_JSON,
_EMPTY_FILE,
@@ -227,7 +229,7 @@ class MtimeDBTestCase(TestCase):
mtimedb = MtimeDB("/path/to/mtimedb")
self.assertLessEqual(set(mtimedb.keys()), _MTIMEDBKEYS)
- def test_instance_has_default_values(self):
+ def test_instances_have_default_values(self):
with patch("portage.util.mtimedb.open",
mock_open(read_data=_EMPTY_FILE)):
mtimedb = MtimeDB("/some/path/mtimedb")
@@ -237,7 +239,7 @@ class MtimeDBTestCase(TestCase):
self.assertEqual(mtimedb["ldpath"], {})
self.assertEqual(mtimedb["updates"], {})
- def test_instance_has_a_deepcopy_of_clean_data(self):
+ def test_instances_keep_a_deepcopy_of_clean_data(self):
with patch("portage.util.mtimedb.open",
mock_open(read_data=_ONE_RESUME_LIST_JSON)):
mtimedb = MtimeDB("/some/path/mtimedb")
@@ -274,3 +276,23 @@ class MtimeDBTestCase(TestCase):
mtimedb = MtimeDB("/some/path/mtimedb")
mtimedb.commit()
pwrite2disk.assert_not_called()
+
+ def test_is_readonly_attribute(self):
+ with patch("portage.util.mtimedb.open",
+ mock_open(read_data=_ONE_RESUME_LIST_JSON)):
+ mtimedb = MtimeDB("/some/path/mtimedb")
+ self.assertFalse(mtimedb.is_readonly)
+
+ mtimedb.filename = None
+ self.assertTrue(mtimedb.is_readonly)
+
+ mtimedb.filename = "/what/ever/mtimedb"
+ self.assertFalse(mtimedb.is_readonly)
+
+ def test_make_readonly(self):
+ with patch("portage.util.mtimedb.open",
+ mock_open(read_data=_ONE_RESUME_LIST_JSON)):
+ mtimedb = MtimeDB("/some/path/mtimedb")
+ mtimedb.make_readonly()
+ self.assertTrue(mtimedb.is_readonly)
+ self.assertIs(mtimedb.filename, None)
diff --git a/lib/portage/util/mtimedb.py b/lib/portage/util/mtimedb.py
index a6566e3f8..95da2235f 100644
--- a/lib/portage/util/mtimedb.py
+++ b/lib/portage/util/mtimedb.py
@@ -51,6 +51,16 @@ class MtimeDB(dict):
self.filename = filename
self._load(filename)
+ @property
+ def is_readonly(self):
+ if self.filename is None:
+ return True
+ else:
+ return False
+
+ def make_readonly(self):
+ self.filename = None
+
def _load(self, filename):
f = None
content = None
next reply other threads:[~2022-06-07 23:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-07 23:48 Mike Gilbert [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-02-22 15:36 [gentoo-commits] proj/portage:master commit in: lib/portage/util/, lib/portage/tests/util/ Zac Medico
2022-12-31 13:33 Sam James
2022-06-07 23:48 Mike Gilbert
2022-06-07 23:48 Mike Gilbert
2022-06-07 23:48 Mike Gilbert
2019-01-16 8:33 Zac Medico
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1654645675.4540f2b0a6529705343f493abb478370c15f101f.floppym@gentoo \
--to=floppym@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox