/opt/imh-python/lib/python3.9/site-packages/tornado/test
NameSizeModeActions
csv_translations/-0755rm
gettext_translations/-0755rm
static/-0755rm
templates/-0755rm
__pycache__/-0755rm
asyncio_test.py73290644editdlrm
auth_test.py240260644editdlrm
autoreload_test.py40750644editdlrm
concurrent_test.py61740644editdlrm
curl_httpclient_test.py44770644editdlrm
escape_test.py126940644editdlrm
gen_test.py347210644editdlrm
http1connection_test.py19720644editdlrm
httpclient_test.py320670644editdlrm
httpserver_test.py463320644editdlrm
httputil_test.py196000644editdlrm
import_test.py20460644editdlrm
ioloop_test.py260600644editdlrm
iostream_test.py461780644editdlrm
locale_test.py59070644editdlrm
locks_test.py175640644editdlrm
log_test.py97780644editdlrm
netutil_test.py80470644editdlrm
options_test.cfg760644editdlrm
options_test.py121740644editdlrm
options_test_types.cfg2770644editdlrm
options_test_types_str.cfg1580644editdlrm
process_test.py113920644editdlrm
queues_test.py141880644editdlrm
resolve_test_helper.py4210644editdlrm
routing_test.py91210644editdlrm
runtests.py84400644editdlrm
simple_httpclient_test.py318210644editdlrm
static_foo.txt970644editdlrm
tcpclient_test.py171150644editdlrm
tcpserver_test.py66740644editdlrm
template_test.py192040644editdlrm
test.crt12440644editdlrm
test.key17320644editdlrm
testing_test.py109850644editdlrm
twisted_test.py81160644editdlrm
util.py37680644editdlrm
util_test.py101270644editdlrm
websocket_test.py283310644editdlrm
web_test.py1184230644editdlrm
windows_test.py6980644editdlrm
wsgi_test.py6770644editdlrm
__init__.py3980644editdlrm
__main__.py3470644editdlrm
Edit: /opt/imh-python/lib/python3.9/site-packages/tornado/test/tcpserver_test.py (6674B)
import socket import subprocess import sys import textwrap import unittest from tornado.escape import utf8, to_unicode from tornado import gen from tornado.iostream import IOStream from tornado.log import app_log from tornado.tcpserver import TCPServer from tornado.test.util import skipIfNonUnix from tornado.testing import AsyncTestCase, ExpectLog, bind_unused_port, gen_test class TCPServerTest(AsyncTestCase): @gen_test def test_handle_stream_coroutine_logging(self): # handle_stream may be a coroutine and any exception in its # Future will be logged. class TestServer(TCPServer): @gen.coroutine def handle_stream(self, stream, address): yield stream.read_bytes(len(b"hello")) stream.close() 1 / 0 server = client = None try: sock, port = bind_unused_port() server = TestServer() server.add_socket(sock) client = IOStream(socket.socket()) with ExpectLog(app_log, "Exception in callback"): yield client.connect(("localhost", port)) yield client.write(b"hello") yield client.read_until_close() yield gen.moment finally: if server is not None: server.stop() if client is not None: client.close() @gen_test def test_handle_stream_native_coroutine(self): # handle_stream may be a native coroutine. class TestServer(TCPServer): async def handle_stream(self, stream, address): stream.write(b"data") stream.close() sock, port = bind_unused_port() server = TestServer() server.add_socket(sock) client = IOStream(socket.socket()) yield client.connect(("localhost", port)) result = yield client.read_until_close() self.assertEqual(result, b"data") server.stop() client.close() def test_stop_twice(self): sock, port = bind_unused_port() server = TCPServer() server.add_socket(sock) server.stop() server.stop() @gen_test def test_stop_in_callback(self): # Issue #2069: calling server.stop() in a loop callback should not # raise EBADF when the loop handles other server connection # requests in the same loop iteration class TestServer(TCPServer): @gen.coroutine def handle_stream(self, stream, address): server.stop() # type: ignore yield stream.read_until_close() sock, port = bind_unused_port() server = TestServer() server.add_socket(sock) server_addr = ("localhost", port) N = 40 clients = [IOStream(socket.socket()) for i in range(N)] connected_clients = [] @gen.coroutine def connect(c): try: yield c.connect(server_addr) except EnvironmentError: pass else: connected_clients.append(c) yield [connect(c) for c in clients] self.assertGreater(len(connected_clients), 0, "all clients failed connecting") try: if len(connected_clients) == N: # Ideally we'd make the test deterministic, but we're testing # for a race condition in combination with the system's TCP stack... self.skipTest( "at least one client should fail connecting " "for the test to be meaningful" ) finally: for c in connected_clients: c.close() # Here tearDown() would re-raise the EBADF encountered in the IO loop @skipIfNonUnix class TestMultiprocess(unittest.TestCase): # These tests verify that the two multiprocess examples from the # TCPServer docs work. Both tests start a server with three worker # processes, each of which prints its task id to stdout (a single # byte, so we don't have to worry about atomicity of the shared # stdout stream) and then exits. def run_subproc(self, code): proc = subprocess.Popen( sys.executable, stdin=subprocess.PIPE, stdout=subprocess.PIPE ) proc.stdin.write(utf8(code)) proc.stdin.close() proc.wait() stdout = proc.stdout.read() proc.stdout.close() if proc.returncode != 0: raise RuntimeError( "Process returned %d. stdout=%r" % (proc.returncode, stdout) ) return to_unicode(stdout) def test_single(self): # As a sanity check, run the single-process version through this test # harness too. code = textwrap.dedent( """ from tornado.ioloop import IOLoop from tornado.tcpserver import TCPServer server = TCPServer() server.listen(0, address='127.0.0.1') IOLoop.current().run_sync(lambda: None) print('012', end='') """ ) out = self.run_subproc(code) self.assertEqual("".join(sorted(out)), "012") def test_simple(self): code = textwrap.dedent( """ from tornado.ioloop import IOLoop from tornado.process import task_id from tornado.tcpserver import TCPServer server = TCPServer() server.bind(0, address='127.0.0.1') server.start(3) IOLoop.current().run_sync(lambda: None) print(task_id(), end='') """ ) out = self.run_subproc(code) self.assertEqual("".join(sorted(out)), "012") def test_advanced(self): code = textwrap.dedent( """ from tornado.ioloop import IOLoop from tornado.netutil import bind_sockets from tornado.process import fork_processes, task_id from tornado.ioloop import IOLoop from tornado.tcpserver import TCPServer sockets = bind_sockets(0, address='127.0.0.1') fork_processes(3) server = TCPServer() server.add_sockets(sockets) IOLoop.current().run_sync(lambda: None) print(task_id(), end='') """ ) out = self.run_subproc(code) self.assertEqual("".join(sorted(out)), "012")