File: //usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/test_inlinecb.cpython-310.pyc
o
�b�, � @ s� d Z ddlmZmZmZmZ ddlmZmZ G dd� de�Z G dd� de�Z
G dd � d e�ZG d
d� de�Z
G dd
� d
e�ZG dd� de�ZG dd� de�ZdS )z�
Tests for L{twisted.internet.defer.inlineCallbacks}.
Some tests for inlineCallbacks are defined in L{twisted.test.test_defgen} as
well.
� )�CancelledError�Deferred�inlineCallbacks�returnValue)�SynchronousTestCase�TestCasec @ � e Zd ZdZdd� ZdS )�StopIterationReturnTestsz�
On Python 3.4 and newer generator functions may use the C{return} statement
with a value, which is attached to the L{StopIteration} exception that is
raised.
L{inlineCallbacks} will use this value when it fires the C{callback}.
c C sD dt i}td|� t� }|d |�}|�d� | �| �|�d� dS )z�
If the C{return} statement has a value it is propagated back to the
L{Deferred} that the C{inlineCallbacks} function returned.
r z>
@inlineCallbacks
def f(d):
yield d
return 14
�fN� )r �execr �callback�assertEqual�successResultOf)�self�environ�d1�d2� r �E/usr/lib/python3/dist-packages/twisted/internet/test/test_inlinecb.py�test_returnWithValue s �
z-StopIterationReturnTests.test_returnWithValueN)�__name__�
__module__�__qualname__�__doc__r r r r r r s r c @ s0 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
S )�NonLocalExitTestsa�
It's possible for L{returnValue} to be (accidentally) invoked at a stack
level below the L{inlineCallbacks}-decorated function which it is exiting.
If this happens, L{returnValue} should report useful errors.
If L{returnValue} is invoked from a function not decorated by
L{inlineCallbacks}, it will emit a warning if it causes an
L{inlineCallbacks} function further up the stack to exit.
c C s t d� dS )z�
This method mistakenly invokes L{returnValue}, despite the fact that it
is not decorated with L{inlineCallbacks}.
� N)r �r r r r �mistakenMethod? s z NonLocalExitTests.mistakenMethodc C sZ | � |dg� | j| jgd�}| � t|�d� | � |d d t� | � |d d d� dS )ac
Flush the current warnings and assert that we have been told that
C{mistakenMethod} was invoked, and that the result from the Deferred
that was fired (appended to the given list) is C{mistakenMethod}'s
result. The warning should indicate that an inlineCallbacks function
called 'inline' was made to exit.
r )�offendingFunctionsr �category�messagez�returnValue() in 'mistakenMethod' causing 'inline' to exit: returnValue should only be invoked by functions decorated with inlineCallbacksN)r �
flushWarningsr �len�DeprecationWarning)r �
resultList�warningsr r r �assertMistakenMethodWarningF s
�z-NonLocalExitTests.assertMistakenMethodWarningc s4 t � fdd��}|� }g }|�|j� � �|� dS )z�
L{returnValue} will emit a non-local exit warning in the simplest case,
where the offending function is invoked immediately.
c 3 s � � � � td� dV d S )N� r �r r r r r r �inline_ s �
zANonLocalExitTests.test_returnValueNonLocalWarning.<locals>.inlineN)r �addCallback�appendr'