summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_mailbox.py
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2009-05-02 19:17:28 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2009-05-02 19:17:28 (GMT)
commit420d4eb1f3d647487a9c1bb855ec298653165624 (patch)
tree1be430ba39eead18aa141e1e6aa210930fa789cf /Lib/test/test_mailbox.py
parent6e7bdde2c8e006a3251c31885693f8105c1f880e (diff)
downloadcpython-420d4eb1f3d647487a9c1bb855ec298653165624.zip
cpython-420d4eb1f3d647487a9c1bb855ec298653165624.tar.gz
cpython-420d4eb1f3d647487a9c1bb855ec298653165624.tar.bz2
#1607951: Make mailbox.Maildir re-read the directories less frequently.
This is done by recording the current time -1sec, and not re-reading unless the directory mod. times are >= the recorded time.
Diffstat (limited to 'Lib/test/test_mailbox.py')
-rw-r--r--Lib/test/test_mailbox.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index 714bf25..6342676 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -747,6 +747,37 @@ class TestMaildir(TestMailbox):
perms = st.st_mode
self.assertFalse((perms & 0111)) # Execute bits should all be off.
+ def test_reread(self):
+ # Wait for 2 seconds
+ time.sleep(2)
+
+ # Initially, the mailbox has not been read and the time is null.
+ assert getattr(self._box, '_last_read', None) is None
+
+ # Refresh mailbox; the times should now be set to something.
+ self._box._refresh()
+ assert getattr(self._box, '_last_read', None) is not None
+
+ # Try calling _refresh() again; the modification times shouldn't have
+ # changed, so the mailbox should not be re-reading. Re-reading causes
+ # the ._toc attribute to be assigned a new dictionary object, so
+ # we'll check that the ._toc attribute isn't a different object.
+ orig_toc = self._box._toc
+ def refreshed():
+ return self._box._toc is not orig_toc
+
+ time.sleep(1) # Wait 1sec to ensure time.time()'s value changes
+ self._box._refresh()
+ assert not refreshed()
+
+ # Now, write something into cur and remove it. This changes
+ # the mtime and should cause a re-read.
+ filename = os.path.join(self._path, 'cur', 'stray-file')
+ f = open(filename, 'w')
+ f.close()
+ os.unlink(filename)
+ self._box._refresh()
+ assert refreshed()
class _TestMboxMMDF(TestMailbox):