[Python-checkins] r46792 - python/trunk/Lib/test/test_file.py

georg.brandl python-checkins at python.org
Fri Jun 9 20:29:52 CEST 2006


Author: georg.brandl
Date: Fri Jun  9 20:29:52 2006
New Revision: 46792

Modified:
   python/trunk/Lib/test/test_file.py
Log:
Test file.__exit__.



Modified: python/trunk/Lib/test/test_file.py
==============================================================================
--- python/trunk/Lib/test/test_file.py	(original)
+++ python/trunk/Lib/test/test_file.py	Fri Jun  9 20:29:52 2006
@@ -98,7 +98,9 @@
         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 @@
             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):
 


More information about the Python-checkins mailing list