MCPcopy Index your code
hub / github.com/RustPython/RustPython / _setup

Method _setup

Lib/test/test_imaplib.py:275–306  ·  view source on GitHub ↗

Sets up imap_handler for tests. imap_handler should inherit from either: - SimpleIMAPHandler - for testing IMAP commands, - socketserver.StreamRequestHandler - if raw access to stream is needed. Returns (client, server).

(self, imap_handler, connect=True)

Source from the content-addressed store, hash-verified

273 client = None
274
275 def _setup(self, imap_handler, connect=True):
276 """
277 Sets up imap_handler for tests. imap_handler should inherit from either:
278 - SimpleIMAPHandler - for testing IMAP commands,
279 - socketserver.StreamRequestHandler - if raw access to stream is needed.
280 Returns (client, server).
281 """
282 class TestTCPServer(self.server_class):
283 def handle_error(self, request, client_address):
284 """
285 End request and raise the error if one occurs.
286 """
287 self.close_request(request)
288 self.server_close()
289 raise
290
291 self.addCleanup(self._cleanup)
292 self.server = self.server_class((socket_helper.HOST, 0), imap_handler)
293 self.thread = threading.Thread(
294 name=self._testMethodName+'-server',
295 target=self.server.serve_forever,
296 # Short poll interval to make the test finish quickly.
297 # Time between requests is short enough that we won't wake
298 # up spuriously too many times.
299 kwargs={'poll_interval': 0.01})
300 self.thread.daemon = True # In case this function raises.
301 self.thread.start()
302
303 if connect:
304 self.client = self.imap_class(*self.server.server_address)
305
306 return self.client, self.server
307
308 def _cleanup(self):
309 """

Calls 2

addCleanupMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected