summaryrefslogtreecommitdiff
path: root/Lib/test/test_mailbox.py
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2012-06-28 13:53:43 +0300
committerPetri Lehtinen <petri@digip.org>2012-06-28 13:53:43 +0300
commit7991fa641d77edb14f2528980fa147cfe519f2df (patch)
tree6d745fa65ae68d9e6c8d5e30105954d21a4c3e37 /Lib/test/test_mailbox.py
parent9057a01fb07cc98d4d973dde1afe8b19cb38f263 (diff)
parentacc950a2fc6d50f1c6c6ed4339600f307574d8ab (diff)
downloadcpython-7991fa641d77edb14f2528980fa147cfe519f2df.tar.gz
#9559: Append data to single-file mailbox files if messages are only added
If messages were only added, a new file is no longer created and renamed over the old file when flush() is called on an mbox, MMDF or Babyl mailbox.
Diffstat (limited to 'Lib/test/test_mailbox.py')
-rw-r--r--Lib/test/test_mailbox.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index cb54505d9a..c56002bebf 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -945,7 +945,32 @@ class TestMaildir(TestMailbox, unittest.TestCase):
self._box._refresh()
self.assertTrue(refreshed())
-class _TestMboxMMDF(TestMailbox):
+
+class _TestSingleFile(TestMailbox):
+ '''Common tests for single-file mailboxes'''
+
+ def test_add_doesnt_rewrite(self):
+ # When only adding messages, flush() should not rewrite the
+ # mailbox file. See issue #9559.
+
+ # Inode number changes if the contents are written to another
+ # file which is then renamed over the original file. So we
+ # must check that the inode number doesn't change.
+ inode_before = os.stat(self._path).st_ino
+
+ self._box.add(self._template % 0)
+ self._box.flush()
+
+ inode_after = os.stat(self._path).st_ino
+ self.assertEqual(inode_before, inode_after)
+
+ # Make sure the message was really added
+ self._box.close()
+ self._box = self._factory(self._path)
+ self.assertEqual(len(self._box), 1)
+
+
+class _TestMboxMMDF(_TestSingleFile):
def tearDown(self):
super().tearDown()
@@ -1220,7 +1245,7 @@ class TestMH(TestMailbox, unittest.TestCase):
return os.path.join(self._path, '.mh_sequences.lock')
-class TestBabyl(TestMailbox, unittest.TestCase):
+class TestBabyl(_TestSingleFile, unittest.TestCase):
_factory = lambda self, path, factory=None: mailbox.Babyl(path, factory)