Format: application/x-python-code
⬇ Download File (3.1 KB)
   1  o
   2  
   3  -h�
   4  �@sBddlZddlZddlZddlmZddlmZGdd�d�ZdS)�N�)�guarantee_single_callable)�timeoutc@sPeZdZdZdd�Zddd�Zddd	�Zd
   5  d�Zdd
   6  �Zddd�Z	ddd�Z
   7  dS)�ApplicationCommunicatorz}
   8      Runs an ASGI application in a test mode, allowing sending of
   9      messages to it and retrieval of messages it sends.
  10      cCsNt|�|_||_t��|_t��|_t���	tj
  11  |�||jj|jj��|_
  12  dS�N)r�application�scope�asyncio�Queue�input_queue�output_queue�contextvars�Context�run�create_task�get�put�future)�selfrr�r�EC:\Users\shubh\Videos\agent\nova\Lib\site-packages\asgiref/testing.py�__init__s
  13  
  14  
  15  
  16  �z ApplicationCommunicator.__init__rc�s��zXt|�4IdH�#z
  17  |jIdH|j��Wn
  18  tjy"YnwWd�IdHn1IdHs3wYW|j��sX|j��z	|jIdHWdStjyWYdSwdS|j��sw|j��z|jIdHWwtjyvYwww)zV
  19          Waits for the application to stop itself and returns any exceptions.
  20          N)�
  21  async_timeoutr�resultr	�CancelledError�done�cancel)rrrrr�waits6���(��
  22  
  23  ��
  24  ��zApplicationCommunicator.waitTcCs.|j��s|j��dS|r|j��dSdSr)rrrr)r�
  25  exceptionsrrr�stop0s
  26  
  27  �zApplicationCommunicator.stopcCs(z	|jdd�WdStyYdSw)NF)r)r�RuntimeError)rrrr�__del__7s
  28  �zApplicationCommunicator.__del__c�s�|j�|�IdHdS)z;
  29          Sends a single message to the application
  30          N)rr)r�messagerrr�
  31  send_input?s�z"ApplicationCommunicator.send_inputc�s��|j��r|j��z*t|�4IdH�|j��IdHWd�IdHWS1IdHs.wYWdStjyh}z&|j��rJ|j��|�|j��z	|jIdHW|�tj	ycY|�wd}~ww)zX
  32          Receives a single message from the application, with optional timeout.
  33          N)
  34  rrrrrrr	�TimeoutErrorrr)rr�errr�receive_outputFs*�
  35  
  36  4�
  37  
  38  
  39  �����z&ApplicationCommunicator.receive_output皙�����?�{�G�z�?c�sR�t��}t��||kr$|j��sdSt�|�IdHt��||ks
  40  |j��S)zO
  41          Checks that there is no message to receive in the given time.
  42          FN)�time�	monotonicr�emptyr	�sleep)rr�interval�startrrr�receive_nothing]s�
  43  �
  44  z'ApplicationCommunicator.receive_nothingN)r)T)r'r()�__name__�
  45  __module__�__qualname__�__doc__rrrr!r#r&r/rrrrr	s
  46  
  47  
  48  r)r	r
  49  r)�
  50  compatibilityrrrrrrrr�<module>s