]> granicus.if.org Git - python/commitdiff
Try to get rid of spurious failure in test_resource on the Debian buildbots by changi...
authorNick Coghlan <ncoghlan@gmail.com>
Tue, 24 Jul 2007 14:39:23 +0000 (14:39 +0000)
committerNick Coghlan <ncoghlan@gmail.com>
Tue, 24 Jul 2007 14:39:23 +0000 (14:39 +0000)
Lib/test/test_resource.py

index d1fd230ba8aa3083a3e29c1c2f91073ec00f048b..16e360f1a8bf91c302ddc8412d8e49281f066eb2 100644 (file)
@@ -49,17 +49,24 @@ class ResourceTest(unittest.TestCase):
                 except ValueError:
                     limit_set = False
                 f = open(test_support.TESTFN, "wb")
-                f.write("X" * 1024)
                 try:
-                    f.write("Y")
-                    f.flush()
-                except IOError:
-                    if not limit_set:
-                        raise
-                f.close()
-                os.unlink(test_support.TESTFN)
+                    f.write("X" * 1024)
+                    try:
+                        f.write("Y")
+                        f.flush()
+                    except IOError:
+                        if not limit_set:
+                            raise
+                    if limit_set:
+                        # Close will attempt to flush the byte we wrote
+                        # Restore limit first to avoid getting a spurious error
+                        resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
+                finally:
+                    f.close()
+                    os.unlink(test_support.TESTFN)
             finally:
-                resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
+                if limit_set:
+                    resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
 
     def test_fsize_toobig(self):
         # Be sure that setrlimit is checking for really large values