From: Guido van Rossum Date: Mon, 29 Mar 1999 19:59:32 +0000 (+0000) Subject: Test protection against picling to/from closed (real) file. X-Git-Tag: v1.5.2c1~57 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=89ae2b9f071cb78322fd1df1571027cd7159a698;p=python Test protection against picling to/from closed (real) file. --- diff --git a/Lib/test/test_cpickle.py b/Lib/test/test_cpickle.py index bedb321fb8..90326f78dd 100644 --- a/Lib/test/test_cpickle.py +++ b/Lib/test/test_cpickle.py @@ -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()