aboutsummaryrefslogtreecommitdiffstats
path: root/lib/portage/tests/util/test_mtimedb.py
diff options
context:
space:
mode:
authorDavid Palao <david.palao@gmail.com>2022-05-25 17:23:20 +0200
committerMike Gilbert <floppym@gentoo.org>2022-06-07 19:47:55 -0400
commitc79c8898dc4ccd85829d00e7104b8e69ae8aa7f4 (patch)
treed2f9c24783f0cecfe9a575d158eb884ffb8f791f /lib/portage/tests/util/test_mtimedb.py
parenttest(mtimedb): added two more UTs about MtimeDB instances creation (diff)
downloadgentoo-portage-c79c8898dc4ccd85829d00e7104b8e69ae8aa7f4.tar.xz
gentoo-portage-c79c8898dc4ccd85829d00e7104b8e69ae8aa7f4.zip
refactor(mtimedb): MtimeDB.commit splitted into two methods
- commit itself handles only the logic of when to write to disk - __write_to_disk performs the actual writing Signed-off-by: David Palao <david.palao@gmail.com> Signed-off-by: Mike Gilbert <floppym@gentoo.org>
Diffstat (limited to 'lib/portage/tests/util/test_mtimedb.py')
-rw-r--r--lib/portage/tests/util/test_mtimedb.py37
1 files changed, 34 insertions, 3 deletions
diff --git a/lib/portage/tests/util/test_mtimedb.py b/lib/portage/tests/util/test_mtimedb.py
index e6ddf5b80b2..a65a6be9128 100644
--- a/lib/portage/tests/util/test_mtimedb.py
+++ b/lib/portage/tests/util/test_mtimedb.py
@@ -222,13 +222,13 @@ class MtimeDBTestCase(TestCase):
)
for contents in all_fixtures:
with patch(
- 'portage.util.mtimedb.open', mock_open(read_data=contents)
+ "portage.util.mtimedb.open", mock_open(read_data=contents)
):
mtimedb = MtimeDB("/path/to/mtimedb")
self.assertLessEqual(set(mtimedb.keys()), _MTIMEDBKEYS)
def test_instance_has_default_values(self):
- with patch('portage.util.mtimedb.open',
+ with patch("portage.util.mtimedb.open",
mock_open(read_data=_EMPTY_FILE)):
mtimedb = MtimeDB("/some/path/mtimedb")
self.assertEqual(mtimedb["starttime"], 0)
@@ -238,8 +238,39 @@ class MtimeDBTestCase(TestCase):
self.assertEqual(mtimedb["updates"], {})
def test_instance_has_a_deepcopy_of_clean_data(self):
- with patch('portage.util.mtimedb.open',
+ with patch("portage.util.mtimedb.open",
mock_open(read_data=_ONE_RESUME_LIST_JSON)):
mtimedb = MtimeDB("/some/path/mtimedb")
self.assertEqual(dict(mtimedb), dict(mtimedb._clean_data))
self.assertIsNot(mtimedb, mtimedb._clean_data)
+
+ @patch("portage.util.mtimedb.MtimeDB._MtimeDB__write_to_disk")
+ def test_commit_writes_to_disk_if_needed_and_possible(self, pwrite2disk):
+ with patch("portage.util.mtimedb.open",
+ mock_open(read_data=_EMPTY_FILE)):
+ mtimedb = MtimeDB("/some/path/mtimedb")
+ mtimedb.commit()
+ pwrite2disk.assert_not_called()
+ mtimedb["updates"]["/long/path/1Q-2021"] = 1739992409
+ d = {}
+ d.update(mtimedb)
+ mtimedb.commit()
+ pwrite2disk.assert_called_once_with(d)
+
+ @patch("portage.util.mtimedb.MtimeDB._MtimeDB__write_to_disk")
+ def test_commit_does_not_write_to_disk_if_no_file(self, pwrite2disk):
+ with patch("portage.util.mtimedb.open",
+ mock_open(read_data=_EMPTY_FILE)):
+ mtimedb = MtimeDB("/some/path/mtimedb")
+ mtimedb["updates"]["/long/path/1Q-2021"] = 1739992409
+ mtimedb.filename = None
+ mtimedb.commit()
+ pwrite2disk.assert_not_called()
+
+ @patch("portage.util.mtimedb.MtimeDB._MtimeDB__write_to_disk")
+ def test_commit_does_not_write_to_disk_if_no_changes(self, pwrite2disk):
+ with patch("portage.util.mtimedb.open",
+ mock_open(read_data=_EMPTY_FILE)):
+ mtimedb = MtimeDB("/some/path/mtimedb")
+ mtimedb.commit()
+ pwrite2disk.assert_not_called()