summaryrefslogtreecommitdiff
path: root/Lib/test/test_file.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-02-23 15:11:18 +0000
committerGeorg Brandl <georg@python.org>2008-02-23 15:11:18 +0000
commitad61bc8d9bb3839341ee99b2befc6760c44179d4 (patch)
tree1bd20fb6edd43434908162a4a4966bc61ed33f3d /Lib/test/test_file.py
parent7e251e83d5b488904212f91bace1322d12475803 (diff)
downloadcpython-git-ad61bc8d9bb3839341ee99b2befc6760c44179d4.tar.gz
#2067: file.__exit__() now calls subclasses' close() method.
Diffstat (limited to 'Lib/test/test_file.py')
-rw-r--r--Lib/test/test_file.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py
index 73cb5b2412..3ae460c976 100644
--- a/Lib/test/test_file.py
+++ b/Lib/test/test_file.py
@@ -322,12 +322,28 @@ class OtherFileTests(unittest.TestCase):
finally:
os.unlink(TESTFN)
+class FileSubclassTests(unittest.TestCase):
+
+ def testExit(self):
+ # test that exiting with context calls subclass' close
+ class C(file):
+ def __init__(self, *args):
+ self.subclass_closed = False
+ file.__init__(self, *args)
+ def close(self):
+ self.subclass_closed = True
+ file.close(self)
+
+ with C(TESTFN, 'w') as f:
+ pass
+ self.failUnless(f.subclass_closed)
+
def test_main():
# Historically, these tests have been sloppy about removing TESTFN.
# So get rid of it no matter what.
try:
- run_unittest(AutoFileTests, OtherFileTests)
+ run_unittest(AutoFileTests, OtherFileTests, FileSubclassTests)
finally:
if os.path.exists(TESTFN):
os.unlink(TESTFN)