[Python-checkins] r65536 - python/trunk/Lib/test/test_mailbox.py

andrew.kuchling python-checkins at python.org
Tue Aug 5 03:00:57 CEST 2008


Author: andrew.kuchling
Date: Tue Aug  5 03:00:57 2008
New Revision: 65536

Log:
Bug 3228: take a test from Niels Gustaebel's patch, and based on his patch, check for having os.stat available

Modified:
   python/trunk/Lib/test/test_mailbox.py

Modified: python/trunk/Lib/test/test_mailbox.py
==============================================================================
--- python/trunk/Lib/test/test_mailbox.py	(original)
+++ python/trunk/Lib/test/test_mailbox.py	Tue Aug  5 03:00:57 2008
@@ -716,10 +716,32 @@
         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 @@
         # 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 @@
                 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)


More information about the Python-checkins mailing list