diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2002-01-01 19:11:13 +0000 |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2002-01-01 19:11:13 +0000 |
commit | 58585eaeaf11a61f8509531cf5ee62e9e4f2d6c1 (patch) | |
tree | 58ea5c9fd7099ae8fff4c06210ed666015cba480 | |
parent | dbcc2486cf6a14f670b4666a125708ce5553a55e (diff) | |
download | cpython-58585eaeaf11a61f8509531cf5ee62e9e4f2d6c1.tar.gz |
SF Patch #494867 test file methods
Test that the file methods raise ValueError when called on a closed file.
Test .isatty()
Test name, closed attributes
-rw-r--r-- | Lib/test/test_file.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py index 931e33db36..c00874d390 100644 --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -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) |