]> granicus.if.org Git - python/commitdiff
Test protection against picling to/from closed (real) file.
authorGuido van Rossum <guido@python.org>
Mon, 29 Mar 1999 19:59:32 +0000 (19:59 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 29 Mar 1999 19:59:32 +0000 (19:59 +0000)
Lib/test/test_cpickle.py

index bedb321fb8f64c06d952401d9fc5a9b02bb7763c..90326f78dd88b53b826591b08f42a5bc9a580b9d 100644 (file)
@@ -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()