From: Georg Brandl Date: Fri, 9 Jun 2006 18:29:52 +0000 (+0000) Subject: Test file.__exit__. X-Git-Tag: v2.5b1~173 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e7ec81f130882b95b76a9aa74fe0dcb24ff15feb;p=thirdparty%2FPython%2Fcpython.git Test file.__exit__. --- diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py index 4698936827e7..73cb5b241278 100644 --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -98,7 +98,9 @@ class AutoFileTests(unittest.TestCase): if sys.platform.startswith('atheos'): methods.remove('truncate') - self.f.close() + # __exit__ should close the file + self.f.__exit__(None, None, None) + self.assert_(self.f.closed) for methodname in methods: method = getattr(self.f, methodname) @@ -106,6 +108,14 @@ class AutoFileTests(unittest.TestCase): self.assertRaises(ValueError, method) self.assertRaises(ValueError, self.f.writelines, []) + # file is closed, __exit__ shouldn't do anything + self.assertEquals(self.f.__exit__(None, None, None), None) + # it must also return None if an exception was given + try: + 1/0 + except: + self.assertEquals(self.f.__exit__(*sys.exc_info()), None) + class OtherFileTests(unittest.TestCase):