/
opt
/
imh-python
/
lib
/
python3.9
/
site-packages
/
tornado
/
test
/
/opt/imh-python/lib/python3.9/site-packages/tornado/test
mkdir
upload
Name
Size
Mode
Actions
csv_translations/
-
0755
rm
gettext_translations/
-
0755
rm
static/
-
0755
rm
templates/
-
0755
rm
__pycache__/
-
0755
rm
asyncio_test.py
7329
0644
edit
dl
rm
auth_test.py
24026
0644
edit
dl
rm
autoreload_test.py
4075
0644
edit
dl
rm
concurrent_test.py
6174
0644
edit
dl
rm
curl_httpclient_test.py
4477
0644
edit
dl
rm
escape_test.py
12694
0644
edit
dl
rm
gen_test.py
34721
0644
edit
dl
rm
http1connection_test.py
1972
0644
edit
dl
rm
httpclient_test.py
32067
0644
edit
dl
rm
httpserver_test.py
46332
0644
edit
dl
rm
httputil_test.py
19600
0644
edit
dl
rm
import_test.py
2046
0644
edit
dl
rm
ioloop_test.py
26060
0644
edit
dl
rm
iostream_test.py
46178
0644
edit
dl
rm
locale_test.py
5907
0644
edit
dl
rm
locks_test.py
17564
0644
edit
dl
rm
log_test.py
9778
0644
edit
dl
rm
netutil_test.py
8047
0644
edit
dl
rm
options_test.cfg
76
0644
edit
dl
rm
options_test.py
12174
0644
edit
dl
rm
options_test_types.cfg
277
0644
edit
dl
rm
options_test_types_str.cfg
158
0644
edit
dl
rm
process_test.py
11392
0644
edit
dl
rm
queues_test.py
14188
0644
edit
dl
rm
resolve_test_helper.py
421
0644
edit
dl
rm
routing_test.py
9121
0644
edit
dl
rm
runtests.py
8440
0644
edit
dl
rm
simple_httpclient_test.py
31821
0644
edit
dl
rm
static_foo.txt
97
0644
edit
dl
rm
tcpclient_test.py
17115
0644
edit
dl
rm
tcpserver_test.py
6674
0644
edit
dl
rm
template_test.py
19204
0644
edit
dl
rm
test.crt
1244
0644
edit
dl
rm
test.key
1732
0644
edit
dl
rm
testing_test.py
10985
0644
edit
dl
rm
twisted_test.py
8116
0644
edit
dl
rm
util.py
3768
0644
edit
dl
rm
util_test.py
10127
0644
edit
dl
rm
websocket_test.py
28331
0644
edit
dl
rm
web_test.py
118423
0644
edit
dl
rm
windows_test.py
698
0644
edit
dl
rm
wsgi_test.py
677
0644
edit
dl
rm
__init__.py
398
0644
edit
dl
rm
__main__.py
347
0644
edit
dl
rm
Edit:
/opt/imh-python/lib/python3.9/site-packages/tornado/test/concurrent_test.py
(6174B)
# # Copyright 2012 Facebook # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from concurrent import futures import logging import re import socket import unittest from tornado.concurrent import ( Future, run_on_executor, future_set_result_unless_cancelled, ) from tornado.escape import utf8, to_unicode from tornado import gen from tornado.iostream import IOStream from tornado.tcpserver import TCPServer from tornado.testing import AsyncTestCase, bind_unused_port, gen_test class MiscFutureTest(AsyncTestCase): def test_future_set_result_unless_cancelled(self): fut = Future() # type: Future[int] future_set_result_unless_cancelled(fut, 42) self.assertEqual(fut.result(), 42) self.assertFalse(fut.cancelled()) fut = Future() fut.cancel() is_cancelled = fut.cancelled() future_set_result_unless_cancelled(fut, 42) self.assertEqual(fut.cancelled(), is_cancelled) if not is_cancelled: self.assertEqual(fut.result(), 42) # The following series of classes demonstrate and test various styles # of use, with and without generators and futures. class CapServer(TCPServer): @gen.coroutine def handle_stream(self, stream, address): data = yield stream.read_until(b"\n") data = to_unicode(data) if data == data.upper(): stream.write(b"error\talready capitalized\n") else: # data already has \n stream.write(utf8("ok\t%s" % data.upper())) stream.close() class CapError(Exception): pass class BaseCapClient(object): def __init__(self, port): self.port = port def process_response(self, data): m = re.match("(.*)\t(.*)\n", to_unicode(data)) if m is None: raise Exception("did not match") status, message = m.groups() if status == "ok": return message else: raise CapError(message) class GeneratorCapClient(BaseCapClient): @gen.coroutine def capitalize(self, request_data): logging.debug("capitalize") stream = IOStream(socket.socket()) logging.debug("connecting") yield stream.connect(("127.0.0.1", self.port)) stream.write(utf8(request_data + "\n")) logging.debug("reading") data = yield stream.read_until(b"\n") logging.debug("returning") stream.close() raise gen.Return(self.process_response(data)) class ClientTestMixin(object): def setUp(self): super(ClientTestMixin, self).setUp() # type: ignore self.server = CapServer() sock, port = bind_unused_port() self.server.add_sockets([sock]) self.client = self.client_class(port=port) def tearDown(self): self.server.stop() super(ClientTestMixin, self).tearDown() # type: ignore def test_future(self): future = self.client.capitalize("hello") self.io_loop.add_future(future, self.stop) self.wait() self.assertEqual(future.result(), "HELLO") def test_future_error(self): future = self.client.capitalize("HELLO") self.io_loop.add_future(future, self.stop) self.wait() self.assertRaisesRegexp(CapError, "already capitalized", future.result) def test_generator(self): @gen.coroutine def f(): result = yield self.client.capitalize("hello") self.assertEqual(result, "HELLO") self.io_loop.run_sync(f) def test_generator_error(self): @gen.coroutine def f(): with self.assertRaisesRegexp(CapError, "already capitalized"): yield self.client.capitalize("HELLO") self.io_loop.run_sync(f) class GeneratorClientTest(ClientTestMixin, AsyncTestCase): client_class = GeneratorCapClient class RunOnExecutorTest(AsyncTestCase): @gen_test def test_no_calling(self): class Object(object): def __init__(self): self.executor = futures.thread.ThreadPoolExecutor(1) @run_on_executor def f(self): return 42 o = Object() answer = yield o.f() self.assertEqual(answer, 42) @gen_test def test_call_with_no_args(self): class Object(object): def __init__(self): self.executor = futures.thread.ThreadPoolExecutor(1) @run_on_executor() def f(self): return 42 o = Object() answer = yield o.f() self.assertEqual(answer, 42) @gen_test def test_call_with_executor(self): class Object(object): def __init__(self): self.__executor = futures.thread.ThreadPoolExecutor(1) @run_on_executor(executor="_Object__executor") def f(self): return 42 o = Object() answer = yield o.f() self.assertEqual(answer, 42) @gen_test def test_async_await(self): class Object(object): def __init__(self): self.executor = futures.thread.ThreadPoolExecutor(1) @run_on_executor() def f(self): return 42 o = Object() async def f(): answer = await o.f() return answer result = yield f() self.assertEqual(result, 42) if __name__ == "__main__": unittest.main()
Save
cmd:
run