a
    "h#                     @   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
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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
gc_collectfoofoo.barquuxc                   @   sD   e Zd 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 )	Testz5Keep these TestCase classes out of the main namespacec                   @   s   e Zd Zdd Zdd ZdS )zTest.Fooc                 C   s   d S N selfr   r   ?/opt/python-3.9.21/usr/lib/python3.9/unittest/test/test_case.pyrunTest"       zTest.Foo.runTestc                 C   s   d S r   r   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 r   r   r   r   r   r   test2&   r   zTest.Bar.test2N)r   r   r   r   r   r   r   r   Bar%   s   r   c                       s8   e Zd ZdZ fddZdd Zdd Zdd	 Z  ZS )
zTest.LoggingTestCasez!A test case which logs its calls.c                    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"   appendr   r   r   r   r%   /   s    zTest.LoggingTestCase.setUpc                 C   s   | j d d S r   r&   r   r   r   r   r   2   s    zTest.LoggingTestCase.testc                 C   s   | j d d S )NtearDownr&   r   r   r   r   r(   5   s    zTest.LoggingTestCase.tearDown)	r   r   r   __doc__r!   r%   r   r(   __classcell__r   r   r#   r   r    (   s
   r    N)	r   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/e)*e+j,j-dFkdG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 ZWdd ZXdd ZYeZj[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zadd Zbdd Zcdd Zddd Zedd Zfdd Zgdd Zhdd Zidd Zjdd Zkdd ZlddÄ Zmenjoddń ZpddǄ ZqdS )Test_TestCaser   r   r   c                 C   s   G dd dt j}| |  dd  d t  }|dd ||j |dd W d    n1 sn0    Y  | t |  W d    n1 s0    Y  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 r   MyExceptionr   r   r   r   r   U   r   z;Test_TestCase.test_init__no_test_name.<locals>.Test.runTestc                 S   s   d S r   r   r   r   r   r   r   V   r   z8Test_TestCase.test_init__no_test_name.<locals>.Test.testNr   r   r   r   r   r   r   r   r   r   T   s   r   iz.Test.runTest      )r+   r,   assertEqualidassertRaisesfailureExceptionAttributeErrorrun)r   r   r   r   r   r   test_init__no_test_nameS   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 r   r.   r   r   r   r   r   j   r   z?Test_TestCase.test_init__test_name__valid.<locals>.Test.runTestc                 S   s   d S r   r   r   r   r   r   r   k   r   z<Test_TestCase.test_init__test_name__valid.<locals>.Test.testNr0   r   r   r   r   r   i   s   r   r   iz
.Test.test)r+   r,   r3   r4   r   r   r   r   r   test_init__test_name__validh   s    z)Test_TestCase.test_init__test_name__validc                 C   s@   G dd dt j}z|d W n ty0   Y n0 | 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 r   r.   r   r   r   r   r   u   r   zATest_TestCase.test_init__test_name__invalid.<locals>.Test.runTestc                 S   s   d S r   r   r   r   r   r   r   v   r   z>Test_TestCase.test_init__test_name__invalid.<locals>.Test.testNr0   r   r   r   r   r   t   s   r   ZtestfoozFailed to raise ValueError)r+   r,   
ValueErrorfailr:   r   r   r   test_init__test_name__invalids   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 r   r   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,   r3   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 r   r   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,   defaultTestResultr3   type
TestResult)r   r   resultr   r   r   test_defaultTestResult   s    
z$Test_TestCase.test_defaultTestResultc                    sH   g }t |}G  fdddtj  || g d}| || 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%   RuntimeErrorr   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    r8   r3   r   r"   rG   expectedr   rM   r   #test_run_call_order__error_in_setUp   s    z1Test_TestCase.test_run_call_order__error_in_setUpc                    s>   g }G  fdddt j  |  g d}| || 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 r   r   r"   r   r   r   r   rD      s    z_Test_TestCase.test_run_call_order__error_in_setUp_default_result.<locals>.Foo.defaultTestResultc                    s   t  |   tdd S rI   rJ   r   rL   r   r   r%      s    zSTest_TestCase.test_run_call_order__error_in_setUp_default_result.<locals>.Foo.setUp)r   r   r   rD   r%   r*   r   rM   r#   r   r      s   r   )startTestRunrN   r%   rO   rP   stopTestRunr   r    r8   r3   r   r"   rS   r   rM   r   2test_run_call_order__error_in_setUp_default_result   s
    z@Test_TestCase.test_run_call_order__error_in_setUp_default_resultc                    sH   g }t |}G  fdddtj g d} || | || 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 Nraised by Foo.testr   r   rK   r   rL   r   r   r      s    zBTest_TestCase.test_run_call_order__error_in_test.<locals>.Foo.testr   r   r   r   r*   r   rM   r#   r   r      s   r   rN   r%   r   r(   rO   rP   rQ   rR   r   rM   r   "test_run_call_order__error_in_test   s    z0Test_TestCase.test_run_call_order__error_in_testc                    s>   g }G  fdddt j g d} |  | || 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 r   rU   r   r   r   r   rD      s    z^Test_TestCase.test_run_call_order__error_in_test_default_result.<locals>.Foo.defaultTestResultc                    s   t  |   tdd S r[   r]   r   rL   r   r   r      s    zQTest_TestCase.test_run_call_order__error_in_test_default_result.<locals>.Foo.testr   r   r   rD   r   r*   r   rM   r#   r   r      s   r   rV   rN   r%   r   r(   rO   rP   rW   rX   rY   r   rM   r   1test_run_call_order__error_in_test_default_result   s
    z?Test_TestCase.test_run_call_order__error_in_test_default_resultc                    sH   g }t |}G  fdddtj g d} || | || 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 r[   r   r   r=   r   rL   r   r   r      s    zDTest_TestCase.test_run_call_order__failure_in_test.<locals>.Foo.testr^   r   rM   r#   r   r      s   r   rN   r%   r   r(   
addFailurerP   rQ   rR   r   rM   r   $test_run_call_order__failure_in_test   s    z2Test_TestCase.test_run_call_order__failure_in_testc                    s>   G  fdddt j g d}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 r   rU   r   r   r   r   rD      s    z`Test_TestCase.test_run_call_order__failure_in_test_default_result.<locals>.Foo.defaultTestResultc                    s   t  |   | d d S r[   rd   r   rL   r   r   r      s    zSTest_TestCase.test_run_call_order__failure_in_test_default_result.<locals>.Foo.testra   r   rM   r#   r   r      s   r   )rV   rN   r%   r   r(   rf   rP   rW   rX   )r   rS   r"   r   rM   r   3test_run_call_order__failure_in_test_default_result   s
    zATest_TestCase.test_run_call_order__failure_in_test_default_resultc                    sH   g }t |}G  fdddtj  || g d}| || 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(   rK   r   rL   r   r   r(     s    zJTest_TestCase.test_run_call_order__error_in_tearDown.<locals>.Foo.tearDown)r   r   r   r(   r*   r   rM   r#   r   r     s   r   r_   rQ   rR   r   rM   r   &test_run_call_order__error_in_tearDown  s    z4Test_TestCase.test_run_call_order__error_in_tearDownc                    s>   G  fdddt j g } |  g d}| || 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 r   rU   r   r   r   r   rD     s    zbTest_TestCase.test_run_call_order__error_in_tearDown_default_result.<locals>.Foo.defaultTestResultc                    s   t  |   tdd S ri   rj   r   rL   r   r   r(     s    zYTest_TestCase.test_run_call_order__error_in_tearDown_default_result.<locals>.Foo.tearDown)r   r   r   rD   r(   r*   r   rM   r#   r   r     s   r   rb   rX   rY   r   rM   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 r   )r   r   r   r   r   rD   .  s    zOTest_TestCase.test_run_call_order_default_result.<locals>.Foo.defaultTestResultc                 S   s   d S r   r   r   r   r   r   r   0  s    zBTest_TestCase.test_run_call_order_default_result.<locals>.Foo.testN)r   r   r   rD   r   r   r   r   r   r   -  s   r   r   )r+   r,   r8   rA   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  |   dD ]}| j|dl |dkr6| d dD ]D}| j|d$ || dkr`tdW d    q:1 st0    Y  q:W d    q1 s0    Y  qdd	  d S )
Nr@   r2   r1   ir@   failurer2   r1   j   r\   r   )r   r   subTestr=   rK   r   rp   rt   rL   r   r   r   7  s    
Hz;Test_TestCase._check_call_order__subtests.<locals>.Foo.testr^   r   rM   r#   r   r   6  s   r   rX   r   rG   r"   Zexpected_eventsr   rM   r   _check_call_order__subtests5  s    z)Test_TestCase._check_call_order__subtestsc                 C   s&   g }t |}g d}| ||| d S )N)rN   r%   r   r(   addSubTestFailureaddSubTestSuccessrz   rz   r{   rO   rP   )r   ry   rR   r   r   r   test_run_call_order__subtestsM  s    z+Test_TestCase.test_run_call_order__subtestsc                 C   s&   g }t |}g d}| ||| d S )Nre   )r   ry   rR   r   r   r   $test_run_call_order__subtests_legacyV  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  |   dD ]f}| j|dF dD ]0}| j|d W d    q(1 sN0    Y  q(W d    q1 sn0    Y  qd S )N)r@   r2   ro   rr   rs   )r   r   rv   rw   rL   r   r   r   a  s    zCTest_TestCase._check_call_order__subtests_success.<locals>.Foo.testr^   r   rM   r#   r   r   `  s   r   rX   rx   r   rM   r   #_check_call_order__subtests_success_  s    	z1Test_TestCase._check_call_order__subtests_successc                 C   s8   g }t |}g dddg  ddg }| ||| d S )N)rN   r%   r   r(   ru   r{   
addSuccessrP   )r   r~   rR   r   r   r   %test_run_call_order__subtests_successl  s    z3Test_TestCase.test_run_call_order__subtests_successc                 C   s&   g }t |}g d}| ||| d S )N)rN   r%   r   r(   r   rP   )r   r~   rR   r   r   r   ,test_run_call_order__subtests_success_legacyv  s    z:Test_TestCase.test_run_call_order__subtests_success_legacyc                    sN   g }t |}d|_G  fdddtj g d} || | || 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    n1 s:0    Y  | jdd | d W d    n1 sp0    Y  | d d S )Nr@   ro   rq   r2   )r   r   rv   r=   r   rL   r   r   r     s    ((zFTest_TestCase.test_run_call_order__subtests_failfast.<locals>.Foo.testr^   r   rM   r#   r   r     s   r   )rN   r%   r   r(   rz   rP   )r   failfastr   r    r8   r3   rR   r   rM   r   &test_run_call_order__subtests_failfast~  s    	z4Test_TestCase.test_run_call_order__subtests_failfastc                    sT   g  G  fdddt j}t  }d|_t |}|| g d}|  | 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    n1 s(0    Y   d d S )Na1a2)rv   r'   r   r"   r   r   test_a  s    
(z8Test_TestCase.test_subtests_failfast.<locals>.Foo.test_ac                    sr   |     d W d    n1 s(0    Y  |    | d W d    n1 sZ0    Y   d d S )Nb1rq   b2)rv   r'   r=   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   r   r   r   r   r   r   r     s   r   T)r   r   r   )r+   r,   rF   r   Z	makeSuiter8   r3   )r   r   rG   ZsuiterS   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    n1 s20    Y  d S )N	test case	subtest 1)r'   rv   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   r   r   )r+   r,   debugr3   rA   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 r   r   r   r   r   r   r     s    z>Test_TestCase.test_failureException__default.<locals>.Foo.testNr?   r   r   r   r   r     s   r   r   )r+   r,   assertIsr6   AssertionErrorrA   r   r   r   test_failureException__default  s    z,Test_TestCase.test_failureException__defaultc                 C   sV   g }t |}G dd dtj}| |djt |d| g d}| || 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 r   )rK   r   r   r   r   r     s    zRTest_TestCase.test_failureException__subclassing__explicit_raise.<locals>.Foo.testNr   r   r   r   rK   r6   r   r   r   r   r     s   r   r   rN   rf   rP   r   r+   r,   r   r6   rK   r8   r3   r   r"   rG   r   rS   r   r   r   2test_failureException__subclassing__explicit_raise  s    z@Test_TestCase.test_failureException__subclassing__explicit_raisec                 C   sV   g }t |}G dd dtj}| |djt |d| g d}| || 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   )r=   r   r   r   r   r     s    zRTest_TestCase.test_failureException__subclassing__implicit_raise.<locals>.Foo.testNr   r   r   r   r   r     s   r   r   r   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 r   r   r   r   r   r   r     s    z-Test_TestCase.test_setUp.<locals>.Foo.runTestNrC   r   r   r   r   r     s   r   )r+   r,   r%   rA   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 r   r   r   r   r   r   r     s    z0Test_TestCase.test_tearDown.<locals>.Foo.runTestNrC   r   r   r   r   r      s   r   )r+   r,   r(   rA   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 r   r   r   r   r   r   r     s    z*Test_TestCase.test_id.<locals>.Foo.runTestNrC   r   r   r   r   r     s   r   )r+   r,   assertIsInstancer4   strrA   r   r   r   test_id  s    zTest_TestCase.test_idc                    sT   g t  G  fdddtj}|d }| |  g d}| | 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 r   r   r   r   r   r   r     s    z@Test_TestCase.test_run__uses_defaultTestResult.<locals>.Foo.testc                    s    S r   r   r   )defaultResultr   r   rD   !  s    zMTest_TestCase.test_run__uses_defaultTestResult.<locals>.Foo.defaultTestResultN)r   r   r   r   rD   r   r   r"   r   r   r     s   r   r   )rV   rN   r   r   rP   rW   )r   r+   r,   r8   r   r3   )r   r   rG   rS   r   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 r   r   r   r   r   r   r   1  s    z>Test_TestCase.test_run__returns_given_result.<locals>.Foo.testNr?   r   r   r   r   r   0  s   r   r   )r+   r,   rF   r8   r   )r   r   rG   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 r   r   r   r   r   r   r   A  s    zPTest_TestCase.test_call__invoking_an_instance_delegates_to_run.<locals>.Foo.testc                    s   |  |  S r   )r   )r   rG   ZresultInZ	resultOutr   r   r8   D  s    zOTest_TestCase.test_call__invoking_an_instance_delegates_to_run.<locals>.Foo.runN)r   r   r   r   r8   r   r   r   r   r   @  s   r   r   )r+   rF   r,   r   )r   r   r   r   r   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 r   )assertIsNoneshortDescriptionr   r   r   r   $testShortDescriptionWithoutDocstringM  s    z2Test_TestCase.testShortDescriptionWithoutDocstringr2   z)Docstrings are omitted with -O2 and abovec                 C   s   |  |  d  dS )z7Tests shortDescription() for a method with a docstring.Nr3   r   r   r   r   r   (testShortDescriptionWithOneLineDocstringP  s    z6Test_TestCase.testShortDescriptionWithOneLineDocstringc                 C   s   |  |  d dS )zTests shortDescription() for a method with a longer docstring.

        This method ensures that only the first line of a docstring is
        returned used in the short description, no matter how long the
        whole thing is.
        z>Tests shortDescription() for a method with a longer docstring.Nr   r   r   r   r   *testShortDescriptionWithMultiLineDocstringX  s    	z8Test_TestCase.testShortDescriptionWithMultiLineDocstringc                 C   s   |  |  d dS )z
            Tests shortDescription() whitespace is trimmed, so that the first
            line of nonwhite-space text becomes the docstring.
        zATests shortDescription() whitespace is trimmed, so that the firstNr   r   r   r   r   &testShortDescriptionWhitespaceTrimmingf  s    z4Test_TestCase.testShortDescriptionWhitespaceTrimmingc                    sV   G dd dt       }}| ||k d fdd	}|  | | || d S )Nc                   @   s   e Zd ZdZdS )z7Test_TestCase.testAddTypeEqualityFunc.<locals>.SadSnakez)Dummy class for test_addTypeEqualityFunc.N)r   r   r   r)   r   r   r   r   SadSnaker  s   r   c                    s    t | t |  ko kS   S r   )rE   )abmsgr   r   r   AllSnakesCreatedEqualv  s    zDTest_TestCase.testAddTypeEqualityFunc.<locals>.AllSnakesCreatedEqual)N)objectassertFalseZaddTypeEqualityFuncr3   )r   s1s2r   r   r   r   testAddTypeEqualityFuncq  s    z%Test_TestCase.testAddTypeEqualityFuncc                 C   s,   t  }| || | | j| j|t   d S r   )r   r   r5   r6   r   thingr   r   r   testAssertIs~  s    zTest_TestCase.testAssertIsc                 C   s,   t  }| |t   | | j| j|| d S r   )r   ZassertIsNotr5   r6   r   r   r   r   testAssertIsNot  s    zTest_TestCase.testAssertIsNotc                 C   s(   g }|  |t | | j| j |t d S r   )r   listr5   r6   dictr   r   r   r   testAssertIsInstance  s
    z"Test_TestCase.testAssertIsInstancec                 C   s(   g }|  |t | | j| j |t d S r   )ZassertNotIsInstancer   r5   r6   r   r   r   r   r   testAssertNotIsInstance  s
    z%Test_TestCase.testAssertNotIsInstancec                 C   s   dddd}|  dd |  dg d |  d	| | d
d | dg d | d| | | j| j dd | | j| j dg d | | j| j d| | | j| jdd | | j| jdg d | | j| jd| d S )NZbananaZgrassZfish)monkeycowZsealr   abcr2   rn   r   dr   Zotterx   Zelephantr   r@   r   )assertInassertNotInr5   r6   )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    n1 s0    Y  | | j$ | ddiddi W d    n1 s0    Y  | | j$ | ddiddi W d    n1 s*0    Y  | | j& | dddddi W d    n1 sn0    Y  | | j& | dddddi W d    n1 s0    Y  d	d
d tdD }| | j$ | d|iddi W d    n1 s0    Y  W d    n1 s,0    Y  d S )Nignorer   r@   r2   r   r   oner   )r   r    c                 s   s   | ]}t |V  qd S r   )chr).0rp   r   r   r   	<genexpr>  r   z=Test_TestCase.testAssertDictContainsSubset.<locals>.<genexpr>   r   u   �)	warningscatch_warningssimplefilterDeprecationWarningassertDictContainsSubsetr5   r6   joinrange)r   r   r   r   r   testAssertDictContainsSubset  s(    .2466z*Test_TestCase.testAssertDictContainsSubsetc              	   C   s  di i fg g ft  t  ft t fg}|D ]\}}z| || W n& | jyh   | d||f  Y n0 z| j||dd W n& | jy   | d||f  Y n0 z| ||d W q* | jy   | d||f  Y q*0 q*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}|D ]L\}}| | j| j|| | | j| j||d | j| j| j||dd q: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   r@   r2      r1   )set	frozensetr3   r6   r=   r5   )r   Zequal_pairsr   r   Zunequal_pairsr   r   r   testAssertEqual  sF    

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   r@   r   zThese are unequal)assertListEqualassertTupleEqualassertSequenceEqualr5   r+   r,   r6   tupleextendassertDictEqualupdate)r   r   r   r   r   r   r   r   testEquality  sh    








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 | _z| || W n0 | jy } z|jd	 }W Y d }~nd }~0 0 | d
 | t|t| | || t|d | _z| || W n2 | jy, } z|jd	 }W Y d }~nd }~0 0 | d
 | t|t| | || d | _z| || W n2 | jy } z|jd	 }W Y d }~nd }~0 0 | d
 | t|t| | || d S )Ni  r   r   i   r   
r@   r2   r   z!assertSequenceEqual did not fail.)r3   maxDiffr   difflibZndiffpprintZpformat
splitlinesr+   caseDIFF_OMITTEDlenr   r6   argsr=   
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 )Nr@   r   barfoobarr   )r   _truncateMessager+   r   r   r   r3   )r   messager   r   r   r   testTruncateMessageH  s    z!Test_TestCase.testTruncateMessagec              
   C   sr   t d}dd }||_z|i ddi W n6 | jyb } z| t|d W Y d }~nd }~0 0 | d d S )Nr3   c                 S   s   dS r   r   r   r   r   r   r   truncateX  s    z<Test_TestCase.testAssertDictEqualTruncates.<locals>.truncater@   r   r   zassertDictEqual did not fail)r+   r,   r   r   r6   r3   r   r=   r   r   r   r   r   r   r   testAssertDictEqualTruncatesV  s    
&z*Test_TestCase.testAssertDictEqualTruncatesc              
   C   sn   t d}dd }||_z|dd W n6 | jy^ } z| t|d W Y d }~nd }~0 0 | d d S )Nr3   c                 S   s   dS r   r   r   r   r   r   r   d  s    zATest_TestCase.testAssertMultiLineEqualTruncates.<locals>.truncater   r   z!assertMultiLineEqual did not fail)r+   r,   r   assertMultiLineEqualr6   r3   r   r=   r   r   r   r   !testAssertMultiLineEqualTruncatesb  s    
&z/Test_TestCase.testAssertMultiLineEqualTruncatesc                    sZ   jd d _j d_ fdd d}j$} |d |d  W d    n1 sn0    Y  dt|j  |d |d  d	}d
d }j	|_	fdd |d |d  }}j} || W d    n1 s0    Y  
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>w  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   explodingTruncation  s    zHTest_TestCase.testAssertEqual_diffThreshold.<locals>.explodingTruncationc                      s   t d S )Nr   r  r   )old_truncater   r   r   r
    r   z%r != %r)r3   r  r   
addCleanupr5   r6   r   r   	exceptionr   r   )r   scmr  r   r   r   )r	  r  r   r   testAssertEqual_diffThresholdn  s*    2,z+Test_TestCase.testAssertEqual_diffThresholdc                    s  j  d_  fdd d}|d |d  }}j}|| W d    n1 sd0    Y  d}t|jd||f  |d |d  d	}|d | |d |  }}j}|| W d    n1 s0    Y  d
}t|jd||||f  d}|d | |d |  }}j}|| W d    n1 sf0    Y  d}d}t|jd||||f  d S )Nr   c                      s   t d S 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  r5   r6   r3   r   r  )r   r  r   r   r  r   pr   r   r  r   testAssertEqual_shorten  s.    **,z%Test_TestCase.testAssertEqual_shortenc                 C   s  t  }| g dg d | g dg d | ||dddg|dd|df | g dg d | | j| jd	dgdgd
  d	gd
 ddg  | | j| jg dg d | | j| jdgddg | | j| jddgdg | | j| jg d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g ddd	g | | j| jg dg d | | 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}h d}| || tj	
g gg }| |d	dg fg ttj	dd}h d}| || d S )Nrn   )r1   r2   r@   )r   r   baz)r   r  r   r2   r1   )r@   2r   r   )r   r  Tr   r@   d   )r   r  Tr@   
      )r  r  r  r   r   Fr   y              @y               @r   r   )r@   r@   r2   )r@   r@   r  r   r   )r  r  Tr   TZaaabccdZabbbcce>   )r@   r1   r   )r   r@   r   )r@   r   r   )r1   r@   r   )r   assertCountEqualr5   r6   iterdivmodr   r   r+   utilZ_count_diff_all_purposer3   Z_count_diff_hashable)r   r   r   ZdiffsrS   r   r   r   testAssertCountEqual  sn      

($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   r@   rr   )r   r   )r   assertSetEqualr5   r6   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 )	Nr2   r@   g?g      ?ZbugZants   bugs   ant)r   ZassertGreaterEqualr   ZassertLessEqualr5   r6   r   r   r   r   testInequality  sd    zTest_TestCase.testInequalityc              
   C   sn   d}d}d}d | _ z| || W nF | jyh } z,t|ddd }| || W Y d }~n
d }~0 0 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   r@   )r   r  r6   r   splitr3   r   Zsample_textZrevised_sample_textZsample_text_errorr   errorr   r   r   testAssertMultiLineEqualO  s    z&Test_TestCase.testAssertMultiLineEqualc              
   C   sh   d}d}d}z|  || W nF | jyb } z,t|ddd }|  || W Y d }~n
d }~0 0 d S )Nzladen swallows fly slowlyzunladen swallows fly quicklyzr- laden swallows fly slowly
?                    ^^^^
+ unladen swallows fly quickly
? ++                   ^^^^^
r   r@   )r3   r6   r   r$  r%  r   r   r   testAssertEqualSingleLinen  s    z'Test_TestCase.testAssertEqualSingleLinec              	      sl  t jjr fdd}ndd }| H   j  dd W d    n1 sT0    Y  W d    n1 sr0    Y  |   dd W d    n1 s0    Y  ddg}ddg}| H   j  || W d    n1 s0    Y  W d    n1 s0    Y  | R   j$  t	|t	| W d    n1 s^0    Y  W d    n1 s~0    Y  | N   j   
|t	| W d    n1 s0    Y  W d    n1 s0    Y  | N   j   
t	|| W d    n1 s*0    Y  W d    n1 sJ0    Y  | J   j  
dd W d    n1 s0    Y  W d    n1 s0    Y  | R   j$  t|t| W d    n1 s0    Y  W d    n1 s0    Y    j   |t	| W d    n1 sT0    Y    j   t	|| W d    n1 s0    Y  ddg}dg}  j  || W d    n1 s0    Y    j$  t	|t	| W d    n1 s0    Y    j   
|t	| W d    n1 sZ0    Y    j   
t	|| W d    n1 s0    Y    j$  t|t| W d    n1 s0    Y  dg}ddg}  j  || W d    n1 s"0    Y    j$  t	|t	| W d    n1 sd0    Y    j   
|t	| W d    n1 s0    Y    j   
t	|| W d    n1 s0    Y    j$  t|t| W d    n1 s"0    Y  | R   j$  ddiddi W d    n1 sl0    Y  W d    n1 s0    Y    j   i ddi W d    n1 s0    Y    j   ddii  W d    n1 s0    Y    j$  ddgg d W d    n1 sJ0    Y  | $  ddgddg W d    n1 s0    Y  | R   j$  ddgddg W d    n1 s0    Y  W d    n1 s0    Y  | V   j(  ddg gddg g W d    n1 s>0    Y  W d    n1 s^0    Y  d S )Nc                      s     tdS )Nz#Comparison between bytes and string)assertWarnsRegexBytesWarningr   r   r   r   bytes_warning  s    z=Test_TestCase.testEqualityBytesWarning.<locals>.bytes_warningc                   S   s   t  S r   )
contextlib	ExitStackr   r   r   r   r+    s    r      ar   )r.  r.  r.  )sysflagsr+  r5   r6   r3   ZassertNotEqualr   r   r   r   r!  r   r   r  )r   r+  r   r   r   r   r   testEqualityBytesWarning~  s~    H*JTPPLT00,4004,4004T0044Tz&Test_TestCase.testEqualityBytesWarningc                 C   s<   |  d  | | j| j d | d | | j| jd  d S )NFzDjZoPloGears on Rails)r   r5   r6   ZassertIsNotNoner   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assertRegexr5   r6   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    n1 s|0    Y  | t |  d  W d    n1 s0    Y  |   | t| W d    n1 s0    Y  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   r5  c                      s    dd S N	We expectr   r   r5  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>)	Exceptionr5   r<   intr6   	TypeErrorr   r9  r   r8  r   testAssertRaisesCallable  s    .*z&Test_TestCase.testAssertRaisesCallablec              	      s,  G dd dt   fdd}|   |  W d    n1 sB0    Y  | t f}|  W d    n1 sv0    Y  | |j  | |jjd d | t tddd	 W d    n1 s0    Y  | | j< |   W d    n1 s0    Y  W d    n1 s(0    Y  | 	| jd
@ | j d
d W d    n1 sh0    Y  W d    n1 s0    Y  | 	t
d
@ | j dd W d    n1 s0    Y  W d    n1 s0    Y  |   | t| W d    n1 s0    Y  d S )Nc                   @   s   e Zd ZdS )z<Test_TestCase.testAssertRaisesContext.<locals>.ExceptionMockNr4  r   r   r   r   r5    s   r5  c                      s    dd S r6  r   r   r8  r   r   r9    s    z3Test_TestCase.testAssertRaisesContext.<locals>.Stubr   r7  r:  r;  r<  r   r   *   r   )r?  r5   r<   r   r  r3   r   r@  r6   assertRaisesRegexrA  )r   r9  r  r   r8  r   testAssertRaisesContext  s*    $$*@@@z%Test_TestCase.testAssertRaisesContextc                 C   s  |  t |    W d    n1 s(0    Y  |  t |  d W d    n1 s\0    Y  |  t |  t W d    n1 s0    Y  |  t |  tdf W d    n1 s0    Y  |  t |  ttf W d    n1 s0    Y  d S Nr@   )r5   rA  r   r<   r   r   r   r   testAssertRaisesNoExceptionType	  s    &((,z-Test_TestCase.testAssertRaisesNoExceptionTypec                 C   s4   dd }t |}| t| | |t | d S )Nc                   S   s$   zt W n t y   t Y n0 d S r   )r<   r   r   r   r   func  s    z4Test_TestCase.testAssertRaisesRefcount.<locals>.func)r/  getrefcountr5   r<   r3   )r   rJ  Zrefcountr   r   r   testAssertRaisesRefcount  s    
z&Test_TestCase.testAssertRaisesRefcountc                    sz   G dd dt   fdd}|  td| |  d| | t |  dd  W d    n1 sl0    Y  d S )Nc                   @   s   e Zd ZdS )z:Test_TestCase.testAssertRaisesRegex.<locals>.ExceptionMockNr4  r   r   r   r   r5  #  s   r5  c                      s    dd S r6  r   r   r8  r   r   r9  &  s    z1Test_TestCase.testAssertRaisesRegex.<locals>.Stubzexpect$)r?  rF  recompiler5   rA  rB  r   r8  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    n1 st0    Y  W d    n1 s0    Y  |  td@ | j tdd	d
 W d    n1 s0    Y  W d    n1 s0    Y  d S )Nz"^Exception not raised by <lambda>$r   c                   S   s   d S r   r   r   r   r   r   r
  2  r   z8Test_TestCase.testAssertNotRaisesRegex.<locals>.<lambda>c                   S   s   d S r   r   r   r   r   r   r
  6  r   r   expectr   rD  rE  )rF  r6   r?  rM  rN  rA  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>.MyExcNr4  r   r   r   r   MyExcB  s   rR  c                   S   s   dS NTr   r   r   r   r   r
  D  r   zATest_TestCase.testAssertRaisesRegexInvalidRegex.<locals>.<lambda>)r?  r5   rA  rF  )r   rR  r   r   r   !testAssertRaisesRegexInvalidRegex@  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>.MyWarnNr4  r   r   r   r   MyWarnH  s   rU  c                   S   s   dS rS  r   r   r   r   r   r
  J  r   z@Test_TestCase.testAssertWarnsRegexInvalidRegex.<locals>.<lambda>)Warningr5   rA  r)  )r   rU  r   r   r    testAssertWarnsRegexInvalidRegexF  s    z.Test_TestCase.testAssertWarnsRegexInvalidRegexc                 C   s\   G dd dt j}|dtjd< z$| ttjd W tjd= tjd= ntjd= tjd= 0 d S )Nc                   @   s   e Zd Zedd ZdS )z:Test_TestCase.testAssertWarnsModifySysModules.<locals>.Fooc                 S   s   dt jd< d S )Nr   @bar@)r/  modulesr   r   r   r   __warningregistry__O  s    zNTest_TestCase.testAssertWarnsModifySysModules.<locals>.Foo.__warningregistry__N)r   r   r   propertyrZ  r   r   r   r   r   N  s   r   r   z@foo@rS   rX  )types
ModuleTyper/  rY  assertWarnsUserWarningr   warnrA   r   r   r   testAssertWarnsModifySysModulesL  s    
z-Test_TestCase.testAssertWarnsModifySysModulesc              	   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   r9  [  s    z9Test_TestCase.testAssertRaisesRegexMismatch.<locals>.Stubz*"\^Expected\$" does not match "Unexpected"z
^Expected$)rF  r6   r?  rM  rN  rB  r   r   r   testAssertRaisesRegexMismatchZ  s    
z+Test_TestCase.testAssertRaisesRegexMismatchc                    s~   G dd dt   fdd}d}|  }| || W d    n1 sL0    Y  |j}| |  | |jd | d S )Nc                   @   s   e Zd ZdS )z=Test_TestCase.testAssertRaisesExcValue.<locals>.ExceptionMockNr4  r   r   r   r   r5  j  s   r5  c                    s    | d S r   r   )r   r8  r   r   r9  m  s    z4Test_TestCase.testAssertRaisesExcValue.<locals>.Stubzparticular valuer   )r?  r5   r  r   r3   r   )r   r9  vctxr   r   r8  r   testAssertRaisesExcValuei  s    
&z&Test_TestCase.testAssertRaisesExcValuec                 C   sN  |  t |   W d    n1 s(0    Y  |  t | t W d    n1 s\0    Y  |  t | dd W d    n1 s0    Y  |  t | td W d    n1 s0    Y  |  t  | tdfd W d    n1 s0    Y  |  t  | ttfd W d    n1 s@0    Y  d S Nr@   rP  )r5   rA  rF  r<   r   r   r   r   r   $testAssertRaisesRegexNoExceptionTypex  s    &(**0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    n1 sv0    Y  | t |  td  W d    n1 s0    Y  t T t	dt | | j |  t| W d    n1 s0    Y  W d    n1 s0    Y  t T t	dt | t |  t| W d    n1 sh0    Y  W d    n1 s0    Y  d S )	Nc                   S   s   t dt d S r   r   r`  RuntimeWarningr   r   r   r   _runtime_warn  s    z<Test_TestCase.testAssertWarnsCallable.<locals>._runtime_warnr   categoryc                   S   s   dS r>  r   r   r   r   r   r
    r   z7Test_TestCase.testAssertWarnsCallable.<locals>.<lambda>defaultr&  )
r^  ri  r   r   r`  r5   r6   rA  r   r   r   rj  r   r   r   testAssertWarnsCallable  s&    .*
J
z%Test_TestCase.testAssertWarnsCallablec              
   C   sr  dd }t |d }| t}|  W d    n1 s<0    Y  | ttf}|  W d    n1 sp0    Y  | |jt | |jjd d | 	d|j
 | |j|d  | t |  |  W d    n1 s0    Y  | t tjdtd W d    n1 s"0    Y  | | j< | t W d    n1 s\0    Y  W d    n1 s|0    Y  | | jd@ | jtdd	 W d    n1 s0    Y  W d    n1 s0    Y  | td@ | jtd
d W d    n1 s0    Y  W d    n1 s:0    Y  t | tdt | | jB | t |  W d    n1 s0    Y  W d    n1 s0    Y  W d    n1 s0    Y  t z tdt | tB | t |  W d    n1 s$0    Y  W d    n1 sD0    Y  W d    n1 sd0    Y  d S )Nc                   S   s   t dt d S r   rh  r   r   r   r   rj    s    z;Test_TestCase.testAssertWarnsContext.<locals>._runtime_warnr@   r   r   test_case.pyrk  r   r   rD  rE  rm  r&  )inspectgetsourcelinesr^  ri  r   r   warningr3   r   r   filenamelinenor   r`  r5   r6   rF  rA  r   r   r   rj  Z_runtime_warn_linenor  r   r   r   testAssertWarnsContext  sD    $$$.@@@
f
z$Test_TestCase.testAssertWarnsContextc                 C   sJ  |  t |   W d    n1 s(0    Y  |  t | d W d    n1 s\0    Y  |  t | t W d    n1 s0    Y  |  t | tdf W d    n1 s0    Y  |  t | ttf W d    n1 s0    Y  |  t | ttf W d    n1 s<0    Y  d S rH  )r5   rA  r^  r   r_  r?  r   r   r   r   testAssertWarnsNoExceptionType  s    &((,.z,Test_TestCase.testAssertWarnsNoExceptionTypec              	   C   s  dd }|  td|d | | j" |  tddd  W d    n1 sL0    Y  | t |  tdd  W d    n1 s0    Y  t X tdt | | j  |  td|d W d    n1 s0    Y  W d    n1 s0    Y  | | j  |  td|d W d    n1 s20    Y  t ^ td	t | t| jf  |  td|d W d    n1 s0    Y  W d    n1 s0    Y  d S )
Nc                 S   s   t | t d S r   rh  r   r   r   r   rj    s    zATest_TestCase.testAssertWarnsRegexCallable.<locals>._runtime_warno+fooxc                   S   s   dS r>  r   r   r   r   r   r
    r   z<Test_TestCase.testAssertWarnsRegexCallable.<locals>.<lambda>rm  barzr&  )	r)  ri  r5   r6   rA  r   r   r   r   rn  r   r   r   testAssertWarnsRegexCallable  s4    ",
@$
z*Test_TestCase.testAssertWarnsRegexCallablec              
   C   sF  dd }t |d }| td}|d W d    n1 s@0    Y  | |jt | |jjd d | d|j	 | |j
|d  | | j< | td W d    n1 s0    Y  W d    n1 s0    Y  | | jdB | jtddd	 W d    n1 s0    Y  W d    n1 s<0    Y  | tdB | jtdd
d W d    n1 s|0    Y  W d    n1 s0    Y  t  tdt | | jF | td |d W d    n1 s0    Y  W d    n1 s0    Y  W d    n1 s60    Y  | | jF | td |d W d    n1 sz0    Y  W d    n1 s0    Y  t  tdt | t| jfF | td |d W d    n1 s0    Y  W d    n1 s0    Y  W d    n1 s80    Y  d S )Nc                 S   s   t | t d S r   rh  r   r   r   r   rj    s    z@Test_TestCase.testAssertWarnsRegexContext.<locals>._runtime_warnr@   ry  rz  r   rp  r   r   rD  rE  rm  r{  r&  )rq  rr  r)  ri  r   rs  r3   r   r   rt  ru  r5   r6   rF  rA  r   r   r   r   rv  r   r   r   testAssertWarnsRegexContext  s<    &<@@
hH
z)Test_TestCase.testAssertWarnsRegexContextc                 C   s  |  t |   W d    n1 s(0    Y  |  t | t W d    n1 s\0    Y  |  t | dd W d    n1 s0    Y  |  t | td W d    n1 s0    Y  |  t  | tdfd W d    n1 s0    Y  |  t  | ttfd W d    n1 s@0    Y  |  t  | ttfd W d    n1 s|0    Y  d S rf  )r5   rA  r)  r_  r   r?  r   r   r   r   #testAssertWarnsRegexNoExceptionType.  s    &(**00z1Test_TestCase.testAssertWarnsRegexNoExceptionTypec                 c   s@   t  }d V  W d    n1 s"0    Y  | | d d S )Nr   )r	   r3   getvalue)r   bufr   r   r   assertNoStderr>  s    $zTest_TestCase.assertNoStderrc                 C   s^   |  t|t| t||D ]:\}}| |tj | D ]\}}|  t||| q<qd S r   )r3   r   zipr   logging	LogRecorditemsgetattr)r   recordsmatchesZrecmatchkrc  r   r   r   assertLogRecordsD  s
    zTest_TestCase.assertLogRecordsc              	   C   s   |   p |  $}td td W d    n1 s<0    Y  | |jdg | |j	ddig W d    n1 s~0    Y  d S )N1r  
INFO:foo:1namer   )
r  
assertLogslog_fooinfo
log_foobarr   r3   outputr  r  r   r  r   r   r   testAssertLogsDefaultsK  s    


(z$Test_TestCase.testAssertLogsDefaultsc              	   C   s   |    |  .}td td td W d    n1 sF0    Y  | |j	ddg | 
|jddiddig W d    n1 s0    Y  d S )	Nr  r  3r  WARNING:quux:3r  r   r   r  r  r  r  r  r   log_quuxrs  r3   r  r  r  r  r   r   r   !testAssertLogsTwoMatchingMessagesT  s    



(z/Test_TestCase.testAssertLogsTwoMatchingMessagesc              	   C   s   |    | j|d.}td td td W d    n1 sJ0    Y  | |j	ddg | 
|jddidd	ig W d    n1 s0    Y  d S )
Nlevelr  r  r  zERROR:foo.bar:2zCRITICAL:quux:3r  r   r   )r  r  r  rs  r  r&  r  criticalr3   r  r  r  )r   r  r  r   r   r   checkAssertLogsPerLevel_  s    


(z%Test_TestCase.checkAssertLogsPerLevelc                 C   s   |  tj |  d d S )NERROR)r  r  r  r   r   r   r   testAssertLogsPerLevelj  s    z$Test_TestCase.testAssertLogsPerLevelc              
   C   s   |    | jdd}| j|dd.}td td td W d    n1 sZ0    Y  | |j	ddg | 
|jdd	idd
ig W d    n1 s0    Y  | |j	dg W d    n1 s0    Y  d S )NDEBUGr  r  r  r  r  zDEBUG:foo.bar:2r  r   r   r  r  )r   loggerZouter_cmr  r   r   r   checkAssertLogsPerLoggern  s    


("z&Test_TestCase.checkAssertLogsPerLoggerc                 C   s   |  td |  d d S r   )r  r  	getLoggerr   r   r   r   testAssertLogsPerLogger|  s    z%Test_TestCase.testAssertLogsPerLoggerc              
   C   s   |   d | | j8 |   W d    n1 s60    Y  W d    n1 sT0    Y  W d    n1 sr0    Y  d S r   )r  r5   r6   r  r   r   r   r   testAssertLogsFailureNoLogs  s    

z)Test_TestCase.testAssertLogsFailureNoLogsc              
   C   s   |   r | | jF | jdd td W d    n1 sD0    Y  W d    n1 sb0    Y  W d    n1 s0    Y  d S )NWARNINGr  r  )r  r5   r6   r  r  r  r   r   r   r   !testAssertLogsFailureLevelTooHigh  s    
z/Test_TestCase.testAssertLogsFailureLevelTooHighc              
   C   s   | j dddp | | jD |  d td W d    n1 sH0    Y  W d    n1 sf0    Y  W d    n1 s0    Y  d S )Nr   r  r  r   r  )r  r5   r6   r  r&  r   r   r   r   &testAssertLogsFailureMismatchingLogger  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}|D ]:\}}| t ||  W d   q1 s0    Y  qdS )zY
        Test that the deprecated methods raise a DeprecationWarning. See #9424.
        )r1   r   r1   r1   )       @r  )g      @g      @)Tc                 S   s   dd S )NgQ	@Zspamr   )_r   r   r   r
    r   z9Test_TestCase.testDeprecatedMethodNames.<locals>.<lambda>)Fr@   r2   r   r1   )r   r   r   r   c                   S   s   i d S r   r   r   r   r   r   r
    r   )r   r   N)failIfEqualZassertNotEqualsfailUnlessEqualZassertEqualsfailUnlessAlmostEqualZassertAlmostEqualsfailIfAlmostEqualZassertNotAlmostEquals
failUnlessZassert_failUnlessRaisesrA  failIfr   r   ZassertRaisesRegexpKeyErrorZassertRegexpMatchesr^  r   )r   oldmethr   r   r   r   testDeprecatedMethodNames  s&    z'Test_TestCase.testDeprecatedMethodNamesc              	   C   s`   t jdd dk rdS g d}|D ]8}| t t| | W d   q"1 sP0    Y  q"dS )z9Test that the deprecated fail* methods get removed in 3.xNr2   r  )r  r  r  r  r  r  r  r   )r/  version_infor5   r7   r  )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 r   r   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   sV   t d}ttjd D ]8}tj||d}t|}| || |t t  qd S )Nr8   r@   )protocol)	r+   r,   r   pickleHIGHEST_PROTOCOLdumpsloadsr3   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}||||fD ]:}| t |d  W d    qz1 s0    Y  qzd S )Nc                 S   s   t d S r   )KeyboardInterruptr   r   r   r   _raise  s    z3Test_TestCase.testKeyboardInterrupt.<locals>._raisec                 S   s   d S r   r   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   r  r   r   Test1  s   r  c                       s   e Zd Z ZZdS )z2Test_TestCase.testKeyboardInterrupt.<locals>.Test2Nr   r   r   r%   r  r   r  r  r   r   Test2  s   r  c                       s   e Zd ZZ ZdS )z2Test_TestCase.testKeyboardInterrupt.<locals>.Test3Nr   r   r   r  r(   r   r  r   r   Test3  s   r  c                       s   e Zd Z fddZdS )z2Test_TestCase.testKeyboardInterrupt.<locals>.Test4c                    s   |    d S r   r  r   r  r   r   r    s    zATest_TestCase.testKeyboardInterrupt.<locals>.Test4.test_somethingNr  r   r  r   r   Test4  s   r  r  )N)r+   r,   r5   r  r8   )r   r  r  r  r  klassr   r  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}||||fD ]:}t  }|d| | t|jd | |jd qzd S )Nc                 S   s   t dd S )Nzsome reason)r+   ZSkipTestr   r   r   r   _skip  s    z3Test_TestCase.testSkippingEverywhere.<locals>._skipc                 S   s   d S r   r   r   r   r   r   r    s    z5Test_TestCase.testSkippingEverywhere.<locals>.nothingc                       s   e Zd Z ZdS )z3Test_TestCase.testSkippingEverywhere.<locals>.Test1Nr  r   r  r   r   r    s   r  c                       s   e Zd Z ZZdS )z3Test_TestCase.testSkippingEverywhere.<locals>.Test2Nr  r   r  r  r   r   r    s   r  c                       s   e Zd ZZ ZdS )z3Test_TestCase.testSkippingEverywhere.<locals>.Test3Nr  r   r  r   r   r     s   r  c                       s   e Zd Z fddZdS )z3Test_TestCase.testSkippingEverywhere.<locals>.Test4c                    s   |    d S r   r  r   r  r   r   r    s    zBTest_TestCase.testSkippingEverywhere.<locals>.Test4.test_somethingNr  r   r  r   r   r    s   r  r  r@   )N)r+   r,   rF   r8   r3   r   ZskippedtestsRunr   r  r  r  r  r  rG   r   r  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}||||fD ]:}t  }|d| | t|jd | |jd qzd S )Nc                 S   s   t d S r   )
SystemExitr   r   r   r   r    s    z,Test_TestCase.testSystemExit.<locals>._raisec                 S   s   d S r   r   r   r   r   r   r    s    z-Test_TestCase.testSystemExit.<locals>.nothingc                       s   e Zd Z ZdS )z+Test_TestCase.testSystemExit.<locals>.Test1Nr  r   r  r   r   r    s   r  c                       s   e Zd Z ZZdS )z+Test_TestCase.testSystemExit.<locals>.Test2Nr  r   r  r   r   r    s   r  c                       s   e Zd ZZ ZdS )z+Test_TestCase.testSystemExit.<locals>.Test3Nr  r   r  r   r   r    s   r  c                       s   e Zd Z fddZdS )z+Test_TestCase.testSystemExit.<locals>.Test4c                    s   |    d S r   r  r   r  r   r   r     s    z:Test_TestCase.testSystemExit.<locals>.Test4.test_somethingNr  r   r  r   r   r    s   r  r  r@   )N)r+   r,   rF   r8   r3   r   errorsr  r  r   r  r   testSystemExit  s    
zTest_TestCase.testSystemExitc                 C   sL   t  }t|}t  ~| |  W d    n1 s>0    Y  d S r   )r+   r,   weakrefrefr   Z
disable_gcr   )r   r   wrr   r   r   testNoCycles)  s
    

zTest_TestCase.testNoCyclesc                    s\   G  fdddt  G  fdddtj}dD ](}||}|  t  |  jd q.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 rH  )	ninstancer?  r!   r   r.   r   r   r!   7  s    zBTest_TestCase.test_no_exception_leak.<locals>.MyException.__init__c                    s     j d8  _ d S rH  )r  r   r.   r   r   __del__;  s    zATest_TestCase.test_no_exception_leak.<locals>.MyException.__del__N)r   r   r   r  r!   r  r   r.   r   r   r/   4  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 r   r   r   r.   r   r   r   ?  s    z<Test_TestCase.test_no_exception_leak.<locals>.TestCase.test1c                    s
     d S r   r   r   r.   r   r   r   B  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,   r8   r
   r3   r  )r   r,   Zmethod_nameZtestcaser   r.   r   test_no_exception_leak1  s    
z$Test_TestCase.test_no_exception_leakN)rr   r   r   r   r   Zeq_pairsr   Zne_pairsr9   r;   r>   rB   rH   rT   rZ   r`   rc   rg   rh   rk   rl   rm   ry   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r+   ZskipIfr/  r0  optimizer   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r"  r#  r'  r(  r1  r2  r3  rC  rG  rI  rL  rO  rQ  rT  rW  ra  rb  re  rg  ro  rw  rx  r|  r}  r~  r,  contextmanagerr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   Zcpython_onlyr  r  r   r   r   r   r-   9   s   

		
	


	%4($>(:L 0!,
	
r-   __main__)#r,  r   r   r  rM  r/  r  r   r  rq  r\  copyr   r   r   r+   Zunittest.test.supportr   r   r   r   r   Ztest.supportr	   r
   r  r  r  r  r   r   r,   r-   r   mainr   r   r   r   <module>   sH   


              "