diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-06-27 21:57:19 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-06-27 21:57:19 (GMT) |
commit | a81088ae129f251ad4d1c2cb208ffd2e8d52ea4a (patch) | |
tree | 15831806e742293faad56b1b3c880d1293cf2a4c /Lib/test/test_asyncore.py | |
parent | c3bc856f426d8c182b4ecbdf584717e27389c505 (diff) | |
parent | 4d4c69dc35154a9c21fed1b6b4088e741fbc6ae6 (diff) | |
download | cpython-a81088ae129f251ad4d1c2cb208ffd2e8d52ea4a.zip cpython-a81088ae129f251ad4d1c2cb208ffd2e8d52ea4a.tar.gz cpython-a81088ae129f251ad4d1c2cb208ffd2e8d52ea4a.tar.bz2 |
(Merge 3.4) Issue #11453: asyncore: emit a ResourceWarning when an unclosed
file_wrapper object is destroyed. The destructor now closes the file if needed.
The close() method can now be called twice: the second call does nothing.
Diffstat (limited to 'Lib/test/test_asyncore.py')
-rw-r--r-- | Lib/test/test_asyncore.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py index ef02c33..b4f474f 100644 --- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -413,6 +413,22 @@ class FileWrapperTest(unittest.TestCase): asyncore.loop(timeout=0.01, use_poll=True, count=2) self.assertEqual(b"".join(data), self.d) + def test_resource_warning(self): + # Issue #11453 + fd = os.open(support.TESTFN, os.O_RDONLY) + f = asyncore.file_wrapper(fd) + with support.check_warnings(('', ResourceWarning)): + f = None + support.gc_collect() + + def test_close_twice(self): + fd = os.open(support.TESTFN, os.O_RDONLY) + f = asyncore.file_wrapper(fd) + f.close() + self.assertEqual(f.fd, -1) + # calling close twice should not fail + f.close() + class BaseTestHandler(asyncore.dispatcher): |