diff options
author | Andrew M. Kuchling <amk@amk.ca> | 2008-08-05 01:00:57 (GMT) |
---|---|---|
committer | Andrew M. Kuchling <amk@amk.ca> | 2008-08-05 01:00:57 (GMT) |
commit | 10288e19bf09ae79923794ed50da60af7eb5e3a1 (patch) | |
tree | 20a423c72f0d644503feded03c2fa77240cceaae | |
parent | 7e30b67bf4eaad4288ba76ee7143ee0e9085777f (diff) | |
download | cpython-10288e19bf09ae79923794ed50da60af7eb5e3a1.zip cpython-10288e19bf09ae79923794ed50da60af7eb5e3a1.tar.gz cpython-10288e19bf09ae79923794ed50da60af7eb5e3a1.tar.bz2 |
Bug 3228: take a test from Niels Gustaebel's patch, and based on his patch, check for having os.stat available
-rw-r--r-- | Lib/test/test_mailbox.py | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py index a6494dc..bec51e5 100644 --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -716,10 +716,32 @@ class TestMaildir(TestMailbox): for msg in self._box: pass - def test_file_perms(self): + def test_file_permissions(self): + # Verify that message files are created without execute permissions + if not hasattr(os, "stat") or not hasattr(os, "umask"): + return + msg = mailbox.MaildirMessage(self._template % 0) + orig_umask = os.umask(0) + try: + key = self._box.add(msg) + finally: + os.umask(orig_umask) + path = os.path.join(self._path, self._box._lookup(key)) + mode = os.stat(path).st_mode + self.assert_(mode & 0111 == 0) + + def test_folder_file_perms(self): # From bug #3228, we want to verify that the file created inside a Maildir # subfolder isn't marked as executable. - subfolder = self._box.add_folder('subfolder') + if not hasattr(os, "stat") or not hasattr(os, "umask"): + return + + orig_umask = os.umask(0) + try: + subfolder = self._box.add_folder('subfolder') + finally: + os.umask(orig_umask) + path = os.path.join(subfolder._path, 'maildirfolder') st = os.stat(path) perms = st.st_mode @@ -823,7 +845,7 @@ class TestMbox(_TestMboxMMDF): # From bug #3228, we want to verify that the mailbox file isn't executable, # even if the umask is set to something that would leave executable bits set. # We only run this test on platforms that support umask. - if hasattr(os, 'umask'): + if hasattr(os, 'umask') and hasattr(os, 'stat'): try: old_umask = os.umask(0077) self._box.close() @@ -831,12 +853,13 @@ class TestMbox(_TestMboxMMDF): self._box = mailbox.mbox(self._path, create=True) self._box.add('') self._box.close() - st = os.stat(self._path) - perms = st.st_mode - self.assertFalse((perms & 0111)) # Execute bits should all be off. finally: os.umask(old_umask) + st = os.stat(self._path) + perms = st.st_mode + self.assertFalse((perms & 0111)) # Execute bits should all be off. + class TestMMDF(_TestMboxMMDF): _factory = lambda self, path, factory=None: mailbox.MMDF(path, factory) |