MCPcopy Create free account
hub / github.com/EasyIME/PIME / test_close_file_object

Method test_close_file_object

python/python3/tornado/test/ioloop_test.py:257–282  ·  view source on GitHub ↗

When a file object is used instead of a numeric file descriptor, the object should be closed (by IOLoop.close(all_fds=True), not just the fd.

(self)

Source from the content-addressed store, hash-verified

255 self.io_loop.remove_timeout(handle)
256
257 def test_close_file_object(self):
258 """When a file object is used instead of a numeric file descriptor,
259 the object should be closed (by IOLoop.close(all_fds=True),
260 not just the fd.
261 """
262 # Use a socket since they are supported by IOLoop on all platforms.
263 # Unfortunately, sockets don't support the .closed attribute for
264 # inspecting their close status, so we must use a wrapper.
265 class SocketWrapper(object):
266 def __init__(self, sockobj):
267 self.sockobj = sockobj
268 self.closed = False
269
270 def fileno(self):
271 return self.sockobj.fileno()
272
273 def close(self):
274 self.closed = True
275 self.sockobj.close()
276
277 sockobj, port = bind_unused_port()
278 socket_wrapper = SocketWrapper(sockobj)
279 io_loop = IOLoop()
280 io_loop.add_handler(socket_wrapper, lambda fd, events: None, IOLoop.READ)
281 io_loop.close(all_fds=True)
282 self.assertTrue(socket_wrapper.closed)
283
284 def test_handler_callback_file_object(self):
285 """The handler callback receives the same fd object it passed in."""

Callers

nothing calls this directly

Calls 5

add_handlerMethod · 0.95
closeMethod · 0.95
bind_unused_portFunction · 0.90
IOLoopClass · 0.90
SocketWrapperClass · 0.85

Tested by

no test coverage detected