Kaydet (Commit) 556c7355 authored tarafından Benjamin Peterson's avatar Benjamin Peterson

use addCleanup

üst ebe5d8ae
...@@ -2541,24 +2541,24 @@ class MiscIOTest(unittest.TestCase): ...@@ -2541,24 +2541,24 @@ class MiscIOTest(unittest.TestCase):
def _check_warn_on_dealloc_fd(self, *args, **kwargs): def _check_warn_on_dealloc_fd(self, *args, **kwargs):
fds = [] fds = []
try: def cleanup_fds():
r, w = os.pipe()
fds += r, w
self._check_warn_on_dealloc(r, *args, **kwargs)
# When using closefd=False, there's no warning
r, w = os.pipe()
fds += r, w
with warnings.catch_warnings(record=True) as recorded:
open(r, *args, closefd=False, **kwargs)
support.gc_collect()
self.assertEqual(recorded, [])
finally:
for fd in fds: for fd in fds:
try: try:
os.close(fd) os.close(fd)
except EnvironmentError as e: except EnvironmentError as e:
if e.errno != errno.EBADF: if e.errno != errno.EBADF:
raise raise
self.addCleanup(cleanup_fds)
r, w = os.pipe()
fds += r, w
self._check_warn_on_dealloc(r, *args, **kwargs)
# When using closefd=False, there's no warning
r, w = os.pipe()
fds += r, w
with warnings.catch_warnings(record=True) as recorded:
open(r, *args, closefd=False, **kwargs)
support.gc_collect()
self.assertEqual(recorded, [])
def test_warn_on_dealloc_fd(self): def test_warn_on_dealloc_fd(self):
self._check_warn_on_dealloc_fd("rb", buffering=0) self._check_warn_on_dealloc_fd("rb", buffering=0)
......
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