B
    v9a'                @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZ d dlmZ d dlZd dlmZmZmZmZmZ d dlmZ edZedZedZG d	d
 d
eZG dd dejeeZedkre   dS )    N)deepcopy)support)TestEqualityTestHashingLoggingResultLegacyLoggingResult#ResultWithNoStartTestRunStopTestRun)captured_stderrfoozfoo.barquuxc               @   s@   e Zd ZG dd dejZG dd deZG dd dejZdS )Testc               @   s   e Zd Zdd Zdd ZdS )zTest.Fooc             C   s   d S )N )selfr   r   /usr/lib/python3.7/test_case.pyrunTest!       zTest.Foo.runTestc             C   s   d S )Nr   )r   r   r   r   test1"   r   zTest.Foo.test1N)__name__
__module____qualname__r   r   r   r   r   r   Foo    s   r   c               @   s   e Zd Zdd ZdS )zTest.Barc             C   s   d S )Nr   )r   r   r   r   test2%   r   zTest.Bar.test2N)r   r   r   r   r   r   r   r   Bar$   s   r   c                   s4   e Zd Z fddZdd Zdd Zdd Z  ZS )	zTest.LoggingTestCasec                s   t tj| d || _d S )Ntest)superr   LoggingTestCase__init__events)r   r   )	__class__r   r   r   *   s    zTest.LoggingTestCase.__init__c             C   s   | j d d S )NsetUp)r   append)r   r   r   r   r   .   s    zTest.LoggingTestCase.setUpc             C   s   | j d d S )Nr   )r   r    )r   r   r   r   r   1   s    zTest.LoggingTestCase.testc             C   s   | j d d S )NtearDown)r   r    )r   r   r   r   r!   4   s    zTest.LoggingTestCase.tearDown)r   r   r   r   r   r   r!   __classcell__r   r   )r   r   r   '   s   r   N)r   r   r   unittestTestCaser   r   r   r   r   r   r   r      s   r   c               @   s  e Zd ZededfgZededfededfededfg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'dDdE Z(e)*e+j,j-dFkdGdHdI Z.e)*e+j,j-dFkdGdJdK Z/dLdM Z0dNdO Z1dPdQ Z2dRdS Z3dTdU Z4dVdW Z5dXdY Z6dZd[ Z7d\d] Z8d^d_ Z9d`da Z:dbdc Z;ddde Z<dfdg Z=dhdi Z>djdk Z?dldm Z@dndo ZAdpdq ZBdrds ZCdtdu ZDdvdw ZEdxdy ZFdzd{ ZGd|d} ZHd~d ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWeXjYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zadd Zbdd Zcdd Zddd Zedd Zfdd Zgdd Zhdd Zidd Zjdd Zkeljmdd ZnddÄ ZodS )Test_TestCaser   r   r   c          	   C   s   G dd dt j}| |  dd  d t  }|dd ||j |dd W d Q R X | t |  W d Q R X d S )Nc               @   s   e Zd Zdd Zdd ZdS )z3Test_TestCase.test_init__no_test_name.<locals>.Testc             S   s
   t  d S )N)MyException)r   r   r   r   r   T   r   z;Test_TestCase.test_init__no_test_name.<locals>.Test.runTestc             S   s   d S )Nr   )r   r   r   r   r   U   r   z8Test_TestCase.test_init__no_test_name.<locals>.Test.testN)r   r   r   r   r   r   r   r   r   r   S   s   r   iz.Test.runTest      )r#   r$   assertEqualidassertRaisesfailureExceptionAttributeErrorrun)r   r   r   r   r   r   test_init__no_test_nameR   s    z%Test_TestCase.test_init__no_test_namec             C   s2   G dd dt j}| |d dd  d d S )Nc               @   s   e Zd Zdd Zdd ZdS )z7Test_TestCase.test_init__test_name__valid.<locals>.Testc             S   s
   t  d S )N)r&   )r   r   r   r   r   i   r   z?Test_TestCase.test_init__test_name__valid.<locals>.Test.runTestc             S   s   d S )Nr   )r   r   r   r   r   j   r   z<Test_TestCase.test_init__test_name__valid.<locals>.Test.testN)r   r   r   r   r   r   r   r   r   r   h   s   r   r   iz
.Test.test)r#   r$   r)   r*   )r   r   r   r   r   test_init__test_name__validg   s    z)Test_TestCase.test_init__test_name__validc             C   sB   G dd dt j}y|d W n tk
r2   Y nX | d d S )Nc               @   s   e Zd Zdd Zdd ZdS )z9Test_TestCase.test_init__test_name__invalid.<locals>.Testc             S   s
   t  d S )N)r&   )r   r   r   r   r   t   r   zATest_TestCase.test_init__test_name__invalid.<locals>.Test.runTestc             S   s   d S )Nr   )r   r   r   r   r   u   r   z>Test_TestCase.test_init__test_name__invalid.<locals>.Test.testN)r   r   r   r   r   r   r   r   r   r   s   s   r   ZtestfoozFailed to raise ValueError)r#   r$   
ValueErrorfail)r   r   r   r   r   test_init__test_name__invalidr   s    z+Test_TestCase.test_init__test_name__invalidc             C   s*   G dd dt j}| |d d d S )Nc               @   s   e Zd Zdd ZdS )z.Test_TestCase.test_countTestCases.<locals>.Fooc             S   s   d S )Nr   )r   r   r   r   r      r   z3Test_TestCase.test_countTestCases.<locals>.Foo.testN)r   r   r   r   r   r   r   r   r      s   r   r      )r#   r$   r)   ZcountTestCases)r   r   r   r   r   test_countTestCases   s    z!Test_TestCase.test_countTestCasesc             C   s2   G dd dt j}|  }| t|t j d S )Nc               @   s   e Zd Zdd ZdS )z1Test_TestCase.test_defaultTestResult.<locals>.Fooc             S   s   d S )Nr   )r   r   r   r   r      s    z9Test_TestCase.test_defaultTestResult.<locals>.Foo.runTestN)r   r   r   r   r   r   r   r   r      s   r   )r#   r$   defaultTestResultr)   type
TestResult)r   r   resultr   r   r   test_defaultTestResult   s    
z$Test_TestCase.test_defaultTestResultc                sL   g }t |}G  fdddtj  || ddddg}| || d S )Nc                   s   e Zd Z fddZ  ZS )z>Test_TestCase.test_run_call_order__error_in_setUp.<locals>.Fooc                s   t  |   tdd S )Nzraised by Foo.setUp)r   r   RuntimeError)r   )r   r   r   r   r      s    zDTest_TestCase.test_run_call_order__error_in_setUp.<locals>.Foo.setUp)r   r   r   r   r"   r   )r   )r   r   r      s   r   	startTestr   addErrorstopTest)r   r   r   r.   r)   )r   r   r9   expectedr   )r   r   #test_run_call_order__error_in_setUp   s    z1Test_TestCase.test_run_call_order__error_in_setUpc                sF   g }G  fdddt j  |  ddddddg}| || d S )	Nc                   s&   e Zd Zdd Z fddZ  ZS )zMTest_TestCase.test_run_call_order__error_in_setUp_default_result.<locals>.Fooc             S   s
   t | jS )N)r   r   )r   r   r   r   r6      s    z_Test_TestCase.test_run_call_order__error_in_setUp_default_result.<locals>.Foo.defaultTestResultc                s   t  |   tdd S )Nzraised by Foo.setUp)r   r   r;   )r   )r   r   r   r   r      s    zSTest_TestCase.test_run_call_order__error_in_setUp_default_result.<locals>.Foo.setUp)r   r   r   r6   r   r"   r   )r   )r   r   r      s   r   startTestRunr<   r   r=   r>   stopTestRun)r   r   r.   r)   )r   r   r?   r   )r   r   2test_run_call_order__error_in_setUp_default_result   s    z@Test_TestCase.test_run_call_order__error_in_setUp_default_resultc                sP   g }t |}G  fdddtj ddddddg} || | || d S )	Nc                   s   e Zd Z fddZ  ZS )z=Test_TestCase.test_run_call_order__error_in_test.<locals>.Fooc                s   t  |   tdd S )Nzraised by Foo.test)r   r   r;   )r   )r   r   r   r   r      s    zBTest_TestCase.test_run_call_order__error_in_test.<locals>.Foo.test)r   r   r   r   r"   r   )r   )r   r   r      s   r   r<   r   r   r!   r=   r>   )r   r   r   r.   r)   )r   r   r9   r?   r   )r   r   "test_run_call_order__error_in_test   s    z0Test_TestCase.test_run_call_order__error_in_testc                sJ   g }G  fdddt j ddddddd	d
g} |  | || d S )Nc                   s&   e Zd Zdd Z fddZ  ZS )zLTest_TestCase.test_run_call_order__error_in_test_default_result.<locals>.Fooc             S   s
   t | jS )N)r   r   )r   r   r   r   r6      s    z^Test_TestCase.test_run_call_order__error_in_test_default_result.<locals>.Foo.defaultTestResultc                s   t  |   tdd S )Nzraised by Foo.test)r   r   r;   )r   )r   r   r   r   r      s    zQTest_TestCase.test_run_call_order__error_in_test_default_result.<locals>.Foo.test)r   r   r   r6   r   r"   r   )r   )r   r   r      s   r   rA   r<   r   r   r!   r=   r>   rB   )r   r   r.   r)   )r   r   r?   r   )r   r   1test_run_call_order__error_in_test_default_result   s    z?Test_TestCase.test_run_call_order__error_in_test_default_resultc                sP   g }t |}G  fdddtj ddddddg} || | || d S )	Nc                   s   e Zd Z fddZ  ZS )z?Test_TestCase.test_run_call_order__failure_in_test.<locals>.Fooc                s   t  |   | d d S )Nzraised by Foo.test)r   r   r2   )r   )r   r   r   r   r      s    zDTest_TestCase.test_run_call_order__failure_in_test.<locals>.Foo.test)r   r   r   r   r"   r   )r   )r   r   r      s   r   r<   r   r   r!   
addFailurer>   )r   r   r   r.   r)   )r   r   r9   r?   r   )r   r   $test_run_call_order__failure_in_test   s    z2Test_TestCase.test_run_call_order__failure_in_testc                sJ   G  fdddt j ddddddd	d
g}g } |  | || d S )Nc                   s&   e Zd Zdd Z fddZ  ZS )zNTest_TestCase.test_run_call_order__failure_in_test_default_result.<locals>.Fooc             S   s
   t | jS )N)r   r   )r   r   r   r   r6      s    z`Test_TestCase.test_run_call_order__failure_in_test_default_result.<locals>.Foo.defaultTestResultc                s   t  |   | d d S )Nzraised by Foo.test)r   r   r2   )r   )r   r   r   r   r      s    zSTest_TestCase.test_run_call_order__failure_in_test_default_result.<locals>.Foo.test)r   r   r   r6   r   r"   r   )r   )r   r   r      s   r   rA   r<   r   r   r!   rF   r>   rB   )r   r   r.   r)   )r   r?   r   r   )r   r   3test_run_call_order__failure_in_test_default_result   s    zATest_TestCase.test_run_call_order__failure_in_test_default_resultc                sP   g }t |}G  fdddtj  || ddddddg}| || d S )	Nc                   s   e Zd Z fddZ  ZS )zATest_TestCase.test_run_call_order__error_in_tearDown.<locals>.Fooc                s   t  |   tdd S )Nzraised by Foo.tearDown)r   r!   r;   )r   )r   r   r   r   r!     s    zJTest_TestCase.test_run_call_order__error_in_tearDown.<locals>.Foo.tearDown)r   r   r   r!   r"   r   )r   )r   r   r     s   r   r<   r   r   r!   r=   r>   )r   r   r   r.   r)   )r   r   r9   r?   r   )r   r   &test_run_call_order__error_in_tearDown
  s    
z4Test_TestCase.test_run_call_order__error_in_tearDownc                sJ   G  fdddt j g } |  ddddddd	d
g}| || d S )Nc                   s&   e Zd Zdd Z fddZ  ZS )zPTest_TestCase.test_run_call_order__error_in_tearDown_default_result.<locals>.Fooc             S   s
   t | jS )N)r   r   )r   r   r   r   r6     s    zbTest_TestCase.test_run_call_order__error_in_tearDown_default_result.<locals>.Foo.defaultTestResultc                s   t  |   tdd S )Nzraised by Foo.tearDown)r   r!   r;   )r   )r   r   r   r   r!     s    zYTest_TestCase.test_run_call_order__error_in_tearDown_default_result.<locals>.Foo.tearDown)r   r   r   r6   r!   r"   r   )r   )r   r   r     s   r   rA   r<   r   r   r!   r=   r>   rB   )r   r   r.   r)   )r   r   r?   r   )r   r   5test_run_call_order__error_in_tearDown_default_result  s    

zCTest_TestCase.test_run_call_order__error_in_tearDown_default_resultc             C   s"   G dd dt j}|d  d S )Nc               @   s   e Zd Zdd Zdd ZdS )z=Test_TestCase.test_run_call_order_default_result.<locals>.Fooc             S   s   t  S )N)r   )r   r   r   r   r6   -  s    zOTest_TestCase.test_run_call_order_default_result.<locals>.Foo.defaultTestResultc             S   s   d S )Nr   )r   r   r   r   r   /  s    zBTest_TestCase.test_run_call_order_default_result.<locals>.Foo.testN)r   r   r   r6   r   r   r   r   r   r   ,  s   r   r   )r#   r$   r.   )r   r   r   r   r   "test_run_call_order_default_result*  s    z0Test_TestCase.test_run_call_order_default_resultc                s4   G  fdddt j  || | || d S )Nc                   s   e Zd Z fddZ  ZS )z6Test_TestCase._check_call_order__subtests.<locals>.Fooc                s   t  |   xpdD ]h}| j|dR |dkr8| d x8dD ]0}| j|d || dkrdtdW d Q R X q>W W d Q R X qW dd	  d S )
N)r4   r(   r'   )ir4   failure)r(   r'   )j   zraised by Foo.testr   )r   r   subTestr2   r;   )r   rL   rN   )r   r   r   r   r   6  s    


$z;Test_TestCase._check_call_order__subtests.<locals>.Foo.test)r   r   r   r   r"   r   )r   )r   r   r   5  s   r   )r   r   r.   r)   )r   r9   r   expected_eventsr   )r   r   _check_call_order__subtests4  s    z)Test_TestCase._check_call_order__subtestsc             C   s8   g }t |}dddddddddddg}| ||| d S )	Nr<   r   r   r!   addSubTestFailureaddSubTestSuccessr=   r>   )r   rR   )r   r   r9   r?   r   r   r   test_run_call_order__subtestsL  s    
z+Test_TestCase.test_run_call_order__subtestsc             C   s.   g }t |}ddddddg}| ||| d S )Nr<   r   r   r!   rF   r>   )r   rR   )r   r   r9   r?   r   r   r   $test_run_call_order__subtests_legacyU  s
    z2Test_TestCase.test_run_call_order__subtests_legacyc                s4   G  fdddt j  || | || d S )Nc                   s   e Zd Z fddZ  ZS )z>Test_TestCase._check_call_order__subtests_success.<locals>.Fooc                s^   t  |   xJdD ]B}| j|d, x$dD ]}| j|d W d Q R X q,W W d Q R X qW d S )N)r4   r(   )rL   )r(   r'   )rN   )r   r   rP   )r   rL   rN   )r   r   r   r   r   `  s    

zCTest_TestCase._check_call_order__subtests_success.<locals>.Foo.test)r   r   r   r   r"   r   )r   )r   r   r   _  s   r   )r   r   r.   r)   )r   r9   r   rQ   r   )r   r   #_check_call_order__subtests_success^  s    	z1Test_TestCase._check_call_order__subtests_successc             C   s<   g }t |}ddddgddg  ddg }| ||| d S )	Nr<   r   r   r!   rO   rT   
addSuccessr>   )r   rW   )r   r   r9   r?   r   r   r   %test_run_call_order__subtests_successk  s    z3Test_TestCase.test_run_call_order__subtests_successc             C   s.   g }t |}ddddddg}| ||| d S )Nr<   r   r   r!   rX   r>   )r   rW   )r   r   r9   r?   r   r   r   ,test_run_call_order__subtests_success_legacyu  s
    z:Test_TestCase.test_run_call_order__subtests_success_legacyc                sV   g }t |}d|_G  fdddtj dddddd	g} || | || d S )
NTc                   s   e Zd Z fddZ  ZS )zATest_TestCase.test_run_call_order__subtests_failfast.<locals>.Fooc          	      s`   t  |   | jdd | d W d Q R X | jdd | d W d Q R X | d d S )Nr4   )rL   rM   r(   )r   r   rP   r2   )r   )r   r   r   r   r     s    zFTest_TestCase.test_run_call_order__subtests_failfast.<locals>.Foo.test)r   r   r   r   r"   r   )r   )r   r   r     s   r   r<   r   r   r!   rS   r>   )r   failfastr   r   r.   r)   )r   r   r9   r?   r   )r   r   &test_run_call_order__subtests_failfast}  s    	z4Test_TestCase.test_run_call_order__subtests_failfastc                sV   g  G  fdddt j}t  }d|_t |}|| dddg}|  | d S )Nc                   s0   e Zd Z fddZ fddZ fddZdS )z1Test_TestCase.test_subtests_failfast.<locals>.Fooc          	      s,   |     d W d Q R X  d d S )Na1a2)rP   r    )r   )r   r   r   test_a  s    
z8Test_TestCase.test_subtests_failfast.<locals>.Foo.test_ac          	      sJ   |     d W d Q R X |    | d W d Q R X  d d S )Nb1rM   Zb2)rP   r    r2   )r   )r   r   r   test_b  s
    

z8Test_TestCase.test_subtests_failfast.<locals>.Foo.test_bc                s     d d S )Nc)r    )r   )r   r   r   test_c  s    z8Test_TestCase.test_subtests_failfast.<locals>.Foo.test_cN)r   r   r   r_   ra   rc   r   )r   r   r   r     s   r   Tr]   r^   r`   )r#   r$   r8   r[   Z	makeSuiter.   r)   )r   r   r9   Zsuiter?   r   )r   r   test_subtests_failfast  s    


z$Test_TestCase.test_subtests_failfastc                s:   g  G  fdddt j}|d  |  ddg d S )Nc                   s   e Zd Z fddZdS )z.Test_TestCase.test_subtests_debug.<locals>.Fooc          	      s,     d |     d W d Q R X d S )Nz	test casez	subtest 1)r    rP   )r   )r   r   r   r_     s    

z5Test_TestCase.test_subtests_debug.<locals>.Foo.test_aN)r   r   r   r_   r   )r   r   r   r     s   r   r_   z	test casez	subtest 1)r#   r$   debugr)   )r   r   r   )r   r   test_subtests_debug  s    z!Test_TestCase.test_subtests_debugc             C   s(   G dd dt j}| |djt d S )Nc               @   s   e Zd Zdd ZdS )z9Test_TestCase.test_failureException__default.<locals>.Fooc             S   s   d S )Nr   )r   r   r   r   r     s    z>Test_TestCase.test_failureException__default.<locals>.Foo.testN)r   r   r   r   r   r   r   r   r     s   r   r   )r#   r$   assertIsr,   AssertionError)r   r   r   r   r   test_failureException__default  s    z,Test_TestCase.test_failureException__defaultc             C   sX   g }t |}G dd dtj}| |djt |d| dddg}| || d S )Nc               @   s   e Zd Zdd ZeZdS )zMTest_TestCase.test_failureException__subclassing__explicit_raise.<locals>.Fooc             S   s
   t  d S )N)r;   )r   r   r   r   r     s    zRTest_TestCase.test_failureException__subclassing__explicit_raise.<locals>.Foo.testN)r   r   r   r   r;   r,   r   r   r   r   r     s   r   r   r<   rF   r>   )r   r#   r$   rg   r,   r;   r.   r)   )r   r   r9   r   r?   r   r   r   2test_failureException__subclassing__explicit_raise  s    
z@Test_TestCase.test_failureException__subclassing__explicit_raisec             C   sX   g }t |}G dd dtj}| |djt |d| dddg}| || d S )Nc               @   s   e Zd Zdd ZeZdS )zMTest_TestCase.test_failureException__subclassing__implicit_raise.<locals>.Fooc             S   s   |  d d S )Nr
   )r2   )r   r   r   r   r     s    zRTest_TestCase.test_failureException__subclassing__implicit_raise.<locals>.Foo.testN)r   r   r   r   r;   r,   r   r   r   r   r     s   r   r   r<   rF   r>   )r   r#   r$   rg   r,   r;   r.   r)   )r   r   r9   r   r?   r   r   r   2test_failureException__subclassing__implicit_raise  s    
z@Test_TestCase.test_failureException__subclassing__implicit_raisec             C   s    G dd dt j}|   d S )Nc               @   s   e Zd Zdd ZdS )z%Test_TestCase.test_setUp.<locals>.Fooc             S   s   d S )Nr   )r   r   r   r   r     s    z-Test_TestCase.test_setUp.<locals>.Foo.runTestN)r   r   r   r   r   r   r   r   r     s   r   )r#   r$   r   )r   r   r   r   r   
test_setUp  s    zTest_TestCase.test_setUpc             C   s    G dd dt j}|   d S )Nc               @   s   e Zd Zdd ZdS )z(Test_TestCase.test_tearDown.<locals>.Fooc             S   s   d S )Nr   )r   r   r   r   r      s    z0Test_TestCase.test_tearDown.<locals>.Foo.runTestN)r   r   r   r   r   r   r   r   r     s   r   )r#   r$   r!   )r   r   r   r   r   test_tearDown  s    zTest_TestCase.test_tearDownc             C   s(   G dd dt j}| |  t d S )Nc               @   s   e Zd Zdd ZdS )z"Test_TestCase.test_id.<locals>.Fooc             S   s   d S )Nr   )r   r   r   r   r     s    z*Test_TestCase.test_id.<locals>.Foo.runTestN)r   r   r   r   r   r   r   r   r     s   r   )r#   r$   assertIsInstancer*   str)r   r   r   r   r   test_id  s    zTest_TestCase.test_idc                s\   g t  G  fdddtj}|d }| |  ddddddg}| | d S )	Nc                   s$   e Zd ZfddZ fddZdS )z;Test_TestCase.test_run__uses_defaultTestResult.<locals>.Fooc                s     d d S )Nr   )r    )r   )r   r   r   r     s    z@Test_TestCase.test_run__uses_defaultTestResult.<locals>.Foo.testc                s    S )Nr   )r   )defaultResultr   r   r6      s    zMTest_TestCase.test_run__uses_defaultTestResult.<locals>.Foo.defaultTestResultN)r   r   r   r   r6   r   )rq   r   r   r   r     s   r   r   rA   r<   rX   r>   rB   )r   r#   r$   r.   rg   r)   )r   r   r9   r?   r   )rq   r   r    test_run__uses_defaultTestResult  s    z.Test_TestCase.test_run__uses_defaultTestResultc             C   s8   G dd dt j}t  }|d|}| || d S )Nc               @   s   e Zd Zdd ZdS )z9Test_TestCase.test_run__returns_given_result.<locals>.Fooc             S   s   d S )Nr   )r   r   r   r   r   0  s    z>Test_TestCase.test_run__returns_given_result.<locals>.Foo.testN)r   r   r   r   r   r   r   r   r   /  s   r   r   )r#   r$   r8   r.   rg   )r   r   r9   retvalr   r   r   test_run__returns_given_result-  s    z,Test_TestCase.test_run__returns_given_resultc                sD   t   t  G  fdddt j}|d }| | d S )Nc                   s"   e Zd Zdd Z fddZdS )zKTest_TestCase.test_call__invoking_an_instance_delegates_to_run.<locals>.Fooc             S   s   d S )Nr   )r   r   r   r   r   @  s    zPTest_TestCase.test_call__invoking_an_instance_delegates_to_run.<locals>.Foo.testc                s   |  |  S )N)rg   )r   r9   )resultIn	resultOutr   r   r.   C  s    zOTest_TestCase.test_call__invoking_an_instance_delegates_to_run.<locals>.Foo.runN)r   r   r   r   r.   r   )ru   rv   r   r   r   ?  s   r   r   )r#   r8   r$   rg   )r   r   rs   r   )ru   rv   r   0test_call__invoking_an_instance_delegates_to_run;  s
    z>Test_TestCase.test_call__invoking_an_instance_delegates_to_runc             C   s   |  |   d S )N)assertIsNoneshortDescription)r   r   r   r   $testShortDescriptionWithoutDocstringL  s    z2Test_TestCase.testShortDescriptionWithoutDocstringr(   z)Docstrings are omitted with -O2 and abovec             C   s   |  |  d d S )Nz7Tests shortDescription() for a method with a docstring.)r)   ry   )r   r   r   r   (testShortDescriptionWithOneLineDocstringO  s    z6Test_TestCase.testShortDescriptionWithOneLineDocstringc             C   s   |  |  d d S )Nz>Tests shortDescription() for a method with a longer docstring.)r)   ry   )r   r   r   r   *testShortDescriptionWithMultiLineDocstringW  s    	z8Test_TestCase.testShortDescriptionWithMultiLineDocstringc                sV   G dd dt       }}| ||k d fdd	}|  | | || d S )Nc               @   s   e Zd ZdS )z7Test_TestCase.testAddTypeEqualityFunc.<locals>.SadSnakeN)r   r   r   r   r   r   r   SadSnakef  s   r}   c                s    t | t |  ko kS   S )N)r7   )abmsg)r}   r   r   AllSnakesCreatedEqualj  s    zDTest_TestCase.testAddTypeEqualityFunc.<locals>.AllSnakesCreatedEqual)N)objectassertFalseZaddTypeEqualityFuncr)   )r   s1s2r   r   )r}   r   testAddTypeEqualityFunce  s    z%Test_TestCase.testAddTypeEqualityFuncc             C   s,   t  }| || | | j| j|t   d S )N)r   rg   r+   r,   )r   thingr   r   r   testAssertIsr  s    zTest_TestCase.testAssertIsc             C   s,   t  }| |t   | | j| j|| d S )N)r   ZassertIsNotr+   r,   )r   r   r   r   r   testAssertIsNotw  s    zTest_TestCase.testAssertIsNotc             C   s(   g }|  |t | | j| j |t d S )N)rn   listr+   r,   dict)r   r   r   r   r   testAssertIsInstance|  s    z"Test_TestCase.testAssertIsInstancec             C   s(   g }|  |t | | j| j |t d S )N)ZassertNotIsInstancer   r+   r,   r   )r   r   r   r   r   testAssertNotIsInstance  s    z%Test_TestCase.testAssertNotIsInstancec             C   s   dddd}|  dd |  dddd	g |  d
| | dd | dddd	g | d| | | j| j dd | | j| j dddd	g | | j| j d| | | j| jdd | | j| jdddd	g | | j| jd| d S )NZbananaZgrassZfish)monkeycowZsealr~   abcr(   r4   r'   r   dr   Zotterx   Zelephantrb   r   )assertInassertNotInr+   r,   )r   Zanimalsr   r   r   testAssertIn  s    zTest_TestCase.testAssertInc          
   C   s  t   t dt | i i  | i ddi | ddiddi | ddiddd | dddddd | | j | ddii  W d Q R X | | j | ddiddi W d Q R X | | j | ddiddi W d Q R X | | j | dddddi W d Q R X | | j | dddddi W d Q R X d	d
d tdD }| | j | d|iddi W d Q R X W d Q R X d S )Nignorer~   r4   r(   )r~   r   onerb   )r~   rb    c             s   s   | ]}t |V  qd S )N)chr).0rL   r   r   r   	<genexpr>  s    z=Test_TestCase.testAssertDictContainsSubset.<locals>.<genexpr>   r
   u   �)	warningscatch_warningssimplefilterDeprecationWarningassertDictContainsSubsetr+   r,   joinrange)r   r   r   r   r   testAssertDictContainsSubset  s(      z*Test_TestCase.testAssertDictContainsSubsetc          	   C   s  di i fg g ft  t  ft t fg}x|D ]\}}y| || W n( | jk
rl   | d||f  Y nX y| j||dd W n( | jk
r   | d||f  Y nX y| ||d W q, | jk
r   | d||f  Y q,X q,W dg fi t  ft dd	gtdd
gftddgt d
dgft ddgt ddgfg}xT|D ]L\}}| | j| j|| | | j| j||d | j| j| j||dd qFW d S )N)r   r   zassertEqual(%r, %r) failedr
   )r   z$assertEqual(%r, %r) with msg= failedz/assertEqual(%r, %r) with third parameter failedr   r   r4   r(      r'   )set	frozensetr)   r,   r2   r+   )r   Zequal_pairsr~   r   Zunequal_pairsr   r   r   testAssertEqual  s<    
zTest_TestCase.testAssertEqualc             C   s  |  g g  | dd | g d ddg g}g }| tjj| j || | tjj| j t|t| | tjj| j|t| || |  || | t|t| | |t| | t|| | | j| j |t| | | j| jt|| | | j| j d | | | j| jd t| | | j| jd t| | | j| j dd | | j| jdd | | j| jdd | 	i i  ddi}i }| tjj| j	|| |
| | 	|| d|d< | tjj| j	||d | | j| j	d | | | j| j	g | | | j| j	dd d S )Nr   r   r~   r4   r   zThese are unequal)assertListEqualassertTupleEqualassertSequenceEqualr+   r#   r$   r,   tupleextendassertDictEqualupdate)r   r~   r   rb   r   r   r   r   testEquality  sT    








zTest_TestCase.testEqualityc          
   C   s  |  | jd ddd  }ddd  }dtt| t| }tj	j
t|d f }t|d | _y| || W n. | jk
r } z|jd	 }W d d }~X Y nX | d
 | t|t| | || t|d | _y| || W n0 | jk
r( } z|jd	 }W d d }~X Y nX | d
 | t|t| | || d | _y| || W n0 | jk
r } z|jd	 }W d d }~X Y nX | d
 | t|t| | || d S )Ni  r~   r   i   r   
r4   r(   r   z!assertSequenceEqual did not fail.)r)   maxDiffr   difflibZndiffpprintZpformat
splitlinesr#   caseDIFF_OMITTEDlenr   r,   argsr2   
assertLessr   assertGreaterr   )r   Zseq1Zseq2diffomitteder   r   r   r   testAssertSequenceEqualMaxDiff  s<    


z,Test_TestCase.testAssertSequenceEqualMaxDiffc             C   sr   d| _ | dd}tjjtd }| |d|  d | _ | dd}| |d d| _ | dd}| |d d S )Nr4   r
   barfoobarr   )r   _truncateMessager#   r   r   r   r)   )r   messager   r   r   r   testTruncateMessage<  s    z!Test_TestCase.testTruncateMessagec          
   C   sp   t d}dd }||_y|i ddi W n4 | jk
r` } z| t|d W d d }~X Y nX | d d S )Nr)   c             S   s   dS )Nr
   r   )r   r   r   r   r   truncateL  s    z<Test_TestCase.testAssertDictEqualTruncates.<locals>.truncater4   r   r
   zassertDictEqual did not fail)r#   r$   r   r   r,   r)   ro   r2   )r   r   r   r   r   r   r   testAssertDictEqualTruncatesJ  s    
"z*Test_TestCase.testAssertDictEqualTruncatesc          
   C   sl   t d}dd }||_y|dd W n4 | jk
r\ } z| t|d W d d }~X Y nX | d d S )Nr)   c             S   s   dS )Nr
   r   )r   r   r   r   r   r   X  s    zATest_TestCase.testAssertMultiLineEqualTruncates.<locals>.truncater
   r   z!assertMultiLineEqual did not fail)r#   r$   r   assertMultiLineEqualr,   r)   ro   r2   )r   r   r   r   r   r   r   !testAssertMultiLineEqualTruncatesV  s    
"z/Test_TestCase.testAssertMultiLineEqualTruncatesc          	      s0   jd d _j d_ fdd d}j} |d |d  W d Q R X dt|j  |d |d  d	}d
d }j	|_	fdd |d |d  }}j} || W d Q R X 
dt|j  t|jd||f   |d |d  d S )Ni       c                  s   t d S )N_diffThreshold)setattrr   )old_thresholdr   r   r   <lambda>k  r   z=Test_TestCase.testAssertEqual_diffThreshold.<locals>.<lambda>Zxxxxxxxxxxxxxxxxr~   r   ^Z@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxc             S   s   t dd S )Nzthis should not be raised)SystemError)r   r   r   r   r   explodingTruncationy  s    zHTest_TestCase.testAssertEqual_diffThreshold.<locals>.explodingTruncationc                  s   t d S )Nr   )r   r   )old_truncater   r   r   r   }  r   z%r != %r)r)   r   r   
addCleanupr+   r,   r   ro   	exceptionr   r   )r   scmr   r   r   r   )r   r   r   r   testAssertEqual_diffThresholdb  s*    z+Test_TestCase.testAssertEqual_diffThresholdc          	      s\  j  d_  fdd d}|d |d  }}j}|| W d Q R X d}t|jd||f  |d |d  d	}|d | |d |  }}j}|| W d Q R X d
}t|jd||||f  d}|d | |d |  }}j}|| W d Q R X d}d}t|jd||||f  d S )Nr   c                  s   t d S )Nr   )r   r   )r   r   r   r   r     r   z7Test_TestCase.testAssertEqual_shorten.<locals>.<lambda>Zdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr~   r   zKxxxx[35 chars]xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz'%sa' != '%sb'Z2yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyzxxxx[85 chars]xxxxxxxxxxxz'%sa%s' != '%sb%s'Zdyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyzxxxx[91 chars]xxxxxz6yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy[56 chars]yyyy)r   r   r+   r,   r)   ro   r   )r   r   r   r   r   rb   pr   r   )r   r   r   testAssertEqual_shorten  s.    z%Test_TestCase.testAssertEqual_shortenc             C   s  t  }| dddgdddg | dddgdddg | ||dddg|dd|df | ddddgddd	dg | | j| jddgdgd
  dgd
 ddg  | | j| jddddgddd	dg | | j| jdgddg | | j| jddgdg | | j| jdddgddg | ddgddgdgdddgddgg | tddg ddgtddg ddg | | j| jg tddddt g | ddiddigddiddig | ddtg gtg ddg | | j| jg tg ddddt g | | j| jdggdgg | | j| jdddgddg | | j| jdddddgddd	dg | | j| jdddid d	gddid	d g ddhddhg}|d d d }| || ttj	
dd}ddddh}| || tj	
g gg }| |ddg fg ttj	dd}ddddh}| || d S )Nr4   r(   r'   r
   r   Zbaz2r~   Td   
      r   r   Fr   y              @y               @r   ZaaabccdZabbbcce)r'   r4   r~   )r4   r'   r   )r4   r   r   )r   r4   r   )r   assertCountEqualr+   r,   iterdivmodr   r   r#   utilZ_count_diff_all_purposer)   Z_count_diff_hashable)r   r~   r   Zdiffsr?   r   r   r   testAssertCountEqual  sV     $($z"Test_TestCase.testAssertCountEqualc             C   s  t  }t  }| || | | j| jd | | | j| jg | | | j| j|d  | | j| j|g  t dg}t  }| | j| j|| t dg}t dg}| || t dg}t ddg}| | j| j|| t dg}tddg}| | j| j|| t ddg}tddg}| || t  }d}| | j| j|| | | j| j|| t ddg}t dg}| | j| j|| d S )Nr~   r   r
   )r   r4   )r(   r'   )r   r   )r   assertSetEqualr+   r,   r   )r   Zset1Zset2r   r   r   testAssertSetEqual  s:    





z Test_TestCase.testAssertSetEqualc             C   s  |  dd | dd | dd | dd | dd | dd | | j| j dd | | j| j dd | | j| jdd | | j| jdd | | j| jdd | | j| jdd |  dd | dd | dd | dd | dd | dd | | j| j dd | | j| j dd | | j| jdd | | j| jdd | | j| jdd | | j| jdd |  dd | dd | dd | dd | dd | dd | | j| j dd | | j| j dd | | j| jdd | | j| jdd | | j| jdd | | j| jdd |  dd | dd | dd | dd | dd | dd | | j| j dd | | j| j dd | | j| jdd | | j| jdd | | j| jdd | | j| jdd d S )	Nr(   r4   g?g      ?ZbugZants   bugs   ant)r   ZassertGreaterEqualr   ZassertLessEqualr+   r,   )r   r   r   r   testInequality	  sb    zTest_TestCase.testInequalityc          
   C   sl   d}d}d}d | _ y| || W nD | jk
rf } z$t|ddd }| || W d d }~X Y nX d S )Nzxhttp://www.python.org/doc/2.3/lib/module-unittest.html
test case
    A test case is the smallest unit of testing. [...]
zhttp://www.python.org/doc/2.4.1/lib/module-unittest.html
test case
    A test case is the smallest unit of testing. [...] You may provide your
    own implementation that does not subclass from TestCase, of course.
a  - http://www.python.org/doc/2.3/lib/module-unittest.html
?                             ^
+ http://www.python.org/doc/2.4.1/lib/module-unittest.html
?                             ^^^
  test case
-     A test case is the smallest unit of testing. [...]
+     A test case is the smallest unit of testing. [...] You may provide your
?                                                       +++++++++++++++++++++
+     own implementation that does not subclass from TestCase, of course.
r   r4   )r   r   r,   ro   splitr)   )r   sample_textrevised_sample_textsample_text_errorr   errorr   r   r   testAssertMultiLineEqualC  s    z&Test_TestCase.testAssertMultiLineEqualc          
   C   sf   d}d}d}y|  || W nD | jk
r` } z$t|ddd }|  || W d d }~X Y nX d S )Nzladen swallows fly slowlyzunladen swallows fly quicklyzr- laden swallows fly slowly
?                    ^^^^
+ unladen swallows fly quickly
? ++                   ^^^^^
r   r4   )r)   r,   ro   r   )r   r   r   r   r   r   r   r   r   testAssertEqualSingleLineb  s    z'Test_TestCase.testAssertEqualSingleLinec          
      sH  t jjr fdd}ndd }| *   j  dd W d Q R X W d Q R X |   dd W d Q R X ddg}ddg}| *   j  || W d Q R X W d Q R X | 2   j  t	|t	| W d Q R X W d Q R X | .   j  
|t	| W d Q R X W d Q R X | .   j  
t	|| W d Q R X W d Q R X | *   j  
dd W d Q R X W d Q R X | 2   j  t|t| W d Q R X W d Q R X   j  |t	| W d Q R X   j  t	|| W d Q R X ddg}dg}  j  || W d Q R X   j  t	|t	| W d Q R X   j  
|t	| W d Q R X   j  
t	|| W d Q R X   j  t|t| W d Q R X dg}ddg}  j  || W d Q R X   j  t	|t	| W d Q R X   j  
|t	| W d Q R X   j  
t	|| W d Q R X   j  t|t| W d Q R X | 2   j  ddiddi W d Q R X W d Q R X   j  i ddi W d Q R X   j  ddii  W d Q R X   j  ddgdddg W d Q R X |   ddgddg W d Q R X | 2   j  ddgddg W d Q R X W d Q R X | 6   j  ddg gddg g W d Q R X W d Q R X d S )Nc                  s     tdS )Nz#Comparison between bytes and string)assertWarnsRegexBytesWarningr   )r   r   r   bytes_warningt  s    z=Test_TestCase.testEqualityBytesWarning.<locals>.bytes_warningc               S   s   t  S )N)
contextlib	ExitStackr   r   r   r   r   x  s    r~      ar   )sysflagsr   r+   r,   r)   ZassertNotEqualr   r   r   r   r   r   r   r   )r   r   r~   r   r   )r   r   testEqualityBytesWarningr  s~      ($$ (( (z&Test_TestCase.testEqualityBytesWarningc             C   s<   |  d  | | j| j d | d | | j| jd  d S )NFzDjZoPloGears on Rails)rx   r+   r,   ZassertIsNotNone)r   r   r   r   testAssertIsNone  s    

zTest_TestCase.testAssertIsNonec             C   s$   |  dd | | j| j dd d S )NZ
asdfabasdfzab+ZsaaasZaaaa)ZassertRegexr+   r,   )r   r   r   r   testAssertRegex  s    zTest_TestCase.testAssertRegexc          	      s   G dd dt   fdd}|  | | t f| | jttddd | | j |  dd	  W d Q R X | t |  d  W d Q R X |   | t| W d Q R X d S )
Nc               @   s   e Zd ZdS )z=Test_TestCase.testAssertRaisesCallable.<locals>.ExceptionMockN)r   r   r   r   r   r   r   ExceptionMock  s   r   c                  s    dd S )Nz	We expectr   r   )r   r   r   Stub  s    z4Test_TestCase.testAssertRaisesCallable.<locals>.Stub19   )basec               S   s   dS )Nr   r   r   r   r   r   r     r   z8Test_TestCase.testAssertRaisesCallable.<locals>.<lambda>)	Exceptionr+   r1   intr,   assertWarnsr   )r   r   r   )r   r   testAssertRaisesCallable  s    z&Test_TestCase.testAssertRaisesCallablec                sl  G dd dt   fdd}|   |  W d Q R X | t f}|  W d Q R X | |j  | |jjd d | t tddd	 W d Q R X | | j |   W d Q R X W d Q R X | 	| jd
  | j d
d W d Q R X W d Q R X | 
td
6 | t  | j dd W d Q R X W d Q R X W d Q R X |   | t| W d Q R X d S )Nc               @   s   e Zd ZdS )z<Test_TestCase.testAssertRaisesContext.<locals>.ExceptionMockN)r   r   r   r   r   r   r   r     s   r   c                  s    dd S )Nz	We expectr   r   )r   r   r   r     s    z3Test_TestCase.testAssertRaisesContext.<locals>.Stubr   z	We expectr   r   )r   r   )r   *   )r   )r   r+   r1   rn   r   r)   r   r   r,   assertRaisesRegexr   r   rh   )r   r   r   r   )r   r   testAssertRaisesContext  s,    z%Test_TestCase.testAssertRaisesContextc          	   C   s   |  t |    W d Q R X |  t |  d W d Q R X |  t |  t W d Q R X |  t |  tdf W d Q R X |  t |  ttf W d Q R X d S )Nr4   )r+   	TypeErrorr   r1   )r   r   r   r   testAssertRaisesNoExceptionType  s    z-Test_TestCase.testAssertRaisesNoExceptionTypec             C   s4   dd }t |}| t| | |t | d S )Nc               S   s&   yt W n t k
r    t Y nX d S )N)r1   r   r   r   r   func  s    z4Test_TestCase.testAssertRaisesRefcount.<locals>.func)r   getrefcountr+   r1   r)   )r   r  Zrefcountr   r   r   testAssertRaisesRefcount
  s    
z&Test_TestCase.testAssertRaisesRefcountc          	      sf   G dd dt   fdd}|  td| |  d| | t |  dd  W d Q R X d S )Nc               @   s   e Zd ZdS )z:Test_TestCase.testAssertRaisesRegex.<locals>.ExceptionMockN)r   r   r   r   r   r   r   r     s   r   c                  s    dd S )Nz	We expectr   r   )r   r   r   r     s    z1Test_TestCase.testAssertRaisesRegex.<locals>.Stubzexpect$)r   r  recompiler   r   )r   r   r   )r   r   testAssertRaisesRegex  s    z#Test_TestCase.testAssertRaisesRegexc             C   s   |  | jd| j ttddd  |  | jd| j tddd  |  | jd" | j tddd W d Q R X W d Q R X | td8 | t" | j tdd	d
 W d Q R X W d Q R X W d Q R X d S )Nz"^Exception not raised by <lambda>$r   c               S   s   d S )Nr   r   r   r   r   r   '  r   z8Test_TestCase.testAssertNotRaisesRegex.<locals>.<lambda>c               S   s   d S )Nr   r   r   r   r   r   +  r   r   expect)r   r  )r   )	r  r,   r   r
  r  r   r   r+   rh   )r   r   r   r   testAssertNotRaisesRegex#  s    

z&Test_TestCase.testAssertNotRaisesRegexc             C   s*   G dd dt }| t| j|dd  d S )Nc               @   s   e Zd ZdS )z>Test_TestCase.testAssertRaisesRegexInvalidRegex.<locals>.MyExcN)r   r   r   r   r   r   r   MyExc8  s   r  c               S   s   dS )NTr   r   r   r   r   r   :  r   zATest_TestCase.testAssertRaisesRegexInvalidRegex.<locals>.<lambda>)r   r+   r  r  )r   r  r   r   r   !testAssertRaisesRegexInvalidRegex6  s    z/Test_TestCase.testAssertRaisesRegexInvalidRegexc             C   s*   G dd dt }| t| j|dd  d S )Nc               @   s   e Zd ZdS )z>Test_TestCase.testAssertWarnsRegexInvalidRegex.<locals>.MyWarnN)r   r   r   r   r   r   r   MyWarn>  s   r  c               S   s   dS )NTr   r   r   r   r   r   @  r   z@Test_TestCase.testAssertWarnsRegexInvalidRegex.<locals>.<lambda>)Warningr+   r  r   )r   r  r   r   r    testAssertWarnsRegexInvalidRegex<  s    z.Test_TestCase.testAssertWarnsRegexInvalidRegexc          	   C   sB   dd }|  | jd| j td| |  | jd| j ttd| d S )Nc               S   s   t dd S )NZ
Unexpected)r   r   r   r   r   r   C  s    z9Test_TestCase.testAssertRaisesRegexMismatch.<locals>.Stubz*"\^Expected\$" does not match "Unexpected"z
^Expected$)r  r,   r   r
  r  )r   r   r   r   r   testAssertRaisesRegexMismatchB  s    z+Test_TestCase.testAssertRaisesRegexMismatchc          	      sj   G dd dt   fdd}d}|  }| || W d Q R X |j}| |  | |jd | d S )Nc               @   s   e Zd ZdS )z=Test_TestCase.testAssertRaisesExcValue.<locals>.ExceptionMockN)r   r   r   r   r   r   r   r   R  s   r   c                s    | d S )Nr   )r
   )r   r   r   r   U  s    z4Test_TestCase.testAssertRaisesExcValue.<locals>.Stubzparticular valuer   )r   r+   r   rn   r)   r   )r   r   vZctxr   r   )r   r   testAssertRaisesExcValueQ  s    
z&Test_TestCase.testAssertRaisesExcValuec          	   C   s   |  t |   W d Q R X |  t | t W d Q R X |  t | dd W d Q R X |  t | td W d Q R X |  t | tdfd W d Q R X |  t | ttfd W d Q R X d S )Nr4   r  )r+   r  r  r1   r   )r   r   r   r   $testAssertRaisesRegexNoExceptionType`  s    z2Test_TestCase.testAssertRaisesRegexNoExceptionTypec          
   C   s  dd }|  t| |  t| |  ttf| | j ttjdtd | | j |  tdd  W d Q R X |  t |  td  W d Q R X t 6 tdt | | j |  t| W d Q R X W d Q R X t 4 tdt | t |  t| W d Q R X W d Q R X d S )	Nc               S   s   t dt d S )Nr
   )r   warnRuntimeWarningr   r   r   r   _runtime_warno  s    z<Test_TestCase.testAssertWarnsCallable.<locals>._runtime_warnr
   )categoryc               S   s   dS )Nr   r   r   r   r   r   r   {  r   z7Test_TestCase.testAssertWarnsCallable.<locals>.<lambda>defaultr   )	r   r  r   r   r  r+   r,   r   r   )r   r  r   r   r   testAssertWarnsCallablen  s$    
 
z%Test_TestCase.testAssertWarnsCallablec             C   s.  dd }t |d }| t}|  W d Q R X | ttf}|  W d Q R X | |jt | |jjd d | 	d|j
 | |j|d  | t |  |  W d Q R X | t tjdtd W d Q R X | | j | t W d Q R X W d Q R X | | jd  | jtdd	 W d Q R X W d Q R X | td6 | t  | jtd
d W d Q R X W d Q R X W d Q R X t F tdt | | j" | t |  W d Q R X W d Q R X W d Q R X t D tdt | t" | t |  W d Q R X W d Q R X W d Q R X d S )Nc               S   s   t dt d S )Nr
   )r   r  r  r   r   r   r   r    s    z;Test_TestCase.testAssertWarnsContext.<locals>._runtime_warnr4   r   r
   ztest_case.py)r  r   )r   r  )r   r  r   )inspectgetsourcelinesr   r  r   rn   warningr)   r   r   filenamelinenor   r  r+   r,   r  r   rh   r   r   )r   r  _runtime_warn_linenor   r   r   r   testAssertWarnsContext  sF    
$
z$Test_TestCase.testAssertWarnsContextc          	   C   s   |  t |   W d Q R X |  t | d W d Q R X |  t | t W d Q R X |  t | tdf W d Q R X |  t | ttf W d Q R X |  t | ttf W d Q R X d S )Nr4   )r+   r  r   r   UserWarningr   )r   r   r   r   testAssertWarnsNoExceptionType  s    z,Test_TestCase.testAssertWarnsNoExceptionTypec          
   C   s&  dd }|  td|d | | j |  tddd  W d Q R X | t |  tdd  W d Q R X t : tdt | | j |  td|d W d Q R X W d Q R X | | j |  td|d W d Q R X t > td	t | t| jf |  td|d W d Q R X W d Q R X d S )
Nc             S   s   t | t d S )N)r   r  r  )r   r   r   r   r    s    zATest_TestCase.testAssertWarnsRegexCallable.<locals>._runtime_warnzo+fooxc               S   s   dS )Nr   r   r   r   r   r   r     r   z<Test_TestCase.testAssertWarnsRegexCallable.<locals>.<lambda>r  barzr   )	r   r  r+   r,   r   r   r   r   r   )r   r  r   r   r   testAssertWarnsRegexCallable  s*    

z*Test_TestCase.testAssertWarnsRegexCallablec             C   s  dd }t |d }| td}|d W d Q R X | |jt | |jjd d | d|j	 | |j
|d  | | j | td W d Q R X W d Q R X | | jd" | jtddd	 W d Q R X W d Q R X | td8 | t" | jtdd
d W d Q R X W d Q R X W d Q R X t J tdt | | j& | td |d W d Q R X W d Q R X W d Q R X | | j& | td |d W d Q R X W d Q R X t N tdt | t| jf& | td |d W d Q R X W d Q R X W d Q R X d S )Nc             S   s   t | t d S )N)r   r  r  )r   r   r   r   r    s    z@Test_TestCase.testAssertWarnsRegexContext.<locals>._runtime_warnr4   zo+r'  r   ztest_case.pyr   )r   r  )r   r  r(  r   )r  r  r   r  rn   r   r)   r   r   r!  r"  r+   r,   r  r   rh   r   r   r   )r   r  r#  r   r   r   r   testAssertWarnsRegexContext  s>    
&
z)Test_TestCase.testAssertWarnsRegexContextc          	   C   s   |  t |   W d Q R X |  t | t W d Q R X |  t | dd W d Q R X |  t | td W d Q R X |  t | tdfd W d Q R X |  t | ttfd W d Q R X |  t | ttfd W d Q R X d S )Nr4   r  )r+   r  r   r%  r   r   )r   r   r   r   #testAssertWarnsRegexNoExceptionType  s    z1Test_TestCase.testAssertWarnsRegexNoExceptionTypec          	   c   s,   t  }d V  W d Q R X | | d d S )Nr   )r	   r)   getvalue)r   bufr   r   r   assertNoStderr(  s    zTest_TestCase.assertNoStderrc             C   sf   |  t|t| xLt||D ]>\}}| |tj x&| D ]\}}|  t||| q@W q W d S )N)r)   r   ziprn   loggingZ	LogRecorditemsgetattr)r   recordsmatchesZrecmatchkr  r   r   r   assertLogRecords.  s
    zTest_TestCase.assertLogRecordsc          
   C   sd   |   R |  }td td W d Q R X | |jdg | |j	ddig W d Q R X d S )N1r   z
INFO:foo:1namer
   )
r.  
assertLogslog_fooinfo
log_foobarre   r)   outputr7  r3  )r   r   r   r   r   testAssertLogsDefaults5  s    


z$Test_TestCase.testAssertLogsDefaultsc          
   C   sv   |   d |  $}td td td W d Q R X | |j	ddg | 
|jddiddig W d Q R X d S )	Nr8  r   3z
INFO:foo:1zWARNING:quux:3r9  r
   r   )r.  r:  r;  r<  r=  re   log_quuxr   r)   r>  r7  r3  )r   r   r   r   r   !testAssertLogsTwoMatchingMessages>  s    



z/Test_TestCase.testAssertLogsTwoMatchingMessagesc          
   C   sz   |   h | j|d$}td td td W d Q R X | |j	ddg | 
|jddidd	ig W d Q R X d S )
N)levelr8  r   r@  zERROR:foo.bar:2zCRITICAL:quux:3r9  zfoo.barr   )r.  r:  r;  r   r=  r   rA  Zcriticalr)   r>  r7  r3  )r   rC  r   r   r   r   checkAssertLogsPerLevelI  s    


z%Test_TestCase.checkAssertLogsPerLevelc             C   s   |  tj |  d d S )NERROR)rD  r0  rE  )r   r   r   r   testAssertLogsPerLevelT  s    z$Test_TestCase.testAssertLogsPerLevelc             C   s   |    | jddj}| j|dd$}td td td W d Q R X | |j	ddg | 
|jdd	idd
ig W d Q R X | |j	dg W d Q R X d S )NDEBUG)rC  r8  r   r@  z
INFO:foo:1zDEBUG:foo.bar:2r9  r
   zfoo.barzWARNING:quux:3)r.  r:  r;  r<  r=  re   rA  r   r)   r>  r7  r3  )r   ZloggerZouter_cmr   r   r   r   checkAssertLogsPerLoggerX  s    


z&Test_TestCase.checkAssertLogsPerLoggerc             C   s   |  td |  d d S )Nr
   )rH  r0  	getLogger)r   r   r   r   testAssertLogsPerLoggerf  s    z%Test_TestCase.testAssertLogsPerLoggerc             C   sD   |   2 | | j |   W d Q R X W d Q R X W d Q R X d S )N)r.  r+   r,   r:  )r   r   r   r   testAssertLogsFailureNoLogsj  s    

z)Test_TestCase.testAssertLogsFailureNoLogsc             C   sR   |   @ | | j( | jdd td W d Q R X W d Q R X W d Q R X d S )NZWARNING)rC  r8  )r.  r+   r,   r:  r;  r<  )r   r   r   r   !testAssertLogsFailureLevelTooHighq  s    
z/Test_TestCase.testAssertLogsFailureLevelTooHighc             C   sV   | j ddd> | | j& |  d td W d Q R X W d Q R X W d Q R X d S )Nr   rE  )rC  r
   r8  )r:  r+   r,   rA  r   )r   r   r   r   &testAssertLogsFailureMismatchingLoggerx  s    z4Test_TestCase.testAssertLogsFailureMismatchingLoggerc             C   s   | j df| jdf| jdf| jdf| jdf| jdf| jdf| jdf| jdf| j	df| j
tdd ff| jdf| jtd	d
dtd	d
ddff| jtddd ff| jdff}x.|D ]&\}}| t ||  W d Q R X qW d S )N)r'   r   )r'   r'   )g       @g       @)g      @g      @)Tc             S   s   dd S )NgQ	@Zspamr   )_r   r   r   r     r   z9Test_TestCase.testDeprecatedMethodNames.<locals>.<lambda>)Fr4   r(   )r~   r   r'   )r~   r   rb   r
   c               S   s   i d S )Nr
   r   r   r   r   r   r     r   )r   r   )failIfEqualZassertNotEqualsfailUnlessEqualZassertEqualsfailUnlessAlmostEqualZassertAlmostEqualsfailIfAlmostEqualZassertNotAlmostEquals
failUnlessZassert_failUnlessRaisesr  failIfr   r   ZassertRaisesRegexpKeyErrorZassertRegexpMatchesr   r   )r   oldZmethr   r   r   r   testDeprecatedMethodNames  s$    z'Test_TestCase.testDeprecatedMethodNamesc          
   C   s\   t jd d dk rd S ddddddd	d
g}x,|D ]$}| t t| | W d Q R X q0W d S )Nr(   )r'   r'   rO  rP  rQ  rR  rS  rT  rU  r   )r   version_infor+   r-   r2  )r   Zdeprecated_namesZdeprecated_namer   r   r   _testDeprecatedFailMethods  s    
z(Test_TestCase._testDeprecatedFailMethodsc             C   s&   G dd dt j}|d}t| d S )Nc               @   s   e Zd Zdd ZdS )z0Test_TestCase.testDeepcopy.<locals>.TestableTestc             S   s   d S )Nr   )r   r   r   r   testNothing  s    z<Test_TestCase.testDeepcopy.<locals>.TestableTest.testNothingN)r   r   r   r[  r   r   r   r   TestableTest  s   r\  r[  )r#   r$   r   )r   r\  r   r   r   r   testDeepcopy  s    zTest_TestCase.testDeepcopyc             C   sZ   t d}xJttjd D ]8}tj||d}t|}| || |t t  qW d S )Nr.   r4   )protocol)	r#   r$   r   pickleZHIGHEST_PROTOCOLdumpsloadsr)   r   )r   r   r^  Zpickled_testZunpickled_testr   r   r   
testPickle  s    

zTest_TestCase.testPicklec          
      s   ddd dd G  fdddt j}G  fdddt j}G  fd	d
d
t j}G  fdddt j}x6||||fD ]&}| t |d  W d Q R X q|W d S )Nc             S   s   t d S )N)KeyboardInterrupt)r   r   r   r   _raise  s    z3Test_TestCase.testKeyboardInterrupt.<locals>._raisec             S   s   d S )Nr   )r   r   r   r   nothing  s    z4Test_TestCase.testKeyboardInterrupt.<locals>.nothingc                   s   e Zd Z ZdS )z2Test_TestCase.testKeyboardInterrupt.<locals>.Test1N)r   r   r   test_somethingr   )rd  r   r   Test1  s   rg  c                   s   e Zd Z ZZdS )z2Test_TestCase.testKeyboardInterrupt.<locals>.Test2N)r   r   r   r   rf  r   )rd  re  r   r   Test2  s   rh  c                   s   e Zd ZZ ZdS )z2Test_TestCase.testKeyboardInterrupt.<locals>.Test3N)r   r   r   rf  r!   r   )rd  re  r   r   Test3  s   ri  c                   s   e Zd Z fddZdS )z2Test_TestCase.testKeyboardInterrupt.<locals>.Test4c                s   |    d S )N)r   )r   )rd  r   r   rf    s    zATest_TestCase.testKeyboardInterrupt.<locals>.Test4.test_somethingN)r   r   r   rf  r   )rd  r   r   Test4  s   rj  rf  )N)r#   r$   r+   rc  r.   )r   rg  rh  ri  rj  klassr   )rd  re  r   testKeyboardInterrupt  s    
z#Test_TestCase.testKeyboardInterruptc                s   ddd dd G  fdddt j}G  fdddt j}G  fd	d
d
t j}G  fdddt j}xJ||||fD ]:}t  }|d| | t|jd | |jd q|W d S )Nc             S   s   t dd S )Nzsome reason)r#   ZSkipTest)r   r   r   r   _skip  s    z3Test_TestCase.testSkippingEverywhere.<locals>._skipc             S   s   d S )Nr   )r   r   r   r   re    s    z5Test_TestCase.testSkippingEverywhere.<locals>.nothingc                   s   e Zd Z ZdS )z3Test_TestCase.testSkippingEverywhere.<locals>.Test1N)r   r   r   rf  r   )rm  r   r   rg    s   rg  c                   s   e Zd Z ZZdS )z3Test_TestCase.testSkippingEverywhere.<locals>.Test2N)r   r   r   r   rf  r   )rm  re  r   r   rh    s   rh  c                   s   e Zd ZZ ZdS )z3Test_TestCase.testSkippingEverywhere.<locals>.Test3N)r   r   r   rf  r!   r   )rm  re  r   r   ri    s   ri  c                   s   e Zd Z fddZdS )z3Test_TestCase.testSkippingEverywhere.<locals>.Test4c                s   |    d S )N)r   )r   )rm  r   r   rf    s    zBTest_TestCase.testSkippingEverywhere.<locals>.Test4.test_somethingN)r   r   r   rf  r   )rm  r   r   rj    s   rj  rf  r4   )N)r#   r$   r8   r.   r)   r   ZskippedtestsRun)r   rg  rh  ri  rj  rk  r9   r   )rm  re  r   testSkippingEverywhere  s    
z$Test_TestCase.testSkippingEverywherec                s   ddd dd G  fdddt j}G  fdddt j}G  fd	d
d
t j}G  fdddt j}xJ||||fD ]:}t  }|d| | t|jd | |jd q|W d S )Nc             S   s   t d S )N)
SystemExit)r   r   r   r   rd    s    z,Test_TestCase.testSystemExit.<locals>._raisec             S   s   d S )Nr   )r   r   r   r   re    s    z-Test_TestCase.testSystemExit.<locals>.nothingc                   s   e Zd Z ZdS )z+Test_TestCase.testSystemExit.<locals>.Test1N)r   r   r   rf  r   )rd  r   r   rg    s   rg  c                   s   e Zd Z ZZdS )z+Test_TestCase.testSystemExit.<locals>.Test2N)r   r   r   r   rf  r   )rd  re  r   r   rh    s   rh  c                   s   e Zd ZZ ZdS )z+Test_TestCase.testSystemExit.<locals>.Test3N)r   r   r   rf  r!   r   )rd  re  r   r   ri    s   ri  c                   s   e Zd Z fddZdS )z+Test_TestCase.testSystemExit.<locals>.Test4c                s   |    d S )N)r   )r   )rd  r   r   rf  
  s    z:Test_TestCase.testSystemExit.<locals>.Test4.test_somethingN)r   r   r   rf  r   )rd  r   r   rj  	  s   rj  rf  r4   )N)r#   r$   r8   r.   r)   r   errorsrn  )r   rg  rh  ri  rj  rk  r9   r   )rd  re  r   testSystemExit  s    
zTest_TestCase.testSystemExitc          	   C   s8   t  }t|}t  ~| |  W d Q R X d S )N)r#   r$   weakrefrefr   Z
disable_gcr   )r   r   Zwrr   r   r   testNoCycles  s
    

zTest_TestCase.testNoCyclesc                sZ   G  fdddt  G  fdddtj}x*dD ]"}||}|  |  jd q0W d S )Nc                   s(   e Zd ZdZ fddZ fddZdS )z9Test_TestCase.test_no_exception_leak.<locals>.MyExceptionr   c                s     j d7  _ t|  d S )Nr4   )	ninstancer   r   )r   )r&   r   r   r   !  s    zBTest_TestCase.test_no_exception_leak.<locals>.MyException.__init__c                s     j d8  _ d S )Nr4   )rv  )r   )r&   r   r   __del__%  s    zATest_TestCase.test_no_exception_leak.<locals>.MyException.__del__N)r   r   r   rv  r   rw  r   )r&   r   r   r&     s   r&   c                   s*   e Zd Z fddZej fddZdS )z6Test_TestCase.test_no_exception_leak.<locals>.TestCasec                s
     d S )Nr   )r   )r&   r   r   r   )  s    z<Test_TestCase.test_no_exception_leak.<locals>.TestCase.test1c                s
     d S )Nr   )r   )r&   r   r   r   ,  s    z<Test_TestCase.test_no_exception_leak.<locals>.TestCase.test2N)r   r   r   r   r#   ZexpectedFailurer   r   )r&   r   r   r$   (  s   r$   )r   r   r   )r   r#   r$   r.   r)   rv  )r   r$   Zmethod_nameZtestcaser   )r&   r   test_no_exception_leak  s    

z$Test_TestCase.test_no_exception_leakN)pr   r   r   r   r   Zeq_pairsr   Zne_pairsr/   r0   r3   r5   r:   r@   rC   rD   rE   rG   rH   rI   rJ   rK   rR   rU   rV   rW   rY   rZ   r\   rd   rf   ri   rj   rk   rl   rm   rp   rr   rt   rw   rz   r#   ZskipIfr   r   optimizer{   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r	  r  r  r  r  r  r  r  r  r$  r&  r)  r*  r+  r   contextmanagerr.  r7  r?  rB  rD  rF  rH  rJ  rK  rL  rM  rX  rZ  r]  rb  rl  ro  rr  r   Zcpython_onlyru  rx  r   r   r   r   r%   8   s   

		
	%4($>(:L!1!-	r%   __main__)!r   r   r   r_  r
  r   r0  r   rs  r  copyr   r   r   r#   Zunittest.test.supportr   r   r   r   r   Ztest.supportr	   rI  r;  r=  rA  r   r   r$   r%   r   mainr   r   r   r   <module>   sF   


              