a
    zex                     @   sZ   d Z ddlZddlZddlmZmZmZ ddlmZ G dd dej	Z
edkrVe  dS )z
Test suite for PEP 380 implementation

adapted from original tests written by Greg Ewing
see <http://www.cosc.canterbury.ac.nz/greg.ewing/python/yield-from/YieldFrom-Python3.1.2-rev5.zip>
    N)captured_stderr
disable_gc
gc_collect)supportc                   @   s  e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dDS )ETestPEP380Operationz
    Test semantics.
    c                    sN   g  fdd}fdd | D ]} d|f  q$| g d dS )zH
        Test delegation of initial next() call to subgenerator
        c                   3   s$    d   E d H   d d S NStarting g1Finishing g1append g2tracer   */usr/lib/python3.9/test/test_yield_from.pyg1   s    
zOTestPEP380Operation.test_delegation_of_initial_next_to_subgenerator.<locals>.g1c                   3   s     d dV    d d S )NStarting g2*   Finishing g2r
   r   r   r   r   r      s    
zOTestPEP380Operation.test_delegation_of_initial_next_to_subgenerator.<locals>.g2
Yielded %s)r   r   z
Yielded 42r   r	   Nr   assertEqualselfr   xr   r   r   /test_delegation_of_initial_next_to_subgenerator   s    
zCTestPEP380Operation.test_delegation_of_initial_next_to_subgeneratorc              
      s   g  fdd}fdd z | D ]} d|f  q&W n6 tyt } z| |jd d W Y d}~nd}~0 0 | d	 | g d
 dS )z?
        Test raising exception in initial next() call
        c                	   3   s6   z$ d   E d H  W  d n d 0 d S r   r
   r   r   r   r   r   1   s    
zKTestPEP380Operation.test_raising_exception_in_initial_next_call.<locals>.g1c                	      s2   z   d tdW   d n  d 0 d S )Nr   spanish inquisition occurredr   r   
ValueErrorr   r   r   r   r   7   s    

zKTestPEP380Operation.test_raising_exception_in_initial_next_call.<locals>.g2r   r   r   N'subgenerator failed to raise ValueError)r   r   r   r	   r   r   r   argsfailr   r   r   er   r   r   +test_raising_exception_in_initial_next_call,   s    
(
z?TestPEP380Operation.test_raising_exception_in_initial_next_callc                    sN   g  fdd}fdd | D ]} d|f  q$| g d dS )z@
        Test delegation of next() call to subgenerator
        c                   3   s0    d dV    E d H  dV   d d S Nr   g1 hamg1 eggsr	   r
   r   r   r   r   r   P   s
    
zLTestPEP380Operation.test_delegation_of_next_call_to_subgenerator.<locals>.g1c                   3   s$     d dV  dV    d d S Nr   g2 spamg2 more spamr   r
   r   r   r   r   r   V   s    
zLTestPEP380Operation.test_delegation_of_next_call_to_subgenerator.<locals>.g2r   )r   Yielded g1 hamr   Yielded g2 spamYielded g2 more spamr   Yielded g1 eggsr	   Nr   r   r   r   r   ,test_delegation_of_next_call_to_subgeneratorK   s    
z@TestPEP380Operation.test_delegation_of_next_call_to_subgeneratorc              
      s   g  fdd}fdd z | D ]} d|f  q&W n6 tyt } z| |jd d W Y d}~nd}~0 0 | d	 | g d
 dS )zA
        Test raising exception in delegated next() call
        c                	   3   sB   z0 d dV    E d H  dV  W  d n d 0 d S r'   r
   r   r   r   r   r   m   s    
zMTestPEP380Operation.test_raising_exception_in_delegated_next_call.<locals>.g1c                	   3   s>   z,  d dV  tddV  W   d n  d 0 d S )Nr   r+   hovercraft is full of eelsr,   r   r   r   r   r   r   r   u   s    
zMTestPEP380Operation.test_raising_exception_in_delegated_next_call.<locals>.g2r   r   r2   Nr    r   r-   r   r.   r   r	   r!   r$   r   r   r   -test_raising_exception_in_delegated_next_callh   s    
(
zATestPEP380Operation.test_raising_exception_in_delegated_next_callc                    s   g  fdd}fdd | }t |}d}z(||}d|f  |d7 }q2W n tyj   Y n0 | g d dS )	z+
        Test delegation of send()
        c                  3   sP    d dV }  d| f    E d H  dV }  d| f   d d S Nr   r(   zg1 received %sr)   r	   r
   r   r   r   r   r      s    
z7TestPEP380Operation.test_delegation_of_send.<locals>.g1c                  3   sD     d dV }   d| f  dV }   d| f    d d S )Nr   r+   g2 received %sr,   r   r
   r6   r   r   r   r      s    
z7TestPEP380Operation.test_delegation_of_send.<locals>.g2   r   )r   g1 received 1r   r.   g2 received 2r/   zg2 received 3r   r0   zg1 received 4r	   N)nextsendr   StopIterationr   )r   r   gyr   r   r   r   test_delegation_of_send   s    
z+TestPEP380Operation.test_delegation_of_sendc                    sL   g fdd fdd fdd}|  t| | g d dS )	zA
        Test handling exception while delegating 'send'
        c                  3   sP    d dV }  d| f    E d H  dV }  d| f   d d S r5   r
   r6   r   r   r   r      s    
zMTestPEP380Operation.test_handling_exception_while_delegating_send.<locals>.g1c                  3   sL     d dV }   d| f  tddV }   d| f    d d S )Nr   r+   r7   r2   r,   r   r   r6   r   r   r   r      s    
zMTestPEP380Operation.test_handling_exception_while_delegating_send.<locals>.g2c                     s\     } t | }d}z(| |}d|f  |d7 }qW n tyV   d Y n0 d S )Nr8   r   r=   )r;   r<   r   r=   )r>   r?   r   )r   r   r   r   run   s    
zNTestPEP380Operation.test_handling_exception_while_delegating_send.<locals>.run)r   r9   r   r.   r:   N)assertRaisesr   r   r   rA   r   r   r   r   r   -test_handling_exception_while_delegating_send   s    zATestPEP380Operation.test_handling_exception_while_delegating_sendc                    sf   g  fdd}fdd | }t dD ]}t|}d|f  q,|  | g d dS )	z)
        Test delegating 'close'
        c                	   3   sB   z0 d dV    E d H  dV  W  d n d 0 d S r'   r
   r   r   r   r   r      s    
z5TestPEP380Operation.test_delegating_close.<locals>.g1c                	   3   s6   z$  d dV  dV  W   d n  d 0 d S r*   r
   r   r   r   r   r      s
    
z5TestPEP380Operation.test_delegating_close.<locals>.g2   r   r3   N)ranger;   r   closer   )r   r   r>   ir   r   r   r   test_delegating_close   s    z)TestPEP380Operation.test_delegating_closec              
      s   g  fdd}fdd z8| }t dD ]}t|}d|f  q.|  W nD ty } z,| |jd d | |jt	 W Y d	}~nd	}~0 0 | 
d
 | g d d	S )zB
        Test handling exception while delegating 'close'
        c                	   3   sB   z0 d dV    E d H  dV  W  d n d 0 d S r'   r
   r   r   r   r   r   	  s    
zMTestPEP380Operation.test_handing_exception_while_delegating_close.<locals>.g1c                	   3   sF   z,  d dV  dV  W   d tdn  d td0 d S )Nr   r+   r,   r   "nybbles have exploded with delightr   r   r   r   r   r     s    



zMTestPEP380Operation.test_handing_exception_while_delegating_close.<locals>.g2rF   r   r   rK   Nr    r3   )rG   r;   r   rH   r   r   r"   assertIsInstance__context__GeneratorExitr#   r   r   r>   rI   r   r%   r   r   r   -test_handing_exception_while_delegating_close  s    $
zATestPEP380Operation.test_handing_exception_while_delegating_closec              
      s   g  fdd}fdd zB| }t dD ]}t|}d|f  q.td}|| W n6 ty } z| |jd d W Y d	}~nd	}~0 0 | d
 | g d d	S )z)
        Test delegating 'throw'
        c                	   3   sB   z0 d dV    E d H  dV  W  d n d 0 d S r'   r
   r   r   r   r   r   2  s    
z5TestPEP380Operation.test_delegating_throw.<locals>.g1c                	   3   s6   z$  d dV  dV  W   d n  d 0 d S r*   r
   r   r   r   r   r   :  s
    
z5TestPEP380Operation.test_delegating_throw.<locals>.g2rF   r   tomato ejectedr   Nr    r3   rG   r;   r   r   throwr   r"   r#   rO   r   r   r   test_delegating_throw-  s    (
z)TestPEP380Operation.test_delegating_throwc                    sP   g   fdd}t  }|| t d}|| d|_|| |  g d dS )zC
        Test 'value' attribute of StopIteration exception
        c                    s,     d| jj| f    d| jf  d S )Nz%s: %sz
value = %s)r   	__class____name__value)r%   r   r   r   pexZ  s    zPTestPEP380Operation.test_value_attribute_of_StopIteration_exception.<locals>.pexspameggs)zStopIteration: zvalue = NoneStopIteration: spamzvalue = spamr[   zvalue = eggsN)r=   rW   r   )r   rX   r%   r   r   r   /test_value_attribute_of_StopIteration_exceptionU  s    zCTestPEP380Operation.test_value_attribute_of_StopIteration_exceptionc                    s,    fdd}dd  |  t| dg d S )Nc                   3   s     E d H  d S Nr   r   r   r   r   r   p  s    z:TestPEP380Operation.test_exception_value_crash.<locals>.g1c                   s   s   dV  dgS )Nr   r   r   r   r   r   r   r   r  s    z:TestPEP380Operation.test_exception_value_crash.<locals>.g2r   )r   list)r   r   r   r^   r   test_exception_value_crashm  s    z.TestPEP380Operation.test_exception_value_crashc                    sP   g  fdd}dfdd	 | D ]} d|f  q&| g d dS )	z-
        Test generator return value
        c                  3   sr    d dV    E d H }  d| f  ddtdfD ]"} |E d H }  d| f  q:dV   d d S )	Nr   r(   zg2 returned %rr8   rF      r)   r	   )r   r=   )retvr   r   r   r   }  s    
z;TestPEP380Operation.test_generator_return_value.<locals>.g1Nc                 3   s,     d dV  dV    d | r(| S d S r*   r
   rd   r   r   r   r     s    

z;TestPEP380Operation.test_generator_return_value.<locals>.g2r   )r   r-   r   r.   r/   r   zg2 returned Noner   r.   r/   r   zg2 returned 1r   r.   r/   r   zg2 returned (2,)r   r.   r/   r   zg2 returned StopIteration(3)r0   r	   )Nr   r   r   r   r   test_generator_return_valuex  s    

z/TestPEP380Operation.test_generator_return_valuec                 C   s<   g }dd }| D ]}| d|f  q| |g d dS )z<
        Test delegation of next() to non-generator
        c                   s   s   t dE d H  d S Nrb   rG   r   r   r   r   r>     s    zGTestPEP380Operation.test_delegation_of_next_to_non_generator.<locals>.gr   )	Yielded 0	Yielded 1	Yielded 2Nr   )r   r   r>   r   r   r   r   (test_delegation_of_next_to_non_generator  s
    
z<TestPEP380Operation.test_delegation_of_next_to_non_generatorc                 C   sN   g }dd }| }t dD ]}|d}|d|f  q| |g d dS )z9
        Test conversion of send(None) to next()
        c                   s   s   t dE d H  d S rg   rh   r   r   r   r   r>     s    zBTestPEP380Operation.test_conversion_of_sendNone_to_next.<locals>.grb   NYielded: %s)z
Yielded: 0z
Yielded: 1z
Yielded: 2)rG   r<   r   r   )r   r   r>   gir   r?   r   r   r   #test_conversion_of_sendNone_to_next  s    
z7TestPEP380Operation.test_conversion_of_sendNone_to_nextc                    sp   g   fdd}| }t | t }|  W d   n1 sB0    Y  | | d |  ddg dS )z=
        Test delegation of close() to non-generator
        c                	   3   sB   z0  d tdE d H    d W   d n  d 0 d S N
starting grb   zg should not be herefinishing gr   rG   r   r   r   r   r>     s
    
zHTestPEP380Operation.test_delegation_of_close_to_non_generator.<locals>.gN rq   rr   )r;   r   rH   r   getvalue)r   r>   rn   outputr   r   r   )test_delegation_of_close_to_non_generator  s    &z=TestPEP380Operation.test_delegation_of_close_to_non_generatorc              
      s   g   fdd}zB| }t dD ]}t|} d|f  q td}|| W n6 ty } z| |jd d W Y d}~nd}~0 0 | d |  g d	 dS )
z:
        Test delegating 'throw' to non-generator
        c                	   3   s8   z&  d tdE d H  W   d n  d 0 d S )N
Starting g
   Finishing grs   r   r   r   r   r>     s    
zETestPEP380Operation.test_delegating_throw_to_non_generator.<locals>.g   r   rQ   r   Nr    )rx   ri   rj   rk   z	Yielded 3z	Yielded 4rz   rR   )r   r>   rn   rI   r   r%   r   r   r   &test_delegating_throw_to_non_generator  s    (
z:TestPEP380Operation.test_delegating_throw_to_non_generatorc              
      s   g   fdd}z:| }t | tdD ]}|d} d|f  q(W n6 ty } z| d|jd  W Y d}~nd}~0 0 | d	 |  d
dg dS )z:
        Test attempting to send to non-generator
        c                	   3   sB   z0  d tdE d H    d W   d n  d 0 d S rp   rs   r   r   r   r   r>     s
    
zGTestPEP380Operation.test_attempting_to_send_to_non_generator.<locals>.grb   r   zShould not have yielded: %sr<   r   Nz#was able to send into non-generatorrq   rr   )	r;   rG   r<   r   AttributeErrorZassertInr"   r#   r   )r   r>   rn   r   r?   r%   r   r   r   (test_attempting_to_send_to_non_generator  s    
(
z<TestPEP380Operation.test_attempting_to_send_to_non_generatorc                    s  G dd d  fdd}|  t0 | }| t|d |d W d   n1 sZ0    Y  |  t0 | }| t|d |t W d   n1 s0    Y  t >}| }| t|d |	  | t|j
j W d   n1 s0    Y  dS )zG
        Test subiterator with a broken getattr implementation
        c                   @   s$   e Zd Zdd Zdd Zdd ZdS )z@TestPEP380Operation.test_broken_getattr_handling.<locals>.Brokenc                 S   s   | S r]   r   r   r   r   r   __iter__"  s    zITestPEP380Operation.test_broken_getattr_handling.<locals>.Broken.__iter__c                 S   s   dS )Nr8   r   r   r   r   r   __next__$  s    zITestPEP380Operation.test_broken_getattr_handling.<locals>.Broken.__next__c                 S   s   dd  d S Nr8   r   r   )r   attrr   r   r   __getattr__&  s    zLTestPEP380Operation.test_broken_getattr_handling.<locals>.Broken.__getattr__N)rV   
__module____qualname__r   r   r   r   r   r   r   Broken!  s   r   c                   3   s     E d H  d S r]   r   r   r   r   r   r>   )  s    z;TestPEP380Operation.test_broken_getattr_handling.<locals>.gr8   N)rB   ZeroDivisionErrorr   r;   r<   rS   r}   r   Zcatch_unraisable_exceptionrH   Z
unraisableexc_type)r   r>   rn   cmr   r   r   test_broken_getattr_handling  s    ((
z0TestPEP380Operation.test_broken_getattr_handlingc                    sD   g fdd dd  fdd}|  t| | dg dS )	z7
        Test exception in initial next() call
        c                   3   s$    d   E d H   d d S )Ng1 about to yield from g2g1 should not be herer
   r   r   r   r   r   B  s    
zCTestPEP380Operation.test_exception_in_initial_next_call.<locals>.g1c                   s   s   dd V  d S r   r   r   r   r   r   r   F  s    zCTestPEP380Operation.test_exception_in_initial_next_call.<locals>.g2c                     s     } t |  d S r]   )r;   )rn   r   r   r   rA   H  s    zDTestPEP380Operation.test_exception_in_initial_next_call.<locals>.runr   N)rB   r   r   rC   r   rD   r   #test_exception_in_initial_next_call=  s    z7TestPEP380Operation.test_exception_in_initial_next_callc              
      s   g  fdd}fdd z$| D ]} d|f  q,W n6 tyz } z| |jd d W Y d}~nd}~0 0 | d	 | g d
 dS )z0
        Test attempted yield-from loop
        c                   3   s4    d dV   d   E d H   d d S )Ng1: startingZy1g1: about to yield from g2r   r
   r   r   r   r   r   U  s
    

z>TestPEP380Operation.test_attempted_yield_from_loop.<locals>.g1c                   3   s2    d dV   d  E d H   d d S )Ng2: startingZy2g2: about to yield from g1zg2 should not be herer
   r   )rn   r   r   r   r   \  s
    


z>TestPEP380Operation.test_attempted_yield_from_loop.<locals>.g2rm   r   zgenerator already executingNz$subgenerator didn't raise ValueError)r   zYielded: y1r   r   zYielded: y2r   r!   )r   r   r?   r%   r   )r   rn   r   r   test_attempted_yield_from_loopP  s    (
z2TestPEP380Operation.test_attempted_yield_from_loopc                    s   g fdd} fddG dd dt  | }tdD ]}t|}d|f  q> d	}|| |D ]}d|f  qr| g d
 dS )z=
        Test returning value from delegated 'throw'
        c                	   3   sB   z0 d dV    E d H  dV  W  d n d 0 d S r'   r
   r   r   r   r   r   x  s    
zITestPEP380Operation.test_returning_value_from_delegated_throw.<locals>.g1c                   3   sH   z d dV  dV  W n(  yB    d dV  dV  Y n0 d S )Nr   r+   r,   Caught LunchError in g2zg2 lunch savedzg2 yet more spamr
   r   )
LunchErrorr   r   r   r     s    


zITestPEP380Operation.test_returning_value_from_delegated_throw.<locals>.g2c                   @   s   e Zd ZdS )zQTestPEP380Operation.test_returning_value_from_delegated_throw.<locals>.LunchErrorNrV   r   r   r   r   r   r   r     s   r   rF   r   rQ   )r   r-   r   r.   r   zYielded g2 yet more spamr0   r	   N)	ExceptionrG   r;   r   rS   r   rO   r   )r   r   r   r   )test_returning_value_from_delegated_throws  s    	
z=TestPEP380Operation.test_returning_value_from_delegated_throwc                    sV   g  fdd}fdd |d |d |d |t d | g d	 dS )
z1
        Test next and return with value
        c              
      sj    | }t | z d t | d W n4 tyd } zd|f  W Y d }~n
d }~0 0 d S )Nf resuming gf SHOULD NOT BE HEREf caught %r)r;   r   r=   rrn   r%   r>   r   r   r   f  s    
z>TestPEP380Operation.test_next_and_return_with_value.<locals>.fc                 3   s$     d d V    d| f  | S )N
g startingg returning %rr
   )r   r   r   r   r>     s    
z>TestPEP380Operation.test_next_and_return_with_value.<locals>.gNr8   ra   rb   )r   r   g returning Nonef caught StopIteration()r   r   g returning 1f caught StopIteration(1)r   r   g returning (2,)f caught StopIteration((2,))r   r   g returning StopIteration(3)(f caught StopIteration(StopIteration(3))r=   r   r   r   r   r   r   test_next_and_return_with_value  s    	z3TestPEP380Operation.test_next_and_return_with_valuec                    sV   g  fdd}fdd |d |d |d |t d | g d	 dS )
z1
        Test send and return with value
        c              
      sl    | }t | z"d |d d W n4 tyf } zd|f  W Y d }~n
d }~0 0 d S )Nf sending spam to grY   r   r   )r;   r   r<   r=   r   r   r   r   r     s    

z>TestPEP380Operation.test_send_and_return_with_value.<locals>.fc                 3   s4     d d V }  d|f    d| f  | S )Nr   zg received %rr   r
   )r   r   r   r   r   r>     s
    
z>TestPEP380Operation.test_send_and_return_with_value.<locals>.gNr8   ra   rb   )r   r   g received 'spam'r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   test_send_and_return_with_value  s    	z3TestPEP380Operation.test_send_and_return_with_valuec              	      s~   fdd  fdd}ddt dfD ]Ng | }t| t|t | ddd	f tg q*d
S )ze
        Test catching an exception thrown into a
        subgenerator and returning a value
        c                   3   s,   z
dV  W n t y&    d Y n0 S )Nr8   inner caught ValueError)r   r   r   )r   rW   r   r   inner  s
    
zTTestPEP380Operation.test_catching_exception_from_subgen_and_returning.<locals>.innerc                  3   s&     E d H }  d| f  | V  d S )Ninner returned %r to outerr
   re   )r   r   r   r   outer  s    zTTestPEP380Operation.test_catching_exception_from_subgen_and_returning.<locals>.outerrF   ra   r8   r   r   N)r=   r   r;   reprrS   r   r   r   r   r>   r   )r   r   rW   r   1test_catching_exception_from_subgen_and_returning  s    zETestPEP380Operation.test_catching_exception_from_subgen_and_returningc                    sl   g fdd  fdd}z| }t | |t W n tyL   Y n0 | d | ddg dS )	zo
        Test throwing GeneratorExit into a subgenerator that
        catches it and returns normally.
        c                   3   s8   z  d d V    d W n ty2   Y d S 0 d S NEnter fExit fr   rN   r   r   r   r   r     s    
zSTestPEP380Operation.test_throwing_GeneratorExit_into_subgen_that_returns.<locals>.fc                   3   s$    d   E d H   d d S NEnter gzExit gr
   r   r   r   r   r   r>   !  s    
zSTestPEP380Operation.test_throwing_GeneratorExit_into_subgen_that_returns.<locals>.g*subgenerator failed to raise GeneratorExitr   r   N)r;   rS   rN   r#   r   )r   r>   rn   r   r   r   4test_throwing_GeneratorExit_into_subgen_that_returns  s    
zHTestPEP380Operation.test_throwing_GeneratorExit_into_subgen_that_returnsc              
      s   g fdd  fdd}z| }t | |t W n6 typ } z| |jd d W Y d}~nd}~0 0 | d | d	d
g dS )ze
        Test throwing GeneratorExit into a subgenerator that
        catches it and yields.
        c                   3   s<   z  d d V    d W n ty6   d V  Y n0 d S r   r   r   r   r   r   r   8  s    
zXTestPEP380Operation.test_throwing_GeneratorExit_into_subgenerator_that_yields.<locals>.fc                   3   s$    d   E d H   d d S r   r
   r   r   r   r   r>   ?  s    
zXTestPEP380Operation.test_throwing_GeneratorExit_into_subgenerator_that_yields.<locals>.gr   zgenerator ignored GeneratorExitNr   r   r   )r;   rS   rN   RuntimeErrorr   r"   r#   r   r>   rn   r%   r   r   r   9test_throwing_GeneratorExit_into_subgenerator_that_yields2  s    (
zMTestPEP380Operation.test_throwing_GeneratorExit_into_subgenerator_that_yieldsc              
      s   g fdd  fdd}z| }t | |t W nD ty~ } z,| |jd d | |jt W Y d}~nd}~0 0 | d | d	d
g dS )z{
        Test throwing GeneratorExit into a subgenerator that
        catches it and raises a different exception.
        c                   3   s>   z  d d V    d W n ty8   tdY n0 d S )Nr   r   Vorpal bunny encountered)r   rN   r   r   r   r   r   r   V  s    
zRTestPEP380Operation.test_throwing_GeneratorExit_into_subgen_that_raises.<locals>.fc                   3   s$    d   E d H   d d S r   r
   r   r   r   r   r>   ]  s    
zRTestPEP380Operation.test_throwing_GeneratorExit_into_subgen_that_raises.<locals>.gr   r   Nr    r   r   )	r;   rS   rN   r   r   r"   rL   rM   r#   r   r   r   r   3test_throwing_GeneratorExit_into_subgen_that_raisesP  s    $
zGTestPEP380Operation.test_throwing_GeneratorExit_into_subgen_that_raisesc                 C   s   dd }|  tt|  d S )Nc                   s   s   dE d H  d S )Nr   r   r   r   r   r   r>   p  s    z4TestPEP380Operation.test_yield_from_empty.<locals>.g)rB   r=   r;   )r   r>   r   r   r   test_yield_from_emptyo  s    z)TestPEP380Operation.test_yield_from_emptyc                    s  fdd}fdd|  tg d | tg}z|d qDW n tyj   Y n0  |g d G dd dt  fd	d} fd
d| tg}z|  qW n ty   Y n0 G fdddtfdd}| t 	  d S )Nc                   3   s   dV    E d H  dV  d S Nr   rb   r   r   )twor   r   onev  s    zOTestPEP380Operation.test_delegating_generators_claim_to_be_running.<locals>.onec                   3   s2   dV  z E d H  W n t y&   Y n0 dV  d S Nr8   rF   r   r   r   r   r   r   z  s    zOTestPEP380Operation.test_delegating_generators_claim_to_be_running.<locals>.two)r   r8   rF   rb   r   c                   @   s   e Zd ZdS )zQTestPEP380Operation.test_delegating_generators_claim_to_be_running.<locals>.MyErrNr   r   r   r   r   MyErr  s   r   c                   3   sL   z
dV  W n  y   Y n0  E d H  z
dV  W n  yF   Y n0 d S r   r   r   )r   r   r   r   r     s    

c                   3   sb   z
dV  W n  y   Y n0 zE d H  W n t y>   Y n0 z
dV  W n  y\   Y n0 d S r   r   r   )r   r   r   r   r     s    

c                       s*   e Zd Zdd Zdd Z fddZdS )zPTestPEP380Operation.test_delegating_generators_claim_to_be_running.<locals>.MyItc                 S   s   | S r]   r   r   r   r   r   r     s    zYTestPEP380Operation.test_delegating_generators_claim_to_be_running.<locals>.MyIt.__iter__c                 S   s   dS Nr   r   r   r   r   r   r     s    zYTestPEP380Operation.test_delegating_generators_claim_to_be_running.<locals>.MyIt.__next__c                    s     j tt  d S r]   )
assertTrue
gi_runningrB   r   r;   )Zself_r   r   r   r   rH     s    zVTestPEP380Operation.test_delegating_generators_claim_to_be_running.<locals>.MyIt.closeN)rV   r   r   r   r   rH   r   r   r   r   MyIt  s   r   c                   3   s     E d H  d S r]   r   r   )r   r   r   r     s    )
r   r_   r;   r   r<   r=   r   rS   objectrH   )r   r   resr   )r   r   r   r   r   r   .test_delegating_generators_claim_to_be_runningt  s2    


zBTestPEP380Operation.test_delegating_generators_claim_to_be_runningc                    sp   dd   fdd}dd }dd }|| D ]}|  d	|v  q.||| D ]}|  d	|v ofd
|v  qPd S )Nc                   S   s   dd t  D S )Nc                 S   s   g | ]}|d  qS )rb   r   ).0r   r   r   r   
<listcomp>      zaTestPEP380Operation.test_delegator_is_visible_to_debugger.<locals>.call_stack.<locals>.<listcomp>)inspectstackr   r   r   r   
call_stack  s    zMTestPEP380Operation.test_delegator_is_visible_to_debugger.<locals>.call_stackc                   3   s     V    V    V  d S r]   r   r   r   r   r   gen  s    zFTestPEP380Operation.test_delegator_is_visible_to_debugger.<locals>.genc                 s   s   | E d H  d S r]   r   r>   r   r   r   rY     s    zGTestPEP380Operation.test_delegator_is_visible_to_debugger.<locals>.spamc                 s   s   | E d H  d S r]   r   r   r   r   r   rZ     s    zGTestPEP380Operation.test_delegator_is_visible_to_debugger.<locals>.eggsrY   rZ   )r   )r   r   rY   rZ   r   r   r   r   %test_delegator_is_visible_to_debugger  s    z9TestPEP380Operation.test_delegator_is_visible_to_debuggerc                    s:   G dd d  fdd}d t |  | d d S )Nc                   @   s   e Zd Zdd Zdd ZdS )z?TestPEP380Operation.test_custom_iterator_return.<locals>.MyIterc                 S   s   | S r]   r   r   r   r   r   r     s    zHTestPEP380Operation.test_custom_iterator_return.<locals>.MyIter.__iter__c                 S   s   t dd S r   )r=   r   r   r   r   r     s    zHTestPEP380Operation.test_custom_iterator_return.<locals>.MyIter.__next__N)rV   r   r   r   r   r   r   r   r   MyIter  s   r   c                   3   s     E d H d S r]   r   r   r   rc   r   r   r     s    z<TestPEP380Operation.test_custom_iterator_return.<locals>.genr   )r_   r   )r   r   r   r   r   test_custom_iterator_return  s
    
z/TestPEP380Operation.test_custom_iterator_returnc                    sz   dd   fdd}dd }t  D | }| }|d  || || ~~t  W d    n1 sl0    Y  d S )Nc                   s   s
   d V  d S r]   r   r   r   r   r   	innermost  s    zDTestPEP380Operation.test_close_with_cleared_frame.<locals>.innermostc                  3   s   d V }   E d H  d S r]   r   )	outer_genr   r   r   r     s    z@TestPEP380Operation.test_close_with_cleared_frame.<locals>.innerc                  s   s   d V } | E d H  d S r]   r   )	inner_genr   r   r   r     s    z@TestPEP380Operation.test_close_with_cleared_frame.<locals>.outer)r   r<   r   )r   r   r   r   r   r   r   r   test_close_with_cleared_frame  s    


z1TestPEP380Operation.test_close_with_cleared_framec                    sJ   G fddd  fdd}| }t | d |d | d d S )Nc                       s(   e Zd Zdd Zdd Z fddZdS )zHTestPEP380Operation.test_send_tuple_with_custom_generator.<locals>.MyGenc                 S   s   | S r]   r   r   r   r   r   r   	  s    zQTestPEP380Operation.test_send_tuple_with_custom_generator.<locals>.MyGen.__iter__c                 S   s   dS r   r   r   r   r   r   r     s    zQTestPEP380Operation.test_send_tuple_with_custom_generator.<locals>.MyGen.__next__c                    s   | d S r]   r   )r   Zwhatre   r   r   r<     s    zMTestPEP380Operation.test_send_tuple_with_custom_generator.<locals>.MyGen.sendN)rV   r   r   r   r   r<   r   re   r   r   MyGen  s   r   c                  3   s     E d H } d S r]   r   re   )r   r   r   r     s    zHTestPEP380Operation.test_send_tuple_with_custom_generator.<locals>.outer)r8   rF   rb      )r;   r<   r   r   r   )r   rd   r   %test_send_tuple_with_custom_generator  s    	
z9TestPEP380Operation.test_send_tuple_with_custom_generatorN)%rV   r   r   __doc__r   r&   r1   r4   r@   rE   rJ   rP   rT   r\   r`   rf   rl   ro   rw   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      sD   %,)")(3  #+*/H'r   __main__)r   Zunittestr   Ztest.supportr   r   r   testr   ZTestCaser   rV   mainr   r   r   r   <module>   s           