]> granicus.if.org Git - python/commitdiff
SF Patch #494867 test file methods
authorNeal Norwitz <nnorwitz@gmail.com>
Tue, 1 Jan 2002 19:11:13 +0000 (19:11 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Tue, 1 Jan 2002 19:11:13 +0000 (19:11 +0000)
Test that the file methods raise ValueError when called on a closed file.
Test .isatty()
Test name, closed attributes

Lib/test/test_file.py

index 931e33db36ea114648a42d949bdf8c30d349356a..c00874d390a71df7da7ed4ffed97001d4c15ea83 100644 (file)
@@ -60,4 +60,33 @@ except IOError, msg:
 else:
     print "no error for invalid mode: %s" % bad_mode
 
+f = open(TESTFN)
+if f.name != TESTFN:
+    raise TestError, 'file.name should be "%s"' % TESTFN
+if f.isatty():
+    raise TestError, 'file.isatty() should be false'
+
+if f.closed:
+    raise TestError, 'file.closed should be false'
+
+f.close()
+if not f.closed:
+    raise TestError, 'file.closed should be true'
+
+for methodname in ['fileno', 'flush', 'isatty', 'read', 'readinto', 'readline', 'readlines', 'seek', 'tell', 'truncate', 'write', 'xreadlines' ]:
+    method = getattr(f, methodname)
+    try:
+        method()
+    except ValueError:
+        pass
+    else:
+        raise TestError, 'file.%s() on a closed file should raise a ValueError' % methodname
+
+try:
+    f.writelines([])
+except ValueError:
+    pass
+else:
+    raise TestError, 'file.writelines([]) on a closed file should raise a ValueError'
+
 os.unlink(TESTFN)