@@ -58,17 +58,10 @@ def test_fsize_enforced(self):
5858 if max_lim != resource .RLIM_INFINITY and max_lim < 1025 :
5959 self .skipTest (f"system RLIMIT_FSIZE hard limit ({ max_lim } ) is too small for this test" )
6060
61- try :
62- resource .setrlimit (resource .RLIMIT_FSIZE , (1024 , max_lim ))
63- resource .setrlimit (resource .RLIMIT_FSIZE , (cur , max_lim ))
64- except (ValueError , OSError , PermissionError ) as e :
65- self .skipTest (f"cannot set RLIMIT_FSIZE to 1024: { e } " )
66-
67- self .addCleanup (os_helper .unlink , os_helper .TESTFN )
68- self .addCleanup (resource .setrlimit , resource .RLIMIT_FSIZE , (cur , max_lim ))
69- resource .setrlimit (resource .RLIMIT_FSIZE , (1024 , max_lim ))
7061 try :
7162 with open (os_helper .TESTFN , "wb" ) as f :
63+ resource .setrlimit (resource .RLIMIT_FSIZE , (1024 , max_lim ))
64+
7265 f .write (b"X" * 1024 )
7366 # This should raise OSError because it exceeds the 1024 byte limit
7467 with self .assertRaises (OSError , msg = "f.write() did not raise OSError when exceeding RLIMIT_FSIZE" ):
@@ -83,9 +76,8 @@ def test_fsize_enforced(self):
8376 time .sleep (.1 )
8477 f .flush ()
8578 finally :
86- # Restore limit after the file is closed by the 'with' block
8779 resource .setrlimit (resource .RLIMIT_FSIZE , (cur , max_lim ))
88-
80+
8981 @unittest .skipIf (sys .platform == "vxworks" ,
9082 "setting RLIMIT_FSIZE is not supported on VxWorks" )
9183 @unittest .skipUnless (hasattr (resource , 'RLIMIT_FSIZE' ), 'requires resource.RLIMIT_FSIZE' )
0 commit comments