[Zope3-checkins] CVS: Zope3/src/zope/app/mail/tests - test_maildir.py:1.3
Jeremy Hylton
jeremy@zope.com
Mon, 30 Jun 2003 18:44:38 -0400
Update of /cvs-repository/Zope3/src/zope/app/mail/tests
In directory cvs.zope.org:/tmp/cvs-serv15677/src/zope/app/mail/tests
Modified Files:
test_maildir.py
Log Message:
Refactor to use os.path.exists().
=== Zope3/src/zope/app/mail/tests/test_maildir.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/mail/tests/test_maildir.py:1.2 Tue Jun 3 18:46:20 2003
+++ Zope3/src/zope/app/mail/tests/test_maildir.py Mon Jun 30 18:44:38 2003
@@ -40,14 +40,24 @@
class FakeOsPathModule:
+ def __init__(self, files, dirs):
+ self.files = files
+ self.dirs = dirs
+
+ _exists_never_fails = False
+
def join(self, *args):
return '/'.join(args)
+ def isdir(self, dir):
+ return dir in self.dirs
+
+ def exists(self, p):
+ return self._exists_never_fails or p in self.files
+
class FakeOsModule:
F_OK = 0
- path = FakeOsPathModule()
-
_stat_mode = {
'/path/to/maildir': stat.S_IFDIR,
'/path/to/maildir/new': stat.S_IFDIR,
@@ -64,13 +74,14 @@
'/path/to/regularfile': stat.S_IFREG,
'/path/to/emptydirectory': stat.S_IFDIR,
}
- _stat_never_fails = False
_listdir = {
'/path/to/maildir/new': ['1', '2'],
'/path/to/maildir/cur': ['2', '1'],
'/path/to/maildir/tmp': ['1', '2'],
}
+ path = FakeOsPathModule(_stat_mode, _listdir)
+
_made_directories = ()
_removed_files = ()
_renamed_files = ()
@@ -81,8 +92,6 @@
def stat(self, path):
if path in self._stat_mode:
return (self._stat_mode[path], 0, 0, 1, 0, 0, 0, 0, 0, 0)
- if self._stat_never_fails:
- return (stat.S_IFREG, 0, 0, 1, 0, 0, 0, 0, 0, 0)
raise OSError('%s does not exist' % path)
def listdir(self, path):
@@ -151,8 +160,8 @@
verifyObject(IMaildir, m)
# Case 2a: directory does not exist, create = False
- self.assertRaises(OSError, Maildir, '/path/to/nosuchfolder', False)
-
+ self.assertRaises(ValueError, Maildir, '/path/to/nosuchfolder', False)
+
# Case 2b: directory does not exist, create = True
m = Maildir('/path/to/nosuchfolder', True)
verifyObject(IMaildir, m)
@@ -164,8 +173,8 @@
'/path/to/nosuchfolder/tmp'])
# Case 3: it is a file, not a directory
- self.assertRaises(OSError, Maildir, '/path/to/regularfile', False)
- self.assertRaises(OSError, Maildir, '/path/to/regularfile', True)
+ self.assertRaises(ValueError, Maildir, '/path/to/regularfile', False)
+ self.assertRaises(ValueError, Maildir, '/path/to/regularfile', True)
# Case 4: it is a directory, but not a maildir
self.assertRaises(OSError, Maildir, '/path/to/emptydirectory', False)
@@ -193,7 +202,7 @@
def test_newMessage_never_loops(self):
from zope.app.mail.maildir import Maildir
from zope.app.interfaces.mail import IMaildirMessageWriter
- self.fake_os_module._stat_never_fails = True
+ self.fake_os_module.path._exists_never_fails = True
m = Maildir('/path/to/maildir')
self.assertRaises(RuntimeError, m.newMessage)