summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_mailbox.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2011-06-17 16:56:41 (GMT)
committerR David Murray <rdmurray@bitdance.com>2011-06-17 16:56:41 (GMT)
commit4c7d21e2b3207d2123949c10d139520c9d19adb1 (patch)
tree6b2ee4d46a74617fea03084e063e52ccea5a1e18 /Lib/test/test_mailbox.py
parent92cafb85dd3143baa7016475b3895f5491fe451f (diff)
parent05ff9904010a488cc640637ac8255cae41b270dd (diff)
downloadcpython-4c7d21e2b3207d2123949c10d139520c9d19adb1.zip
cpython-4c7d21e2b3207d2123949c10d139520c9d19adb1.tar.gz
cpython-4c7d21e2b3207d2123949c10d139520c9d19adb1.tar.bz2
merge #11767: use context manager to close file in __getitem__ to prevent FD leak
Diffstat (limited to 'Lib/test/test_mailbox.py')
-rw-r--r--Lib/test/test_mailbox.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index e462fe3..f5abb41 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -1201,6 +1201,37 @@ class TestBabyl(TestMailbox):
self.assertEqual(set(self._box.get_labels()), set(['blah']))
+class FakeFileLikeObject:
+
+ def __init__(self):
+ self.closed = False
+
+ def close(self):
+ self.closed = True
+
+
+class FakeMailBox(mailbox.Mailbox):
+
+ def __init__(self):
+ mailbox.Mailbox.__init__(self, '', lambda file: None)
+ self.files = [FakeFileLikeObject() for i in range(10)]
+
+ def get_file(self, key):
+ return self.files[key]
+
+
+class TestFakeMailBox(unittest.TestCase):
+
+ def test_closing_fd(self):
+ box = FakeMailBox()
+ for i in range(10):
+ self.assertFalse(box.files[i].closed)
+ for i in range(10):
+ box[i]
+ for i in range(10):
+ self.assertTrue(box.files[i].closed)
+
+
class TestMessage(TestBase):
_factory = mailbox.Message # Overridden by subclasses to reuse tests
@@ -2113,7 +2144,7 @@ def test_main():
TestBabyl, TestMessage, TestMaildirMessage, TestMboxMessage,
TestMHMessage, TestBabylMessage, TestMMDFMessage,
TestMessageConversion, TestProxyFile, TestPartialFile,
- MaildirTestCase)
+ MaildirTestCase, TestFakeMailBox)
support.run_unittest(*tests)
support.reap_children()