Kaydet (Commit) e7ec81f1 authored tarafından Georg Brandl's avatar Georg Brandl

Test file.__exit__.

üst 982c30b8
...@@ -98,7 +98,9 @@ class AutoFileTests(unittest.TestCase): ...@@ -98,7 +98,9 @@ class AutoFileTests(unittest.TestCase):
if sys.platform.startswith('atheos'): if sys.platform.startswith('atheos'):
methods.remove('truncate') 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: for methodname in methods:
method = getattr(self.f, methodname) method = getattr(self.f, methodname)
...@@ -106,6 +108,14 @@ class AutoFileTests(unittest.TestCase): ...@@ -106,6 +108,14 @@ class AutoFileTests(unittest.TestCase):
self.assertRaises(ValueError, method) self.assertRaises(ValueError, method)
self.assertRaises(ValueError, self.f.writelines, []) 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): class OtherFileTests(unittest.TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment