summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-06-09 18:29:52 (GMT)
committerGeorg Brandl <georg@python.org>2006-06-09 18:29:52 (GMT)
commite7ec81f130882b95b76a9aa74fe0dcb24ff15feb (patch)
tree533b4f6e6814a95922f198f68ce5daeb3b1ab51d /Lib
parent982c30b861837b2a3dcadd1d839d1290910e93f7 (diff)
downloadcpython-e7ec81f130882b95b76a9aa74fe0dcb24ff15feb.zip
cpython-e7ec81f130882b95b76a9aa74fe0dcb24ff15feb.tar.gz
cpython-e7ec81f130882b95b76a9aa74fe0dcb24ff15feb.tar.bz2
Test file.__exit__.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_file.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py
index 4698936..73cb5b2 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):