Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74ce77f

Browse files
committed
Add tests for the recent resource module change.
Also add a test that Python doesn't die with SIGXFSZ if it exceeds the file rlimit. (Assuming this will also test the behavior when the 2GB limit is exceed on a platform that doesn't have large file support.)
1 parent d95efe4 commit 74ce77f

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

Lib/test/output/test_resource

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test_resource
2+
True

Lib/test/test_resource.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os
2+
import resource
3+
4+
from test_support import TESTFN
5+
6+
# This test is checking a few specific problem spots. RLIMIT_FSIZE
7+
# should be RLIM_INFINITY, which will be a really big number on a
8+
# platform with large file support. On these platforms, we need to
9+
# test that the get/setrlimit functions properly convert the number to
10+
# a C long long and that the conversion doesn't raise an error.
11+
12+
try:
13+
cur, max = resource.getrlimit(resource.RLIMIT_FSIZE)
14+
except AttributeError:
15+
pass
16+
else:
17+
print resource.RLIM_INFINITY == max
18+
resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
19+
20+
# Now check to see what happens when the RLIMIT_FSIZE is small. Some
21+
# versions of Python were terminated by an uncaught SIGXFSZ, but
22+
# pythonrun.c has been fixed to ignore that exception. If so, the
23+
# write() should return EFBIG when the limit is exceeded.
24+
25+
try:
26+
resource.setrlimit(resource.RLIMIT_FSIZE, (1024, max))
27+
f = open(TESTFN, "wb")
28+
f.write("X" * 1024)
29+
try:
30+
f.write("Y")
31+
f.flush()
32+
except IOError:
33+
pass
34+
f.close()
35+
os.unlink(TESTFN)
36+
finally:
37+
resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
38+
39+
# And be sure that setrlimit is checking for really large values
40+
too_big = 10L**50
41+
try:
42+
resource.setrlimit(resource.RLIMIT_FSIZE, (too_big, max))
43+
except OverflowError:
44+
pass
45+
try:
46+
resource.setrlimit(resource.RLIMIT_FSIZE, (max, too_big))
47+
except OverflowError:
48+
pass

0 commit comments

Comments
 (0)