From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 23328158091 for ; Tue, 7 Jun 2022 23:48:49 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1E4DEE0866; Tue, 7 Jun 2022 23:48:48 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 03CDEE0866 for ; Tue, 7 Jun 2022 23:48:48 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 16EFF335D68 for ; Tue, 7 Jun 2022 23:48:47 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 88B904F8 for ; Tue, 7 Jun 2022 23:48:15 +0000 (UTC) From: "Mike Gilbert" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Gilbert" Message-ID: <1654645675.4540f2b0a6529705343f493abb478370c15f101f.floppym@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/util/, lib/portage/tests/util/ X-VCS-Repository: proj/portage X-VCS-Files: lib/portage/tests/util/test_mtimedb.py lib/portage/util/mtimedb.py X-VCS-Directories: lib/portage/tests/util/ lib/portage/util/ X-VCS-Committer: floppym X-VCS-Committer-Name: Mike Gilbert X-VCS-Revision: 4540f2b0a6529705343f493abb478370c15f101f X-VCS-Branch: master Date: Tue, 7 Jun 2022 23:48:15 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: a251489e-a2a9-4712-b938-335fddec9548 X-Archives-Hash: dedbd244b732967f81cfe6df4b688ba4 commit: 4540f2b0a6529705343f493abb478370c15f101f Author: David Palao gmail com> AuthorDate: Mon May 30 07:00:32 2022 +0000 Commit: Mike Gilbert gentoo 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 gmail.com> Signed-off-by: Mike Gilbert 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