mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Test protection against picling to/from closed (real) file.
This commit is contained in:
parent
4958f9af97
commit
89ae2b9f07
1 changed files with 20 additions and 0 deletions
|
@ -72,4 +72,24 @@ def dotest():
|
|||
if x2 == x: print "ok"
|
||||
else: print "bad"
|
||||
|
||||
# Test protection against closed files
|
||||
import tempfile, os
|
||||
fn = tempfile.mktemp()
|
||||
f = open(fn, "w")
|
||||
f.close()
|
||||
try:
|
||||
cPickle.dump(123, f)
|
||||
except IOError:
|
||||
pass
|
||||
else:
|
||||
print "dump to closed file should raise IOError"
|
||||
f = open(fn, "r")
|
||||
f.close()
|
||||
try:
|
||||
cPickle.load(f)
|
||||
except IOError:
|
||||
pass
|
||||
else:
|
||||
print "load from closed file should raise IOError"
|
||||
|
||||
dotest()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue