/
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/asyncio_test.py
(7329B)
# 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. import asyncio import unittest from concurrent.futures import ThreadPoolExecutor from tornado import gen from tornado.ioloop import IOLoop from tornado.platform.asyncio import ( AsyncIOLoop, to_asyncio_future, AnyThreadEventLoopPolicy, ) from tornado.testing import AsyncTestCase, gen_test class AsyncIOLoopTest(AsyncTestCase): def get_new_ioloop(self): io_loop = AsyncIOLoop() return io_loop def test_asyncio_callback(self): # Basic test that the asyncio loop is set up correctly. asyncio.get_event_loop().call_soon(self.stop) self.wait() @gen_test def test_asyncio_future(self): # Test that we can yield an asyncio future from a tornado coroutine. # Without 'yield from', we must wrap coroutines in ensure_future, # which was introduced during Python 3.4, deprecating the prior "async". if hasattr(asyncio, "ensure_future"): ensure_future = asyncio.ensure_future else: # async is a reserved word in Python 3.7 ensure_future = getattr(asyncio, "async") x = yield ensure_future( asyncio.get_event_loop().run_in_executor(None, lambda: 42) ) self.assertEqual(x, 42) @gen_test def test_asyncio_yield_from(self): @gen.coroutine def f(): event_loop = asyncio.get_event_loop() x = yield from event_loop.run_in_executor(None, lambda: 42) return x result = yield f() self.assertEqual(result, 42) def test_asyncio_adapter(self): # This test demonstrates that when using the asyncio coroutine # runner (i.e. run_until_complete), the to_asyncio_future # adapter is needed. No adapter is needed in the other direction, # as demonstrated by other tests in the package. @gen.coroutine def tornado_coroutine(): yield gen.moment raise gen.Return(42) async def native_coroutine_without_adapter(): return await tornado_coroutine() async def native_coroutine_with_adapter(): return await to_asyncio_future(tornado_coroutine()) # Use the adapter, but two degrees from the tornado coroutine. async def native_coroutine_with_adapter2(): return await to_asyncio_future(native_coroutine_without_adapter()) # Tornado supports native coroutines both with and without adapters self.assertEqual(self.io_loop.run_sync(native_coroutine_without_adapter), 42) self.assertEqual(self.io_loop.run_sync(native_coroutine_with_adapter), 42) self.assertEqual(self.io_loop.run_sync(native_coroutine_with_adapter2), 42) # Asyncio only supports coroutines that yield asyncio-compatible # Futures (which our Future is since 5.0). self.assertEqual( asyncio.get_event_loop().run_until_complete( native_coroutine_without_adapter() ), 42, ) self.assertEqual( asyncio.get_event_loop().run_until_complete( native_coroutine_with_adapter() ), 42, ) self.assertEqual( asyncio.get_event_loop().run_until_complete( native_coroutine_with_adapter2() ), 42, ) class LeakTest(unittest.TestCase): def setUp(self): # Trigger a cleanup of the mapping so we start with a clean slate. AsyncIOLoop().close() # If we don't clean up after ourselves other tests may fail on # py34. self.orig_policy = asyncio.get_event_loop_policy() asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy()) def tearDown(self): asyncio.get_event_loop().close() asyncio.set_event_loop_policy(self.orig_policy) def test_ioloop_close_leak(self): orig_count = len(IOLoop._ioloop_for_asyncio) for i in range(10): # Create and close an AsyncIOLoop using Tornado interfaces. loop = AsyncIOLoop() loop.close() new_count = len(IOLoop._ioloop_for_asyncio) - orig_count self.assertEqual(new_count, 0) def test_asyncio_close_leak(self): orig_count = len(IOLoop._ioloop_for_asyncio) for i in range(10): # Create and close an AsyncIOMainLoop using asyncio interfaces. loop = asyncio.new_event_loop() loop.call_soon(IOLoop.current) loop.call_soon(loop.stop) loop.run_forever() loop.close() new_count = len(IOLoop._ioloop_for_asyncio) - orig_count # Because the cleanup is run on new loop creation, we have one # dangling entry in the map (but only one). self.assertEqual(new_count, 1) class AnyThreadEventLoopPolicyTest(unittest.TestCase): def setUp(self): self.orig_policy = asyncio.get_event_loop_policy() self.executor = ThreadPoolExecutor(1) def tearDown(self): asyncio.set_event_loop_policy(self.orig_policy) self.executor.shutdown() def get_event_loop_on_thread(self): def get_and_close_event_loop(): """Get the event loop. Close it if one is returned. Returns the (closed) event loop. This is a silly thing to do and leaves the thread in a broken state, but it's enough for this test. Closing the loop avoids resource leak warnings. """ loop = asyncio.get_event_loop() loop.close() return loop future = self.executor.submit(get_and_close_event_loop) return future.result() def run_policy_test(self, accessor, expected_type): # With the default policy, non-main threads don't get an event # loop. self.assertRaises( (RuntimeError, AssertionError), self.executor.submit(accessor).result ) # Set the policy and we can get a loop. asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy()) self.assertIsInstance(self.executor.submit(accessor).result(), expected_type) # Clean up to silence leak warnings. Always use asyncio since # IOLoop doesn't (currently) close the underlying loop. self.executor.submit(lambda: asyncio.get_event_loop().close()).result() def test_asyncio_accessor(self): self.run_policy_test(asyncio.get_event_loop, asyncio.AbstractEventLoop) def test_tornado_accessor(self): self.run_policy_test(IOLoop.current, IOLoop)
Save
cmd:
run