a
    ze8C                     @   sp   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 G dd dejZ	G dd dejZ
edkrle  dS )	    N)
gc_collect)productc                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )Test_Assertionsc                 C   s   |  dd | dd | | j| j dd | | j| jdd | j dddd | j| j| j dddd | j dddd | jdddd | j| j| j dddd | j| j| jdddd |  td	td	 | | j| jtd	td	 d S )
Ng1  ?      ?g  ?皙?r   )places   y??inf)assertAlmostEqualassertNotAlmostEqualassertRaisesfailureExceptionfloatself r   3/usr/lib/python3.9/unittest/test/test_assertions.pytest_AlmostEqual
   s0    


z Test_Assertions.test_AlmostEqualc                 C   s  | j dddd | j dddd | jdddd | jdddd | j dddd | j| j| jdddd | j| j| j dddd | j| j| jdddd | jt| j ddddd | jt| jddddd tj }|tjdd	 }| j ||tjd
d	d | j||tjdd	d d S )Nr   r   g      ?)deltag?   )r   r   
   )Zseconds      )r
   r   r   r   	TypeErrordatetimeZnowZ	timedelta)r   firstsecondr   r   r   test_AmostEqualWithDelta!   s8    




z(Test_Assertions.test_AmostEqualWithDeltac                 C   s  dd }|  t|t |  t|td z|  tdd  W n6 | jyr } z| dt| W Y d }~nd }~0 0 | d z|  t|t W n ty   Y n0 | d |  tD}ztW n* ty } z|} W Y d }~n
d }~0 0 W d    n1 s0    Y  | |j	| |  t tdW d    n1 sF0    Y  z0|  t W d    n1 st0    Y  W n8 | jy } z| dt| W Y d }~nd }~0 0 | d z4|  t tW d    n1 s0    Y  W n ty   Y n0 | d d S )	Nc                 S   s   | d S Nr   )er   r   r   _raise=   s    z1Test_Assertions.test_assertRaises.<locals>._raisekeyc                   S   s   d S r   r   r   r   r   r   <lambda>B       z3Test_Assertions.test_assertRaises.<locals>.<lambda>zKeyError not raisedzassertRaises() didn't failz0assertRaises() didn't let exception pass through)
r   KeyErrorr   assertInstrfail
ValueError	ExceptionassertIs	exception)r   r    r   cmexcr   r   r   test_assertRaises<   sD    &

8($&
(z!Test_Assertions.test_assertRaisesc                    sj   G dd d d G  fdddt j}|d  t  |   |d  t  |   d S )Nc                   @   s   e Zd ZdS )z<Test_Assertions.test_assertRaises_frames_survival.<locals>.AN)__name__
__module____qualname__r   r   r   r   Ai   s   r2   c                       s*   e Zd Z fddZdd Zdd ZdS )z>Test_Assertions.test_assertRaises_frames_survival.<locals>.Fooc                    s4     }t |ztW n ty.   tY n0 d S r   )weakrefrefOSErrorr(   )r   ar2   wrr   r   fooo   s    
zBTest_Assertions.test_assertRaises_frames_survival.<locals>.Foo.fooc                 S   s   |  t| j d S r   r   r(   r9   r   r   r   r   test_functionalx   s    zNTest_Assertions.test_assertRaises_frames_survival.<locals>.Foo.test_functionalc                 S   s6   |  t |   W d    n1 s(0    Y  d S r   r:   r   r   r   r   	test_with{   s    zHTest_Assertions.test_assertRaises_frames_survival.<locals>.Foo.test_withN)r/   r0   r1   r9   r;   r<   r   r7   r   r   Foom   s   	r=   r;   r<   )unittestTestCaserunr   assertIsNone)r   r=   r   r7   r   !test_assertRaises_frames_survivalf   s    z1Test_Assertions.test_assertRaises_frames_survivalc              
   C   sf   |  dd z|  ddd W n8 | jyV } z| d|jd  W Y d }~nd }~0 0 | d d S )NzAla ma kotazr+zk.tZMessager   z"assertNotRegex should have failed.)assertNotRegexr   r%   argsr'   )r   r   r   r   r   testAssertNotRegex   s    (z"Test_Assertions.testAssertNotRegexN)r/   r0   r1   r   r   r.   rB   rE   r   r   r   r   r   	   s
   * r   c                   @   s  e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dDS )ETestLongMessagezTest that the individual asserts honour longMessage.
    This actually tests all the message behaviour for
    asserts that use longMessage.c                    sD   G  fdddt j}G  fdddt j}|d _|d _d S )Nc                       s   e Zd ZdZ jZdd ZdS )z0TestLongMessage.setUp.<locals>.TestableTestFalseFc                 S   s   d S r   r   r   r   r   r   testTest   s    z9TestLongMessage.setUp.<locals>.TestableTestFalse.testTestNr/   r0   r1   longMessager   rG   r   r   r   r   TestableTestFalse   s   rJ   c                       s   e Zd ZdZ jZdd ZdS )z/TestLongMessage.setUp.<locals>.TestableTestTrueTc                 S   s   d S r   r   r   r   r   r   rG      s    z8TestLongMessage.setUp.<locals>.TestableTestTrue.testTestNrH   r   r   r   r   TestableTestTrue   s   rK   rG   )r>   r?   testableTruetestableFalse)r   rJ   rK   r   r   r   setUp   s    
zTestLongMessage.setUpc                 C   s   |  tjj d S r   )
assertTruer>   r?   rI   r   r   r   r   testDefault   s    zTestLongMessage.testDefaultc                 C   sl   |  | jd dd |  | jddd |  | jd dd |  | jddd | jt d d S )Nr9   barz	bar : foo)ZassertEqualrM   _formatMessagerL   objectr   r   r   r   test_formatMsg   s
    zTestLongMessage.test_formatMsgc                 C   s*   d dd tdD }| j|d d S )N c                 s   s   | ]}t |V  qd S r   )chr).0ir   r   r   	<genexpr>   r#   zCTestLongMessage.test_formatMessage_unicode_error.<locals>.<genexpr>   u   �)joinrangerL   rR   )r   Zoner   r   r    test_formatMessage_unicode_error   s    z0TestLongMessage.test_formatMessage_unicode_errorc           
   	      s    fdd}t |D ]f\}}||}i }|d }	|	r>ddi}jj|d ||i | W d   q1 sr0    Y  qdS )a_  
        Check that methodName(*args) raises the correct error messages.
        errors should be a list of 4 regex that match the error when:
          1) longMessage = False and no msg passed;
          2) longMessage = False and msg passed;
          3) longMessage = True and no msg passed;
          4) longMessage = True and msg passed;
        c                    s$   | dk }|rj }nj}t| S )Nr   )rM   rL   getattr)rX   ZuseTestableFalsetest
methodNamer   r   r   	getMethod   s
    z1TestLongMessage.assertMessages.<locals>.getMethodr   msgoops)expected_regexN)	enumerateassertRaisesRegexr   )
r   ra   rD   errorsrb   rX   re   Z
testMethodkwargsZwithMsgr   r`   r   assertMessages   s    	zTestLongMessage.assertMessagesc                 C   s   |  ddg d d S )NrO   )F)^False is not true$^oops$rk   z^False is not true : oops$rj   r   r   r   r   testAssertTrue   s    zTestLongMessage.testAssertTruec                 C   s   |  ddg d d S )NZassertFalse)T)^True is not false$rl   ro   z^True is not false : oops$rm   r   r   r   r   testAssertFalse   s    zTestLongMessage.testAssertFalsec                 C   s   |  ddg d d S )NZassertNotEqualr   r   )^1 == 1$rl   rr   z^1 == 1 : oops$rm   r   r   r   r   testNotEqual   s    zTestLongMessage.testNotEqualc                 C   s   |  ddg d d S )Nr
   r   r   ))^1 != 2 within 7 places \(1 difference\)$rl   ru   z0^1 != 2 within 7 places \(1 difference\) : oops$rm   r   r   r   r   testAlmostEqual   s    zTestLongMessage.testAlmostEqualc                 C   s   |  ddg d d S )Nr   rq   )^1 == 1 within 7 places$rl   rw   z^1 == 1 within 7 places : oops$rm   r   r   r   r   testNotAlmostEqual   s    z"TestLongMessage.testNotAlmostEqualc                 C   s   |  ddg d d S )NZ_baseAssertEqualrt   )^1 != 2$rl   ry   z^1 != 2 : oops$rm   r   r   r   r   test_baseAssertEqual   s    z$TestLongMessage.test_baseAssertEqualc                 C   s   |  dg d gfg d d S )NZassertSequenceEqual)\+ \[None\]$rl   r{   z\+ \[None\] : oops$rm   r   r   r   r   testAssertSequenceEqual   s    z'TestLongMessage.testAssertSequenceEqualc                 C   s"   |  dt td gfg d d S )NZassertSetEqual)None$rl   r}   zNone : oops$)rj   setr   r   r   r   testAssertSetEqual   s    z"TestLongMessage.testAssertSetEqualc                 C   s   |  dd g fg d d S )Nr%   )^None not found in \[\]$rl   r   z^None not found in \[\] : oops$rm   r   r   r   r   testAssertIn   s    zTestLongMessage.testAssertInc                 C   s   |  dd d gfg d d S )NZassertNotIn)%^None unexpectedly found in \[None\]$rl   r   z,^None unexpectedly found in \[None\] : oops$rm   r   r   r   r   testAssertNotIn  s    zTestLongMessage.testAssertNotInc                 C   s   |  di ddifg d d S )NZassertDictEqualr!   value)\+ \{'key': 'value'\}$rl   r   z\+ \{'key': 'value'\} : oops$rm   r   r   r   r   testAssertDictEqual  s    z#TestLongMessage.testAssertDictEqualc                 C   sR   t  6 t dt | dddii fg d W d    n1 sD0    Y  d S )NignoreZassertDictContainsSubsetr!   r   )^Missing: 'key'$rl   r   z^Missing: 'key' : oops$)warningscatch_warningssimplefilterDeprecationWarningrj   r   r   r   r   testAssertDictContainsSubset  s
    
z,TestLongMessage.testAssertDictContainsSubsetc                 C   s   |  ddg d d S )NZassertMultiLineEqual)rU   r9   )\+ foo$rl   r   z\+ foo : oops$rm   r   r   r   r   testAssertMultiLineEqual  s    z(TestLongMessage.testAssertMultiLineEqualc                 C   s   |  ddg d d S )NZ
assertLessr   r   )^2 not less than 1$rl   r   z^2 not less than 1 : oops$rm   r   r   r   r   testAssertLess!  s    zTestLongMessage.testAssertLessc                 C   s   |  ddg d d S )NZassertLessEqualr   )^2 not less than or equal to 1$rl   r   z&^2 not less than or equal to 1 : oops$rm   r   r   r   r   testAssertLessEqual&  s    z#TestLongMessage.testAssertLessEqualc                 C   s   |  ddg d d S )NZassertGreaterrt   )^1 not greater than 2$rl   r   z^1 not greater than 2 : oops$rm   r   r   r   r   testAssertGreater,  s    z!TestLongMessage.testAssertGreaterc                 C   s   |  ddg d d S )NZassertGreaterEqualrt   )"^1 not greater than or equal to 2$rl   r   z)^1 not greater than or equal to 2 : oops$rm   r   r   r   r   testAssertGreaterEqual2  s    z&TestLongMessage.testAssertGreaterEqualc                 C   s   |  ddg d d S )NrA   )znot None)^'not None' is not None$rl   r   z^'not None' is not None : oops$rm   r   r   r   r   testAssertIsNone8  s    z TestLongMessage.testAssertIsNonec                 C   s   |  ddg d d S )NZassertIsNotNoner   )^unexpectedly None$rl   r   z^unexpectedly None : oops$rm   r   r   r   r   testAssertIsNotNone>  s    z#TestLongMessage.testAssertIsNotNonec                 C   s   |  ddg d d S )Nr*   Nr9   )^None is not 'foo'$rl   r   z^None is not 'foo' : oops$rm   r   r   r   r   testAssertIsD  s    zTestLongMessage.testAssertIsc                 C   s   |  ddg d d S )NZassertIsNot)NN)^unexpectedly identical: None$rl   r   z%^unexpectedly identical: None : oops$rm   r   r   r   r   testAssertIsNotJ  s    zTestLongMessage.testAssertIsNotc                 C   s   |  ddg d d S )NZassertRegex)r9   rQ   )^Regex didn't match:rl   r   z!^Regex didn't match: (.*) : oops$rm   r   r   r   r   testAssertRegexP  s    zTestLongMessage.testAssertRegexc                 C   s   |  ddg d d S )NrC   )r9   r9   )^Regex matched:rl   r   z^Regex matched: (.*) : oops$rm   r   r   r   r   rE   W  s    z"TestLongMessage.testAssertNotRegexc              
   C   s   t | j| jfi ddif}t||D ]x\\}}}t||}	| |j|D |	|i |}
|  W d   n1 st0    Y  W d   q$1 s0    Y  q$dS )a  
        Check that the correct error messages are raised while executing:
          with method(*args):
              func()
        *errors* should be a list of 4 regex that match the error when:
          1) longMessage = False and no msg passed;
          2) longMessage = False and msg passed;
          3) longMessage = True and no msg passed;
          4) longMessage = True and msg passed;
        rc   rd   N)r   rM   rL   zipr^   rg   r   )r   ra   rD   funcrh   pclsri   errmethodr,   r   r   r   assertMessagesCM_  s    

z TestLongMessage.assertMessagesCMc                 C   s   |  dtfdd g d d S )Nr   c                   S   s   d S r   r   r   r   r   r   r"   s  r#   z2TestLongMessage.testAssertRaises.<locals>.<lambda>^TypeError not raised$rl   r   z^TypeError not raised : oops$r   r   r   r   r   r   testAssertRaisesr  s    z TestLongMessage.testAssertRaisesc                 C   s@   |  dtdfdd g d dd }|  dtdf|g d	 d S )
Nrg   unused regexc                   S   s   d S r   r   r   r   r   r   r"   {  r#   z7TestLongMessage.testAssertRaisesRegex.<locals>.<lambda>r   c                   S   s   t dd S r   )r   r   r   r   r   raise_wrong_message  s    zBTestLongMessage.testAssertRaisesRegex.<locals>.raise_wrong_messageregex^"regex" does not match "foo"$rl   r   z%^"regex" does not match "foo" : oops$r   r   r   r   r   r   testAssertRaisesRegexx  s    z%TestLongMessage.testAssertRaisesRegexc                 C   s   |  dtfdd g d d S )NZassertWarnsc                   S   s   d S r   r   r   r   r   r   r"     r#   z1TestLongMessage.testAssertWarns.<locals>.<lambda>^UserWarning not triggered$rl   r   z"^UserWarning not triggered : oops$r   UserWarningr   r   r   r   testAssertWarns  s    zTestLongMessage.testAssertWarnsc                 C   s@   |  dtdfdd g d dd }|  dtdf|g d	 d S )
NZassertWarnsRegexr   c                   S   s   d S r   r   r   r   r   r   r"     r#   z6TestLongMessage.testAssertWarnsRegex.<locals>.<lambda>r   c                   S   s   t d d S r   )r   warnr   r   r   r   r     s    zATestLongMessage.testAssertWarnsRegex.<locals>.raise_wrong_messager   r   r   r   r   r   r   testAssertWarnsRegex  s    z$TestLongMessage.testAssertWarnsRegexN)%r/   r0   r1   __doc__rN   rP   rT   r]   rj   rn   rp   rs   rv   rx   rz   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rE   r   r   r   r   r   r   r   r   r   rF      sD   
	rF   __main__)r   r   r3   r>   Ztest.supportr   	itertoolsr   r?   r   rF   r/   mainr   r   r   r   <module>   s      