o
    KXhg-                    @   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r~e"  dS 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                   @      e Zd Zdd Zdd ZdS )zTest.Fooc                 C      d S N selfr   r   A/opt/python-3.10.19/usr/lib/python3.10/unittest/test/test_case.pyrunTest"       zTest.Foo.runTestc                 C   r   r   r   r   r   r   r   test1#   r   zTest.Foo.test1N)__name__
__module____qualname__r   r   r   r   r   r   Foo!       r   c                   @      e Zd Zdd ZdS )zTest.Barc                 C   r   r   r   r   r   r   r   test2&   r   zTest.Bar.test2N)r   r   r   r   r   r   r   r   Bar%       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      | j d d S )NsetUpr'   appendr   r   r   r   r+   /      zTest.LoggingTestCase.setUpc                 C   r*   r"   r,   r   r   r   r   r#   2   r.   zTest.LoggingTestCase.testc                 C   r*   )NtearDownr,   r   r   r   r   r/   5   r.   zTest.LoggingTestCase.tearDown)	r   r   r   __doc__r&   r+   r#   r/   __classcell__r   r   r(   r   r%   (   s    r%   N)	r   r   r   r0   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Ä Zmddń ZnddǄ ZoddɄ Zpdd˄ Zqdd̈́ Zrddτ Zsddф Ztddӄ ZuddՄ Zvddׄ Zwexjyddل Zzddۄ Z{dS )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 s7w   Y  | t |  W d    d S 1 sQw   Y  d S )Nc                   @   r   )z3Test_TestCase.test_init__no_test_name.<locals>.Testc                 S      t  r   MyExceptionr   r   r   r   r   U       z;Test_TestCase.test_init__no_test_name.<locals>.Test.runTestc                 S   r   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   r   r   iz.Test.runTest      )r2   r3   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                   @   r   )z7Test_TestCase.test_init__test_name__valid.<locals>.Testc                 S   r5   r   r6   r   r   r   r   r   j   r8   z?Test_TestCase.test_init__test_name__valid.<locals>.Test.runTestc                 S   r   r   r   r   r   r   r   r#   k   r   z<Test_TestCase.test_init__test_name__valid.<locals>.Test.testNr9   r   r   r   r   r   i   r   r   r#   iz
.Test.test)r2   r3   r<   r=   r   r   r   r   r   test_init__test_name__validh   s    z)Test_TestCase.test_init__test_name__validc                 C   sB   G dd dt j}z|d W n
 ty   Y d S w | d d S )Nc                   @   r   )z9Test_TestCase.test_init__test_name__invalid.<locals>.Testc                 S   r5   r   r6   r   r   r   r   r   u   r8   zATest_TestCase.test_init__test_name__invalid.<locals>.Test.runTestc                 S   r   r   r   r   r   r   r   r#   v   r   z>Test_TestCase.test_init__test_name__invalid.<locals>.Test.testNr9   r   r   r   r   r   t   r   r   ZtestfoozFailed to raise ValueError)r2   r3   
ValueErrorfailrC   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                   @   r   )z.Test_TestCase.test_countTestCases.<locals>.Fooc                 S   r   r   r   r   r   r   r   r#      r   z3Test_TestCase.test_countTestCases.<locals>.Foo.testNr   r   r   r#   r   r   r   r   r      r!   r   r#      )r2   r3   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                   @   r   )z1Test_TestCase.test_defaultTestResult.<locals>.Fooc                 S   r   r   r   r   r   r   r   r         z9Test_TestCase.test_defaultTestResult.<locals>.Foo.runTestNr   r   r   r   r   r   r   r   r      r!   r   )r2   r3   defaultTestResultr<   type
TestResult)r   r   resultr   r   r   test_defaultTestResult   s   
z$Test_TestCase.test_defaultTestResultc                    H   g }t |}G  fdddtj  || g d}| || d S )Nc                          e Zd Z fddZ  ZS )z>Test_TestCase.test_run_call_order__error_in_setUp.<locals>.Fooc                       t  |   tdNzraised by Foo.setUpr$   r+   RuntimeErrorr   r   r)   r   r   r+         zDTest_TestCase.test_run_call_order__error_in_setUp.<locals>.Foo.setUp)r   r   r   r+   r1   r   r   r(   r   r          r   )	startTestr+   addErrorstopTestr   r   r%   rA   r<   r   r'   rQ   expectedr   r[   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                       &   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   
   t | jS r   r   r'   r   r   r   r   rN         
z_Test_TestCase.test_run_call_order__error_in_setUp_default_result.<locals>.Foo.defaultTestResultc                    rU   rV   rW   r   rY   r   r   r+      rZ   zSTest_TestCase.test_run_call_order__error_in_setUp_default_result.<locals>.Foo.setUp)r   r   r   rN   r+   r1   r   r[   r(   r   r          r   )startTestRunr]   r+   r^   r_   stopTestRunr   r%   rA   r<   r   r'   rb   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                    H   g }t |}G  fdddtj g d} || | || d S )Nc                       rT   )z=Test_TestCase.test_run_call_order__error_in_test.<locals>.Fooc                    rU   Nraised by Foo.testr$   r#   rX   r   rY   r   r   r#      rZ   zBTest_TestCase.test_run_call_order__error_in_test.<locals>.Foo.testr   r   r   r#   r1   r   r[   r(   r   r      r\   r   r]   r+   r#   r/   r^   r_   r`   ra   r   r[   r   "test_run_call_order__error_in_test      z0Test_TestCase.test_run_call_order__error_in_testc                    s>   g }G  fdddt j g d} |  | || d S )Nc                       rd   )zLTest_TestCase.test_run_call_order__error_in_test_default_result.<locals>.Fooc                 S   re   r   rf   r   r   r   r   rN      rg   z^Test_TestCase.test_run_call_order__error_in_test_default_result.<locals>.Foo.defaultTestResultc                    rU   ro   rq   r   rY   r   r   r#      rZ   zQTest_TestCase.test_run_call_order__error_in_test_default_result.<locals>.Foo.testr   r   r   rN   r#   r1   r   r[   r(   r   r      rh   r   ri   r]   r+   r#   r/   r^   r_   rj   rk   rl   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                    rn   )Nc                       rT   )z?Test_TestCase.test_run_call_order__failure_in_test.<locals>.Fooc                       t  |   | d d S ro   r$   r#   rF   r   rY   r   r   r#         zDTest_TestCase.test_run_call_order__failure_in_test.<locals>.Foo.testrr   r   r[   r(   r   r      r\   r   r]   r+   r#   r/   
addFailurer_   r`   ra   r   r[   r   $test_run_call_order__failure_in_test   ru   z2Test_TestCase.test_run_call_order__failure_in_testc                    s>   G  fdddt j g d}g } |  | || d S )Nc                       rd   )zNTest_TestCase.test_run_call_order__failure_in_test_default_result.<locals>.Fooc                 S   re   r   rf   r   r   r   r   rN      rg   z`Test_TestCase.test_run_call_order__failure_in_test_default_result.<locals>.Foo.defaultTestResultc                    ry   ro   rz   r   rY   r   r   r#      r{   zSTest_TestCase.test_run_call_order__failure_in_test_default_result.<locals>.Foo.testrv   r   r[   r(   r   r          r   )ri   r]   r+   r#   r/   r}   r_   rj   rk   )r   rb   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                    rS   )Nc                       rT   )zATest_TestCase.test_run_call_order__error_in_tearDown.<locals>.Fooc                    rU   Nzraised by Foo.tearDownr$   r/   rX   r   rY   r   r   r/     rZ   zJTest_TestCase.test_run_call_order__error_in_tearDown.<locals>.Foo.tearDown)r   r   r   r/   r1   r   r[   r(   r   r     r\   r   rs   r`   ra   r   r[   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                       rd   )zPTest_TestCase.test_run_call_order__error_in_tearDown_default_result.<locals>.Fooc                 S   re   r   rf   r   r   r   r   rN     rg   zbTest_TestCase.test_run_call_order__error_in_tearDown_default_result.<locals>.Foo.defaultTestResultc                    rU   r   r   r   rY   r   r   r/     rZ   zYTest_TestCase.test_run_call_order__error_in_tearDown_default_result.<locals>.Foo.tearDown)r   r   r   rN   r/   r1   r   r[   r(   r   r     r   r   rw   rk   rl   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                   @   r   )z=Test_TestCase.test_run_call_order_default_result.<locals>.Fooc                 S   s   t  S r   )r   r   r   r   r   rN   .     zOTest_TestCase.test_run_call_order_default_result.<locals>.Foo.defaultTestResultc                 S   r   r   r   r   r   r   r   r#   0  rL   zBTest_TestCase.test_run_call_order_default_result.<locals>.Foo.testN)r   r   r   rN   r#   r   r   r   r   r   -  s    r   r#   )r2   r3   rA   rJ   r   r   r   "test_run_call_order_default_result+  s   z0Test_TestCase.test_run_call_order_default_resultc                    4   G  fdddt j  || | || d S )Nc                       rT   )z6Test_TestCase._check_call_order__subtests.<locals>.Fooc                    s   t  |   dD ]F}| j|d6 |dkr| d dD ]"}| j|d || dkr0tdW d    n1 s:w   Y  qW d    n1 sJw   Y  q	dd	  d S )
NrI   r;   r:   irI   failurer;   r:   j   rp   r   )r$   r#   subTestrF   rX   r   r   r   rY   r   r   r#   7  s    
z;Test_TestCase._check_call_order__subtests.<locals>.Foo.testrr   r   r[   r(   r   r   6  r\   r   rk   r   rQ   r'   Zexpected_eventsr   r[   r   _check_call_order__subtests5  s   z)Test_TestCase._check_call_order__subtestsc                 C   &   g }t |}g d}| ||| d S )N)r]   r+   r#   r/   addSubTestFailureaddSubTestSuccessr   r   r   r^   r_   )r   r   ra   r   r   r   test_run_call_order__subtestsM  s   z+Test_TestCase.test_run_call_order__subtestsc                 C   r   )Nr|   )r   r   ra   r   r   r   $test_run_call_order__subtests_legacyV  s   z2Test_TestCase.test_run_call_order__subtests_legacyc                    r   )Nc                       rT   )z>Test_TestCase._check_call_order__subtests_success.<locals>.Fooc                    s~   t  |   dD ]3}| j|d# dD ]}| j|d W d    n1 s'w   Y  qW d    n1 s7w   Y  q	d S )N)rI   r;   r   r   r   )r$   r#   r   r   rY   r   r   r#   a  s   zCTest_TestCase._check_call_order__subtests_success.<locals>.Foo.testrr   r   r[   r(   r   r   `  r\   r   rk   r   r   r[   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)r]   r+   r#   r/   r   r   
addSuccessr_   )r   r   ra   r   r   r   %test_run_call_order__subtests_successl  s   z3Test_TestCase.test_run_call_order__subtests_successc                 C   r   )N)r]   r+   r#   r/   r   r_   )r   r   ra   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                       rT   )zATest_TestCase.test_run_call_order__subtests_failfast.<locals>.Fooc                    s   t  |   | jdd | d W d    n1 sw   Y  | jdd | d W d    n1 s8w   Y  | d d S )NrI   r   r   r;   )r$   r#   r   rF   r   rY   r   r   r#     s   zFTest_TestCase.test_run_call_order__subtests_failfast.<locals>.Foo.testrr   r   r[   r(   r   r     r\   r   )r]   r+   r#   r/   r   r_   )r   failfastr   r%   rA   r<   ra   r   r[   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w   Y   d d S )Na1a2)r   r-   r   r'   r   r   test_a  s   
z8Test_TestCase.test_subtests_failfast.<locals>.Foo.test_ac                    sr   |     d W d    n1 sw   Y  |    | d W d    n1 s-w   Y   d d S )Nb1r   b2)r   r-   rF   r   r   r   r   test_b  s   

z8Test_TestCase.test_subtests_failfast.<locals>.Foo.test_bc                         d d S )Ncr-   r   r   r   r   test_c     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   )r2   r3   rP   r   Z	makeSuiterA   r<   )r   r   rQ   Zsuiterb   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                          e Zd Z fddZdS )z.Test_TestCase.test_subtests_debug.<locals>.Fooc                    sB     d |     d W d    d S 1 sw   Y  d S )N	test case	subtest 1)r-   r   r   r   r   r   r     s   

"z5Test_TestCase.test_subtests_debug.<locals>.Foo.test_aN)r   r   r   r   r   r   r   r   r         r   r   r   r   )r2   r3   debugr<   rJ   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                   @   r   )z9Test_TestCase.test_failureException__default.<locals>.Fooc                 S   r   r   r   r   r   r   r   r#     rL   z>Test_TestCase.test_failureException__default.<locals>.Foo.testNrH   r   r   r   r   r     r!   r   r#   )r2   r3   assertIsr?   AssertionErrorrJ   r   r   r   test_failureException__default     z,Test_TestCase.test_failureException__defaultc                 C   V   g }t |}G dd dtj}| |djt |d| g d}| || d S )Nc                   @      e Zd Zdd ZeZdS )zMTest_TestCase.test_failureException__subclassing__explicit_raise.<locals>.Fooc                 S   r5   r   )rX   r   r   r   r   r#     r   zRTest_TestCase.test_failureException__subclassing__explicit_raise.<locals>.Foo.testNr   r   r   r#   rX   r?   r   r   r   r   r         r   r#   r]   r}   r_   r   r2   r3   r   r?   rX   rA   r<   r   r'   rQ   r   rb   r   r   r   2test_failureException__subclassing__explicit_raise     z@Test_TestCase.test_failureException__subclassing__explicit_raisec                 C   r   )Nc                   @   r   )zMTest_TestCase.test_failureException__subclassing__implicit_raise.<locals>.Fooc                 S   s   |  d d S Nr   )rF   r   r   r   r   r#     r   zRTest_TestCase.test_failureException__subclassing__implicit_raise.<locals>.Foo.testNr   r   r   r   r   r     r   r   r#   r   r   r   r   r   r   2test_failureException__subclassing__implicit_raise  r   z@Test_TestCase.test_failureException__subclassing__implicit_raisec                 C       G dd dt j}|   d S )Nc                   @   r   )z%Test_TestCase.test_setUp.<locals>.Fooc                 S   r   r   r   r   r   r   r   r     rL   z-Test_TestCase.test_setUp.<locals>.Foo.runTestNrM   r   r   r   r   r     r!   r   )r2   r3   r+   rJ   r   r   r   
test_setUp     zTest_TestCase.test_setUpc                 C   r   )Nc                   @   r   )z(Test_TestCase.test_tearDown.<locals>.Fooc                 S   r   r   r   r   r   r   r   r     rL   z0Test_TestCase.test_tearDown.<locals>.Foo.runTestNrM   r   r   r   r   r      r!   r   )r2   r3   r/   rJ   r   r   r   test_tearDown  r   zTest_TestCase.test_tearDownc                 C   s(   G dd dt j}| |  t d S )Nc                   @   r   )z"Test_TestCase.test_id.<locals>.Fooc                 S   r   r   r   r   r   r   r   r     rL   z*Test_TestCase.test_id.<locals>.Foo.runTestNrM   r   r   r   r   r     r!   r   )r2   r3   assertIsInstancer=   strrJ   r   r   r   test_id  r   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                    r   r"   r   r   r   r   r   r#     r   z@Test_TestCase.test_run__uses_defaultTestResult.<locals>.Foo.testc                    s    S r   r   r   )defaultResultr   r   rN   !  rL   zMTest_TestCase.test_run__uses_defaultTestResult.<locals>.Foo.defaultTestResultN)r   r   r   r#   rN   r   r   r'   r   r   r     s    r   r#   )ri   r]   r#   r   r_   rj   )r   r2   r3   rA   r   r<   )r   r   rQ   rb   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                   @   r   )z9Test_TestCase.test_run__returns_given_result.<locals>.Fooc                 S   r   r   r   r   r   r   r   r#   1  rL   z>Test_TestCase.test_run__returns_given_result.<locals>.Foo.testNrH   r   r   r   r   r   0  r!   r   r#   )r2   r3   rP   rA   r   )r   r   rQ   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   r   r   r   r   r   r   r   r#   A  rL   zPTest_TestCase.test_call__invoking_an_instance_delegates_to_run.<locals>.Foo.testc                    s   |  |  S r   )r   )r   rQ   ZresultInZ	resultOutr   r   rA   D  s   zOTest_TestCase.test_call__invoking_an_instance_delegates_to_run.<locals>.Foo.runN)r   r   r   r#   rA   r   r   r   r   r   @  s    r   r#   )r2   rP   r3   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     z2Test_TestCase.testShortDescriptionWithoutDocstringr;   z)Docstrings are omitted with -O2 and abovec                 C   s   |  |  d  dS )z7Tests shortDescription() for a method with a docstring.Nr<   r   r   r   r   r   (testShortDescriptionWithOneLineDocstringP  s   z6Test_TestCase.testShortDescriptionWithOneLineDocstringc                 C      |  |  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   r   )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   r0   r   r   r   r   SadSnaker      r   c                    s    t | t |  ko kS   S r   )rO   )abmsgr   r   r   AllSnakesCreatedEqualv  s    zDTest_TestCase.testAddTypeEqualityFunc.<locals>.AllSnakesCreatedEqualr   )objectassertFalseZaddTypeEqualityFuncr<   )r   s1s2r   r   r   r   testAddTypeEqualityFuncq  s   z%Test_TestCase.testAddTypeEqualityFuncc                 C   s,   t  }| || | | j| j|t   d S r   )r   r   r>   r?   r   thingr   r   r   testAssertIs~  s   zTest_TestCase.testAssertIsc                 C   s,   t  }| |t   | | j| j|| d S r   )r   ZassertIsNotr>   r?   r   r   r   r   testAssertIsNot  s   zTest_TestCase.testAssertIsNotc                 C   (   g }|  |t | | j| j |t d S r   )r   listr>   r?   dictr   r   r   r   testAssertIsInstance  
   z"Test_TestCase.testAssertIsInstancec                 C   r   r   )ZassertNotIsInstancer   r>   r?   r   r   r   r   r   testAssertNotIsInstance  r   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   abcr;   r   r   dr   Zotterx   Zelephantr   rI   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    n1 sTw   Y  | | j | ddiddi W d    n1 stw   Y  | | j | ddiddi W d    n1 sw   Y  | | j | dddddi W d    n1 sw   Y  | | j | dddddi W d    n1 sw   Y  d	d
d tdD }| | j | d|iddi W d    n	1 sw   Y  W d    n	1 sw   Y  | 	t}| i i  W d    n	1 s/w   Y  | 
|j d jt d S )Nignorer   rI   r;   r   r   oner   )r   r    c                 s   s    | ]}t |V  qd S r   )chr).0r   r   r   r   	<genexpr>  s    z=Test_TestCase.testAssertDictContainsSubset.<locals>.<genexpr>   r   u   �r   )warningscatch_warningssimplefilterDeprecationWarningassertDictContainsSubsetr>   r?   joinrangeassertWarnsr<   filename__file__)r   r   Zwarninfor   r   r   testAssertDictContainsSubset  s@   z*Test_TestCase.testAssertDictContainsSubsetc              	   C   s  di i fg g ft  t  ft t fg}|D ]Z\}}z| || W n | jy4   | d||f  Y nw z
| j||dd W n | jyR   | d||f  Y nw z	| ||d W q | jyo   | d||f  Y 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}|D ]%\}}| | j| j|| | | j| j||d | j| j| j||dd qd 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   rI   r;      r:   )set	frozensetr<   r?   rF   r>   )r   Zequal_pairsr   r   Zunequal_pairsr   r   r   testAssertEqual  sN   


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   rI   r   zThese are unequal)assertListEqualassertTupleEqualassertSequenceEqualr>   r2   r3   r?   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 n | jyX } z|jd	 }W Y d }~n
d }~ww | d
 | t|t| | || t|d | _z| || W n | jy } z|jd	 }W Y d }~n
d }~ww | d
 | t|t| | || d | _z| || W n | jy } z|jd	 }W Y d }~n
d }~ww | d
 | t|t| | || d S )Ni  r   r   i   r   
rI   r;   r   z!assertSequenceEqual did not fail.)r<   maxDiffr  difflibZndiffpprintZpformat
splitlinesr2   caseDIFF_OMITTEDlenr  r?   argsrF   
assertLessr   assertGreaterr   )r   Zseq1Zseq2diffomitteder   r   r   r   testAssertSequenceEqualMaxDiff$  sJ   


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 )NrI   r   barfoobarr   )r  _truncateMessager2   r  r  r  r<   )r   messager#  r   r   r   testTruncateMessageL  s   z!Test_TestCase.testTruncateMessagec              
   C   st   t d}dd }||_z
|i ddi W n | jy2 } z| t|d W Y d }~d S d }~ww | d d S )Nr<   c                 S      dS r   r   r   r"  r   r   r   truncate\  rL   z<Test_TestCase.testAssertDictEqualTruncates.<locals>.truncaterI   r   r   zassertDictEqual did not fail)r2   r3   r(  r  r?   r<   r   rF   r   r#   r-  r$  r   r   r   testAssertDictEqualTruncatesZ  s   
z*Test_TestCase.testAssertDictEqualTruncatesc              
   C   sp   t d}dd }||_z|dd W n | jy0 } z| t|d W Y d }~d S d }~ww | d d S )Nr<   c                 S   r+  r   r   r,  r   r   r   r-  h  rL   zATest_TestCase.testAssertMultiLineEqualTruncates.<locals>.truncater   r&  z!assertMultiLineEqual did not fail)r2   r3   r(  assertMultiLineEqualr?   r<   r   rF   r.  r   r   r   !testAssertMultiLineEqualTruncatesf  s   
z/Test_TestCase.testAssertMultiLineEqualTruncatesc                    sX   jd d _j d_ fdd d}j} |d |d  W d    n1 s7w   Y  dt|j  |d |d  d	}d
d }j	|_	fdd |d |d }}j} || W d    n1 sw   Y  
dt|j  t|jd||f   |d |d  d S )Ni       c                         t d S N_diffThresholdsetattrr   old_thresholdr   r   r   <lambda>{      z=Test_TestCase.testAssertEqual_diffThreshold.<locals>.<lambda>Zxxxxxxxxxxxxxxxxr   r   ^Z@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxc                 S      t d)Nzthis should not be raised)SystemError)r)  r"  r   r   r   explodingTruncation     zHTest_TestCase.testAssertEqual_diffThreshold.<locals>.explodingTruncationc                      r3  )Nr(  r6  r   )old_truncater   r   r   r:    r;  z%r != %r)r<   r5  r  
addCleanupr>   r?   r   r   	exceptionr(  r   )r   scmr?  r   r   r   )r9  rA  r   r   testAssertEqual_diffThresholdr  s.   z+Test_TestCase.testAssertEqual_diffThresholdc                    s  j  d_  fdd d}|d |d }}j}|| W d    n1 s2w   Y  d}t|jd||f  |d |d  d	}|d | |d | }}j}|| W d    n1 svw   Y  d
}t|jd||||f  d}|d | |d | }}j}|| W d    n1 sw   Y  d}d}t|jd||||f  d S )Nr   c                      r3  r4  r6  r   r8  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)r5  rB  r>   r?   r<   r   rC  )r   rD  r   r   rE  r   pr   r   r8  r   testAssertEqual_shorten  s4   "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 )Nr   )r:   r;   rI   )r   r&  baz)r&  rI  r   r;   r:   )rI   2r   r   )r   rJ  Tr   rI   d   )r   rJ  TrI   
      )rL  rM  rL  r   r   Fr   y              @y               @r   r   )rI   rI   r;   )rI   rI   rJ  r   r   )rJ  rJ  Tr   TZaaabccdZabbbcce>   )r   rI   r$  )rI   r:   r   )r:   rI   r   )rI   r   r   )r   assertCountEqualr>   r?   iterdivmodr  r  r2   utilZ_count_diff_all_purposer<   Z_count_diff_hashable)r   r   r   Zdiffsrb   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   rI   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;   rI   g?g      ?ZbugZants   bugs   ant)r!  ZassertGreaterEqualr   ZassertLessEqualr>   r?   r   r   r   r   testInequality  sd   zTest_TestCase.testInequalityc              
   C   sn   d}d}d}d | _ z	| || W d S  | jy6 } zt|ddd }| || W Y d }~d S d }~ww )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  rI   )r  r0  r?   r   splitr<   r   Zsample_textZrevised_sample_textZsample_text_errorr$  errorr   r   r   testAssertMultiLineEqualS  s   z&Test_TestCase.testAssertMultiLineEqualc              
   C   sh   d}d}d}z	|  || W d S  | jy3 } zt|ddd }|  || W Y d }~d S d }~ww )Nzladen swallows fly slowlyzunladen swallows fly quicklyzr- laden swallows fly slowly
?                    ^^^^
+ unladen swallows fly quickly
? ++                   ^^^^^
r  rI   )r<   r?   r   rW  rX  r   r   r   testAssertEqualSingleLiner  s   z'Test_TestCase.testAssertEqualSingleLinec              	      st  t jjr fdd}ndd }| $   j  dd W d    n1 s*w   Y  W d    n1 s9w   Y  |   dd W d    n1 sRw   Y  ddg}ddg}| $   j  || W d    n1 szw   Y  W d    n1 sw   Y  | (   j  t	|t	| W d    n1 sw   Y  W d    n1 sw   Y  | &   j  
|t	| W d    n1 sw   Y  W d    n1 sw   Y  | '   j  
t	|| W d    n	1 sw   Y  W d    n	1 s w   Y  | %   j  
dd W d    n	1 sAw   Y  W d    n	1 sQw   Y  | )   j  t|t| W d    n	1 svw   Y  W d    n	1 sw   Y    j  |t	| W d    n	1 sw   Y    j  t	|| W d    n	1 sw   Y  ddg}dg}  j  || W d    n	1 sw   Y    j  t	|t	| W d    n	1 s	w   Y    j  
|t	| W d    n	1 s(w   Y    j  
t	|| W d    n	1 sGw   Y    j  t|t| W d    n	1 shw   Y  dg}ddg}  j  || W d    n	1 sw   Y    j  t	|t	| W d    n	1 sw   Y    j  
|t	| W d    n	1 sw   Y    j  
t	|| W d    n	1 sw   Y    j  t|t| W d    n	1 sw   Y  | )   j  ddiddi W d    n	1 s1w   Y  W d    n	1 sAw   Y    j  i ddi W d    n	1 s`w   Y    j  ddii  W d    n	1 sw   Y    j  ddgg d W d    n	1 sw   Y  |   ddgddg W d    n	1 sw   Y  | )   j  ddgddg W d    n	1 sw   Y  W d    n	1 sw   Y  | 4   j  ddg gddg g W d    n1 sw   Y  W d    d S W d    d S 1 s3w   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^    r@  r      ar   )ra  ra  ra  )sysflagsr^  r>   r?   r<   ZassertNotEqualr  r  r  r  rT  r  r  rO  )r   r^  r   r   r   r   r   testEqualityBytesWarning  s            Tz&Test_TestCase.testEqualityBytesWarningc                 C   s<   |  d  | | j| j d | d | | j| jd  d S )NFzDjZoPloGears on Rails)r   r>   r?   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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    n1 s>w   Y  | t |  d  W d    n1 sYw   Y  |   | t| W d    d S 1 suw   Y  d S )
Nc                   @      e Zd ZdS )z=Test_TestCase.testAssertRaisesCallable.<locals>.ExceptionMockNr   r   r   r   r   r   r   ExceptionMock      ri  c                          dN	We expectr   r   ri  r   r   Stub  r@  z4Test_TestCase.testAssertRaisesCallable.<locals>.Stub19   basec                   S   r+  Nr   r   r   r   r   r   r:    r   z8Test_TestCase.testAssertRaisesCallable.<locals>.<lambda>)	Exceptionr>   rE   intr?   	TypeErrorr   ro  r   rn  r   testAssertRaisesCallable  s   "z&Test_TestCase.testAssertRaisesCallablec              	      s"  G dd dt   fdd}|   |  W d    n1 s!w   Y  | t f}|  W d    n1 s;w   Y  | |j  | |jjd d | t tddd	 W d    n1 sgw   Y  | | j |   W d    n1 sw   Y  W d    n1 sw   Y  | 	| jd
 | j d
d W d    n1 sw   Y  W d    n1 sw   Y  | 	t
d
 | j dd W d    n1 sw   Y  W d    n1 sw   Y  |   | t| W d    d S 1 s
w   Y  d S )Nc                   @   rg  )z<Test_TestCase.testAssertRaisesContext.<locals>.ExceptionMockNrh  r   r   r   r   ri    rj  ri  c                      rk  rl  r   r   rn  r   r   ro    r@  z3Test_TestCase.testAssertRaisesContext.<locals>.Stubr   rm  rp  rq  rr  r'  r
  *   r'  )ru  r>   rE   r   rC  r<   r  rv  r?   assertRaisesRegexrw  )r   ro  rE  r   rn  r   testAssertRaisesContext  sD   $z%Test_TestCase.testAssertRaisesContextc                 C   s  |  t |    W d    n1 sw   Y  |  t |  d W d    n1 s.w   Y  |  t |  t W d    n1 sHw   Y  |  t |  tdf W d    n1 sdw   Y  |  t |  ttf W d    d S 1 sw   Y  d S NrI   )r>   rw  r   rE   r   r   r   r   testAssertRaisesNoExceptionType  s   
"z-Test_TestCase.testAssertRaisesNoExceptionTypec                 C   s4   dd }t |}| t| | |t | d S )Nc                   S   s   zt  t y   t w r   )rE   r   r   r   r   func  s
   z4Test_TestCase.testAssertRaisesRefcount.<locals>.func)rb  getrefcountr>   rE   r<   )r   r  Zrefcountr   r   r   testAssertRaisesRefcount  s   
z&Test_TestCase.testAssertRaisesRefcountc                    s|   G dd dt   fdd}|  td| |  d| | t |  dd  W d    d S 1 s7w   Y  d S )Nc                   @   rg  )z:Test_TestCase.testAssertRaisesRegex.<locals>.ExceptionMockNrh  r   r   r   r   ri  '  rj  ri  c                      rk  rl  r   r   rn  r   r   ro  *  r@  z1Test_TestCase.testAssertRaisesRegex.<locals>.Stubzexpect$)ru  r|  recompiler>   rw  rx  r   rn  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 s:w   Y  W d    n1 sIw   Y  |  td) | j tdd	d
 W d    n1 shw   Y  W d    d S W d    d S 1 sw   Y  d S )Nz"^Exception not raised by <lambda>$r   c                   S   r   r   r   r   r   r   r   r:  6  r   z8Test_TestCase.testAssertNotRaisesRegex.<locals>.<lambda>c                   S   r   r   r   r   r   r   r   r:  :  r   r'  expectr
  rz  r{  )r|  r?   ru  r  r  rw  r   r   r   r   testAssertNotRaisesRegex2  s.   "z&Test_TestCase.testAssertNotRaisesRegexc                 C   *   G dd dt }| t| j|dd  d S )Nc                   @   rg  )z>Test_TestCase.testAssertRaisesRegexInvalidRegex.<locals>.MyExcNrh  r   r   r   r   MyExcF  rj  r  c                   S   r+  NTr   r   r   r   r   r:  H  r   zATest_TestCase.testAssertRaisesRegexInvalidRegex.<locals>.<lambda>)ru  r>   rw  r|  )r   r  r   r   r   !testAssertRaisesRegexInvalidRegexD     z/Test_TestCase.testAssertRaisesRegexInvalidRegexc                 C   r  )Nc                   @   rg  )z>Test_TestCase.testAssertWarnsRegexInvalidRegex.<locals>.MyWarnNrh  r   r   r   r   MyWarnL  rj  r  c                   S   r+  r  r   r   r   r   r   r:  N  r   z@Test_TestCase.testAssertWarnsRegexInvalidRegex.<locals>.<lambda>)Warningr>   rw  r\  )r   r  r   r   r    testAssertWarnsRegexInvalidRegexJ  r  z.Test_TestCase.testAssertWarnsRegexInvalidRegexc                 C   sZ   G dd dt j}|dtjd< z| ttjd W tjd= tjd= d S tjd= tjd= w )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@)rb  modulesr   r   r   r   __warningregistry__S  s   zNTest_TestCase.testAssertWarnsModifySysModules.<locals>.Foo.__warningregistry__N)r   r   r   propertyr  r   r   r   r   r   R  s    r   r   z@foo@rb   r  )types
ModuleTyperb  r  r  UserWarningr   warnrJ   r   r   r   testAssertWarnsModifySysModulesP  s   
z-Test_TestCase.testAssertWarnsModifySysModulesc              	   C   sB   dd }|  | jd| j td| |  | jd| j ttd| d S )Nc                   S   r=  NZ
Unexpected)ru  r   r   r   r   ro  _  r@  z9Test_TestCase.testAssertRaisesRegexMismatch.<locals>.Stubz*"\^Expected\$" does not match "Unexpected"z
^Expected$)r|  r?   ru  r  r  rx  r   r   r   testAssertRaisesRegexMismatch^  s   
z+Test_TestCase.testAssertRaisesRegexMismatchc                    s~   G dd dt   fdd}d}|  }| || W d    n1 s&w   Y  |j}| |  | |jd | d S )Nc                   @   rg  )z=Test_TestCase.testAssertRaisesExcValue.<locals>.ExceptionMockNrh  r   r   r   r   ri  n  rj  ri  c                    s    | r   r   )r   rn  r   r   ro  q  r@  z4Test_TestCase.testAssertRaisesExcValue.<locals>.Stubzparticular valuer   )ru  r>   rC  r   r<   r  )r   ro  vctxr$  r   rn  r   testAssertRaisesExcValuem  s   

z&Test_TestCase.testAssertRaisesExcValuec                 C   sL  |  t |   W d    n1 sw   Y  |  t | t W d    n1 s.w   Y  |  t | dd W d    n1 sIw   Y  |  t | td W d    n1 sdw   Y  |  t | tdfd W d    n1 sw   Y  |  t | ttfd W d    d S 1 sw   Y  d S NrI   r  )r>   rw  r|  rE   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    n1 s;w   Y  | t |  td  W d    n1 sVw   Y  t * t	dt | | j |  t| W d    n1 s}w   Y  W d    n1 sw   Y  t 2 t	dt | t |  t| W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )	Nc                   S      t dt d S r   r   r  RuntimeWarningr   r   r   r   _runtime_warn  r.   z<Test_TestCase.testAssertWarnsCallable.<locals>._runtime_warnr   categoryc                   S   r+  rt  r   r   r   r   r   r:    r   z7Test_TestCase.testAssertWarnsCallable.<locals>.<lambda>defaultrY  )
r  r  r  r   r  r>   r?   rw  r   r  r   r  r   r   r   testAssertWarnsCallable  s8   

"z%Test_TestCase.testAssertWarnsCallablec              
   C   sz  dd }t |d }| t}|  W d    n1 sw   Y  | ttf}|  W d    n1 s8w   Y  | |jt | |jjd d | 	d|j
 | |j|d  | t |  |  W d    n1 stw   Y  | t tjdtd W d    n1 sw   Y  | | j | t W d    n1 sw   Y  W d    n1 sw   Y  | | jd | jtdd	 W d    n1 sw   Y  W d    n1 sw   Y  | td  | jtd
d W d    n	1 sw   Y  W d    n	1 sw   Y  t > tdt | | j! | t |  W d    n	1 sCw   Y  W d    n	1 sSw   Y  W d    n	1 scw   Y  t F tdt | t! | t |  W d    n	1 sw   Y  W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nc                   S   r  r   r  r   r   r   r   r    r.   z;Test_TestCase.testAssertWarnsContext.<locals>._runtime_warnrI   r   r   test_case.pyr  r'  r
  rz  r{  r  rY  )inspectgetsourcelinesr  r  r  r   warningr<   r  r   r  linenor   r  r>   r?   r|  rw  r   r  r   r  Z_runtime_warn_linenorE  r   r   r   testAssertWarnsContext  st   

 $z$Test_TestCase.testAssertWarnsContextc                 C   sH  |  t |   W d    n1 sw   Y  |  t | d W d    n1 s.w   Y  |  t | t W d    n1 sHw   Y  |  t | tdf W d    n1 sdw   Y  |  t | ttf W d    n1 sw   Y  |  t | ttf W d    d S 1 sw   Y  d S r~  )r>   rw  r  r   r  ru  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 s&w   Y  | t |  tdd  W d    n1 sBw   Y  t , tdt | | j |  td|d W d    n1 skw   Y  W d    n1 szw   Y  | | j |  td|d W d    n1 sw   Y  t 7 td	t | t| jf |  td|d W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )
Nc                 S      t | t d S r   r  r
  r   r   r   r    r.   zATest_TestCase.testAssertWarnsRegexCallable.<locals>._runtime_warno+fooxc                   S   r+  rt  r   r   r   r   r   r:    r   z<Test_TestCase.testAssertWarnsRegexCallable.<locals>.<lambda>r  barzrY  )	r\  r  r>   r?   rw  r   r   r  r  r  r   r   r   testAssertWarnsRegexCallable  sH   

"z*Test_TestCase.testAssertWarnsRegexCallablec              
   C   sN  dd }t |d }| td}|d W d    n1 s w   Y  | |jt | |jjd d | d|j	 | |j
|d  | | j | td W d    n1 s^w   Y  W d    n1 smw   Y  | | jd  | jtddd	 W d    n1 sw   Y  W d    n1 sw   Y  | td  | jtdd
d W d    n1 sw   Y  W d    n1 sw   Y  t ? tdt | | j" | td |d W d    n1 sw   Y  W d    n	1 sw   Y  W d    n	1 sw   Y  | | j# | td |d W d    n	1 s8w   Y  W d    n	1 sHw   Y  t K tdt | t| jf# | td |d W d    n	1 sww   Y  W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nc                 S   r  r   r  r
  r   r   r   r    r.   z@Test_TestCase.testAssertWarnsRegexContext.<locals>._runtime_warnrI   r  r  r   r  r'  r
  rz  r{  r  r  rY  )r  r  r\  r  r   r  r<   r  r   r  r  r>   r?   r|  rw  r   r   r  r  r  r   r   r   testAssertWarnsRegexContext  sl   





 $z)Test_TestCase.testAssertWarnsRegexContextc                 C   s  |  t |   W d    n1 sw   Y  |  t | t W d    n1 s.w   Y  |  t | dd W d    n1 sIw   Y  |  t | td W d    n1 sdw   Y  |  t | tdfd W d    n1 sw   Y  |  t | ttfd W d    n1 sw   Y  |  t | ttfd W d    d S 1 sw   Y  d S r  )r>   rw  r\  r  r   ru  r   r   r   r   #testAssertWarnsRegexNoExceptionType2  s*   
"z1Test_TestCase.testAssertWarnsRegexNoExceptionTypec                 c   sB    t  }d V  W d    n1 sw   Y  | | d d S )Nr   )r	   r<   getvalue)r   bufr   r   r   assertNoStderrB  s
   zTest_TestCase.assertNoStderrc                 C   s^   |  t|t| t||D ]\}}| |tj | D ]\}}|  t||| qqd S r   )r<   r  zipr   logging	LogRecorditemsgetattr)r   recordsmatchesZrecmatchkr  r   r   r   assertLogRecordsH  s   zTest_TestCase.assertLogRecordsc              	   C   s   |   9 |  }td td W d    n1 sw   Y  | |jdg | |j	ddig W d    d S 1 s@w   Y  d S )N1rJ  
INFO:foo:1namer   )
r  
assertLogslog_fooinfo
log_foobarr   r<   outputr  r  r   rE  r   r   r   testAssertLogsDefaultsO  s   


"z$Test_TestCase.testAssertLogsDefaultsc              	   C   s   |   B |  }td td td W d    n1 s#w   Y  | |j	ddg | 
|jddiddig W d    d S 1 sIw   Y  d S )	Nr  rJ  3r  WARNING:quux:3r  r   r   r  r  r  r  r  r   log_quuxr  r<   r  r  r  r  r   r   r   !testAssertLogsTwoMatchingMessagesX  s   



"z/Test_TestCase.testAssertLogsTwoMatchingMessagesc              	   C   s   |   D | j|d}td td td W d    n1 s%w   Y  | |j	ddg | 
|jddidd	ig W d    d S 1 sKw   Y  d S )
Nlevelr  rJ  r  zERROR:foo.bar:2zCRITICAL:quux:3r  r   r   )r  r  r  r  r  rY  r  criticalr<   r  r  r  )r   r  rE  r   r   r   checkAssertLogsPerLevelc  s   


"z%Test_TestCase.checkAssertLogsPerLevelc                 C   s   |  tj |  d d S )NERROR)r  r  r  r   r   r   r   testAssertLogsPerLeveln  s   z$Test_TestCase.testAssertLogsPerLevelc              
   C   s   |   c | jddD}| j|dd}td td td W d    n1 s-w   Y  | |j	ddg | 
|jdd	idd
ig W d    n1 sRw   Y  | |j	dg W d    d S 1 sjw   Y  d S )NDEBUGr  r  rJ  r  r  zDEBUG:foo.bar:2r  r   r   r  r  )r   loggerZouter_cmrE  r   r   r   checkAssertLogsPerLoggerr  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   |   ; | | j |   W d    n1 sw   Y  W d    n1 s*w   Y  W d    d S W d    d S 1 sBw   Y  d S r   )r  r>   r?   r  r   r   r   r   testAssertLogsFailureNoLogs  s   

"z)Test_TestCase.testAssertLogsFailureNoLogsc              
   C   s   |   B | | j# | jdd td W d    n1 s"w   Y  W d    n1 s1w   Y  W d    d S W d    d S 1 sIw   Y  d S NWARNINGr  r  )r  r>   r?   r  r  r  r   r   r   r   !testAssertLogsFailureLevelTooHigh  s   
"z/Test_TestCase.testAssertLogsFailureLevelTooHighc              
   C   s   |   Q tj}ttj z8| | j# | jdd t	d W d    n1 s,w   Y  W d    n1 s;w   Y  W t| nt| w W d    d S 1 sXw   Y  d S r  )
r  r  r  setLevelr  INFOr>   r?   r  r  )r   ZoldLevelr   r   r   4testAssertLogsFailureLevelTooHigh_FilterInRootLogger  s   
"zBTest_TestCase.testAssertLogsFailureLevelTooHigh_FilterInRootLoggerc              
   C   s   | j dddA | | j" |  d td W d    n1 s$w   Y  W d    n1 s3w   Y  W d    d S W d    d S 1 sKw   Y  d S )Nr   r  r  r   r  )r  r>   r?   r  rY  r   r   r   r   &testAssertLogsFailureMismatchingLogger  s   "z4Test_TestCase.testAssertLogsFailureMismatchingLoggerc              	   C   R   |  t |   td1 sw   Y  W d    d S 1 s"w   Y  d S r  )r>   ZeroDivisionErrorr  r   r   r   r   !testAssertLogsUnexpectedException  
   
"z/Test_TestCase.testAssertLogsUnexpectedExceptionc              	   C   s~   |  | j&}|   td td W d    n1 s w   Y  W d    n1 s/w   Y  | t|j	d d S )Nr  rJ  z%Unexpected logs found: ['INFO:foo:1'])
r>   r?   assertNoLogsr  r  r  r   r<   r   rC  r  r   r   r   testAssertNoLogsDefault  s   

z%Test_TestCase.testAssertNoLogsDefaultc              	   C   s~   |  | j&}|   td td W d    n1 s w   Y  W d    n1 s/w   Y  | t|jd d S )Nr  r   z8Unexpected logs found: ['ERROR:quux:1', 'ERROR:foo:foo'])	r>   r?   r  r  rY  r  r<   r   rC  r  r   r   r    testAssertNoLogsFailureFoundLogs  s   

z.Test_TestCase.testAssertNoLogsFailureFoundLogsc              
   C   s   |   A | t# | jtd td W d    n1 s!w   Y  W d    n1 s0w   Y  W d    d S W d    d S 1 sHw   Y  d S )Nr  r  )r  r  r  r  r  rY  r   r   r   r   testAssertNoLogsPerLogger  s   
"z'Test_TestCase.testAssertNoLogsPerLoggerc              
   C   s   |  | j=}| t( | jtd td td W d    n1 s(w   Y  W d    n1 s7w   Y  W d    n1 sFw   Y  | 	t
|jd d S )Nr  r  rJ  z)Unexpected logs found: ['INFO:foo.bar:2'])r>   r?   r  r  r  r  rY  r  r  r<   r   rC  r  r   r   r    testAssertNoLogsFailurePerLogger  s   
z.Test_TestCase.testAssertNoLogsFailurePerLoggerc              	   C   s~   |   1 | jdd td td W d    n1 s w   Y  W d    d S W d    d S 1 s8w   Y  d S )Nr  r  r   r  )r  r  r  r  r  r   r   r   r   r   testAssertNoLogsPerLevel  s   

"z&Test_TestCase.testAssertNoLogsPerLevelc              	   C   s   |  | j(}| jdd td td W d    n1 s"w   Y  W d    n1 s1w   Y  | t|jd d S )Nr  r  r   r  z8Unexpected logs found: ['DEBUG:foo:foo', 'DEBUG:quux:1'])	r>   r?   r  r  r   r  r<   r   rC  r  r   r   r   testAssertNoLogsFailurePerLevel  s   
z-Test_TestCase.testAssertNoLogsFailurePerLevelc              	   C   r  r  )r>   r  r  r   r   r   r   #testAssertNoLogsUnexpectedException  r  z1Test_TestCase.testAssertNoLogsUnexpectedExceptionc                 C   s6   |   }W d    n1 sw   Y  | | d S r   )r  r   )r   valuer   r   r   testAssertNoLogsYieldsNone  s   
z(Test_TestCase.testAssertNoLogsYieldsNonec                 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   n1 slw   Y  qTdS )zY
        Test that the deprecated methods raise a DeprecationWarning. See #9424.
        )r:   r  r:   r:   )       @r  )g      @g      @)Tc                 S   s   dd S )NgQ	@Zspamr   )_r   r   r   r:         z9Test_TestCase.testDeprecatedMethodNames.<locals>.<lambda>)FrI   r;   r   r:   )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_failUnlessRaisesrw  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 ]}| t t| | W d   n1 s(w   Y  qdS )z9Test that the deprecated fail* methods get removed in 3.xNr;   r  )r  r  r  r  r  r  r   r  )rb  version_infor>   r@   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                   @   r   )z0Test_TestCase.testDeepcopy.<locals>.TestableTestc                 S   r   r   r   r   r   r   r   testNothing  rL   z<Test_TestCase.testDeepcopy.<locals>.TestableTest.testNothingN)r   r   r   r  r   r   r   r   TestableTest  r!   r  r  )r2   r3   r   )r   r  r#   r   r   r   testDeepcopy  s   zTest_TestCase.testDeepcopyc                 C   sV   t d}ttjd D ]}tj||d}t|}| || |t t  qd S )NrA   rI   )protocol)	r2   r3   r  pickle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}||||fD ]}| t |d  W d    n1 sUw   Y  q=d S )Nc                 S      t r   )KeyboardInterruptr   r   r   r   _raise6  rL   z3Test_TestCase.testKeyboardInterrupt.<locals>._raisec                 S   r   r   r   r   r   r   r   nothing8  rL   z4Test_TestCase.testKeyboardInterrupt.<locals>.nothingc                          e Zd Z ZdS )z2Test_TestCase.testKeyboardInterrupt.<locals>.Test1Nr   r   r   test_somethingr   r  r   r   Test1;  r   r  c                          e Zd Z ZZdS )z2Test_TestCase.testKeyboardInterrupt.<locals>.Test2Nr   r   r   r+   r  r   r  r  r   r   Test2>      r  c                          e Zd ZZ ZdS )z2Test_TestCase.testKeyboardInterrupt.<locals>.Test3Nr   r   r   r  r/   r   r  r   r   Test3B  r  r   c                       r   )z2Test_TestCase.testKeyboardInterrupt.<locals>.Test4c                       |    d S r   rB  r   r  r   r   r  G  r   zATest_TestCase.testKeyboardInterrupt.<locals>.Test4.test_somethingNr  r   r  r   r   Test4F  r   r#  r  r   )r2   r3   r>   r  rA   )r   r  r  r   r#  klassr   r  r   testKeyboardInterrupt5  s   
z#Test_TestCase.testKeyboardInterruptc                       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 q=d S )Nc                 S   s
   t d)Nzsome reason)r2   ZSkipTestr   r   r   r   _skipO  rg   z3Test_TestCase.testSkippingEverywhere.<locals>._skipc                 S   r   r   r   r   r   r   r   r  Q  rL   z5Test_TestCase.testSkippingEverywhere.<locals>.nothingc                       r  )z3Test_TestCase.testSkippingEverywhere.<locals>.Test1Nr  r   r'  r   r   r  T  r   r  c                       r  )z3Test_TestCase.testSkippingEverywhere.<locals>.Test2Nr  r   r'  r  r   r   r  W  r  r  c                       r  )z3Test_TestCase.testSkippingEverywhere.<locals>.Test3Nr  r   r)  r   r   r   [  r  r   c                       r   )z3Test_TestCase.testSkippingEverywhere.<locals>.Test4c                    r!  r   r"  r   r(  r   r   r  `  r   zBTest_TestCase.testSkippingEverywhere.<locals>.Test4.test_somethingNr  r   r(  r   r   r#  _  r   r#  r  rI   r   )r2   r3   rP   rA   r<   r  ZskippedtestsRunr   r  r  r   r#  r$  rQ   r   r)  r   testSkippingEverywhereN     
z$Test_TestCase.testSkippingEverywherec                    r&  )Nc                 S   r  r   )
SystemExitr   r   r   r   r  j  rL   z,Test_TestCase.testSystemExit.<locals>._raisec                 S   r   r   r   r   r   r   r   r  l  rL   z-Test_TestCase.testSystemExit.<locals>.nothingc                       r  )z+Test_TestCase.testSystemExit.<locals>.Test1Nr  r   r  r   r   r  o  r   r  c                       r  )z+Test_TestCase.testSystemExit.<locals>.Test2Nr  r   r  r   r   r  r  r  r  c                       r  )z+Test_TestCase.testSystemExit.<locals>.Test3Nr  r   r  r   r   r   v  r  r   c                       r   )z+Test_TestCase.testSystemExit.<locals>.Test4c                    r!  r   r"  r   r  r   r   r  {  r   z:Test_TestCase.testSystemExit.<locals>.Test4.test_somethingNr  r   r  r   r   r#  z  r   r#  r  rI   r   )r2   r3   rP   rA   r<   r  errorsr*  r+  r   r  r   testSystemExiti  r-  zTest_TestCase.testSystemExitc                 C   sN   t  }t|}t  ~| |  W d    d S 1 s w   Y  d S r   )r2   r3   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 r~  )	ninstanceru  r&   r   r6   r   r   r&     r{   zBTest_TestCase.test_no_exception_leak.<locals>.MyException.__init__c                    s     j d8  _ d S r~  )r5  r   r6   r   r   __del__  r   zATest_TestCase.test_no_exception_leak.<locals>.MyException.__del__N)r   r   r   r5  r&   r6  r   r6   r   r   r7     s    r7   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                         r   r   r   r6   r   r   r     r   z<Test_TestCase.test_no_exception_leak.<locals>.TestCase.test1c                    r7  r   r   r   r6   r   r   r     s   z<Test_TestCase.test_no_exception_leak.<locals>.TestCase.test2N)r   r   r   r   r2   ZexpectedFailurer   r   r6   r   r   r3     s    r3   )r   r   r   )ru  r2   r3   rA   r
   r<   r5  )r   r3   Zmethod_nameZtestcaser   r6   r   test_no_exception_leak  s   
z$Test_TestCase.test_no_exception_leakN)|r   r   r   r   r   Zeq_pairsr    Zne_pairsrB   rD   rG   rK   rR   rc   rm   rt   rx   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r2   ZskipIfrb  rc  optimizer   r   r   r   r   r   r   r   r   r	  r  r  r%  r*  r/  r1  rF  rH  rS  rU  rV  rZ  r[  rd  re  rf  ry  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r_  contextmanagerr  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,  r0  r   Zcpython_onlyr4  r8  r   r   r   r   r4   9   s    

		
	


	"%4($>(:L 0!,
	

r4   __main__)#r_  r  r  r  r  rb  r  r   r1  r  r  copyr   r#   r   r2   Zunittest.test.supportr   r   r   r   r   Ztest.supportr	   r
   r  r  r  r  r   r   r3   r4   r   mainr   r   r   r   <module>   sL    


              }