File: //lib64/python3.6/site-packages/tornado/__pycache__/testing.cpython-36.pyc
3
��fs � @ s� d Z ddlZddlmZ ddlZddlZddlZddlZddlZddl Z ddl
Z
ddlZddlZddl
mZ ddlmZmZ ddlmZ ddlmZmZ ddl
mZ dd lmZ dd
lmZ ddlmZ ddlmZm Z dd
l!m"Z" ddl#Z#ddl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+m,Z, e#j-�rNddl#m.Z. e$e*e'e/ e*e/ e*e, f Z0eZ1d0e2e$e
j
e3f d�dd�Z4e5d�dd�Z6G dd� de7�Z8G dd� dej9�Z:G dd� de:�Z;G dd� de;�Z<e#j=dd �e5e&e&d!e)ed"f f ge&d1 f d#�d$d%��Z>e#j=e&d!e)ed"f f e&d2 d&�d'd%��Z>d3e&d!e)ed"f f e5e)e&d4 e&e&d!e)ed"f f ge&d5 f f d(�d)d%�Z>de>_?G d*d+� d+ej@�ZAe%dd,�d-d.�ZBeCd/k�r�eB� dS )6a� Support classes for automated testing.
* `AsyncTestCase` and `AsyncHTTPTestCase`: Subclasses of unittest.TestCase
with additional support for testing asynchronous (`.IOLoop`-based) code.
* `ExpectLog`: Make test logs less spammy.
* `main()`: A simple test runner (wrapper around unittest.main()) with support
for the tornado.autoreload module to rerun the tests when code changes.
� N)� Generator)�gen)�AsyncHTTPClient�HTTPResponse)�
HTTPServer)�IOLoop�TimeoutError)�netutil)�AsyncIOMainLoop)�
Subprocess)�app_log)�raise_exc_info�basestring_type)�Application)�Tuple�Any�Callable�Type�Dict�Union�Optional)�
TracebackType)� CoroutineF)�
reuse_port�returnc C s, t jddtj| d�d }|j� d }||fS )z�Binds a server socket to an available port on localhost.
Returns a tuple (socket, port).
.. versionchanged:: 4.4
Always binds to ``127.0.0.1`` without resolving the name
``localhost``.
r z 127.0.0.1)Zfamilyr � )r Zbind_sockets�socketZAF_INETZgetsockname)r �sock�port� r �/usr/lib64/python3.6/testing.py�bind_unused_port4 s
r! )r c C s6 t jjd�} | dk r2yt| �S tk
r0 Y nX dS )z}Get the global timeout setting for async tests.
Returns a float, the timeout in seconds.
.. versionadded:: 3.1
ZASYNC_TEST_TIMEOUTN� )�os�environ�get�float�
ValueError)�envr r r �get_async_test_timeoutD s r) c @ sB e Zd ZdZedd�dd�Zeedd�dd�Zeed �d
d�Z dS )�_TestMethodWrappera~ Wraps a test method to raise an error if it returns a value.
This is mainly used to detect undecorated generators (if a test
method yields it must use a decorator to consume the generator),
but will also detect other kinds of return values (these are not
necessarily errors, but we alert anyway since there is no good
reason to return a value from a test).
N)�orig_methodr c C s
|| _ d S )N)r+ )�selfr+ r r r �__init__^ s z_TestMethodWrapper.__init__)�args�kwargsr c O sB | j ||�}t|t�s tj|�r*td��n|d k r>td| ��d S )NzVGenerator and coroutine test methods should be decorated with tornado.testing.gen_testz)Return value from test method ignored: %r)r+ �
isinstancer �inspect�iscoroutine� TypeErrorr'