
    dafA                         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ej                        Z	 G d dej                        Z
edk(  r ej                          yy)	    N)
gc_collect)productc                   *    e Zd Zd Zd Zd Zd Zd Zy)Test_Assertionsc                    | j                  dd       | j                  dd       | j                  | j                  | j                   dd       | j                  | j                  | j                  dd       | j                  ddd       | j                  | j                  | j                   ddd       | j                  ddd       | j                  ddd       | j                  | j                  | j                   ddd       | j                  | j                  | j                  ddd       | j                  t	        d	      t	        d	             | j                  | j                  | j                  t	        d	      t	        d	             y )
Ng1  ?      ?g  ?皙?r   )places   y??inf)assertAlmostEqualassertNotAlmostEqualassertRaisesfailureExceptionfloatselfs    =/root/Python-3.12.4/Lib/test/test_unittest/test_assertions.pytest_AlmostEqualz Test_Assertions.test_AlmostEqual
   ss   z3/!!)S1$//00)S	B$//33Z	F 	sC2$//00#s1 	 	F 	q&3!!!VA!6$//00!VA 	 	G$//33Qq 	 	J 	uU|U5\:$//1J1J,e	6    c                 j   | j                  ddd       | j                  ddd       | j                  ddd       | j                  ddd       | j                  ddd       | j                  | j                  | j                  ddd       | j                  | j                  | j                   ddd       | j                  | j                  | j                  ddd       | j                  t        | j                   dddd       | j                  t        | j                  dddd       t
        j
                  j                         }|t        j                  d	      z   }| j                  ||t        j                  d
	             | j                  ||t        j                  d	             y )Nr	   r   g      ?)deltag?   )r
   r   
   )seconds      )r   r   r   r   	TypeErrordatetimenow	timedelta)r   firstseconds      r   test_AmostEqualWithDeltaz(Test_Assertions.test_AmostEqualWithDelta!   s   sCs3sCs3!!#s$!7!!#s$!7sCs3$//1J1Js# 	 	/ 	$//1G1Gs$ 	 	0$//1J1Js# 	 	/ 	)T%;%;s1A 	 	7)T%>%>s1A 	 	7 !!%%'++B77uf%-%7%7%C 	 	E!!%(0(:(:1(E 	" 	Gr   c                 D   d }| j                  t        |t               | j                  t        |t        d             	 | j                  t        d        | j                  d       	 | j                  t        |t               | j                  d       | j                  t              5 }	 t        # | j                  $ r%}| j	                  dt        |             Y d }~yd }~ww xY w# t        $ r Y _w xY w# t        $ r}|} d }~ww xY w# 1 sw Y   nxY w| j                  j                         | j                  t              5  t        d      # 1 sw Y   nxY w	 | j                  t              5  	 d d d        n# 1 sw Y   nxY w| j                  d       n7# | j                  $ r%}| j	                  dt        |             Y d }~nd }~ww xY w	 | j                  t              5  t        # 1 sw Y   nxY w	 | j                  d       y # t        $ r Y y w xY w)Nc                     | N )es    r   _raisez1Test_Assertions.test_assertRaises.<locals>._raise=   s    Gr   keyc                       y r'   r(   r(   r   r   <lambda>z3Test_Assertions.test_assertRaises.<locals>.<lambda>B       r   zassertRaises() didn't failzKeyError not raisedz0assertRaises() didn't let exception pass through)
r   KeyErrorfailr   assertInstr
ValueError	ExceptionassertIs	exception)r   r*   r)   cmexcs        r   test_assertRaisesz!Test_Assertions.test_assertRaises<   s   	(FH5(FHUO<	4h5 II23	Jh
; IIHIx( 	B $$ 	9MM/Q88	9  		  	 	 	bllC(x( 	"5/!	" 	"	4""8,   
 II23 $$ 	9MM/Q88	9	J""8, !  ! ! !
 IIHI  		s    B2 )C) *D,C82C&C!!C&)	C54C58	D	DD		DD	EE"F  7F9	F  FF   G/GGH -G44G=9H 	HHc                 0    G d d      d  G fddt         j                        } |d      j                          t                | j	                                  |d      j                          t                | j	                                 y )Nc                       e Zd Zy)<Test_Assertions.test_assertRaises_frames_survival.<locals>.AN)__name__
__module____qualname__r(   r   r   Ar<   i   s    r   r@   c                   &    e Zd Z fdZd Zd Zy)>Test_Assertions.test_assertRaises_frames_survival.<locals>.Fooc                 p            }t        j                  |      	 t        # t        $ r t        w xY wr'   )weakrefrefOSErrorr3   )r   ar@   wrs     r   foozBTest_Assertions.test_assertRaises_frames_survival.<locals>.Foo.fooo   s6    C[[^%!M %$$%s   % 5c                 D    | j                  t        | j                         y r'   r   r3   rI   r   s    r   test_functionalzNTest_Assertions.test_assertRaises_frames_survival.<locals>.Foo.test_functionalx   s    !!*dhh7r   c                 x    | j                  t              5  | j                          d d d        y # 1 sw Y   y xY wr'   rK   r   s    r   	test_withzHTest_Assertions.test_assertRaises_frames_survival.<locals>.Foo.test_with{   s.    &&z2 HHJ  s   09N)r=   r>   r?   rI   rL   rN   )r@   rH   s   r   FoorB   m   s    %8r   rO   rL   rN   )unittestTestCaserunr   assertIsNone)r   rO   r@   rH   s     @@r   !test_assertRaises_frames_survivalz1Test_Assertions.test_assertRaises_frames_survivalf   ss    	 		(## 	$ 	""$"$K"$r   c                     | j                  dd       	 | j                  ddd       | j                  d       y # | j                  $ r)}| j                  d|j                  d          Y d }~y d }~ww xY w)NzAla ma kotazr+zk.tMessagez"assertNotRegex should have failed.r   )assertNotRegexr0   r   r1   args)r   r)   s     r   testAssertNotRegexz"Test_Assertions.testAssertNotRegex   si    M51	<vyA II:; $$ 	0MM)QVVAY//	0s   9 A1A,,A1N)r=   r>   r?   r   r$   r9   rT   rY   r(   r   r   r   r   	   s    6.G6(JT @<r   r   c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#y")#TestLongMessagezTest that the individual asserts honour longMessage.
    This actually tests all the message behaviour for
    asserts that use longMessage.c                       G  fddt         j                        } G  fddt         j                        } |d       _         |d       _        y )Nc                   2    e Zd ZdZW  j                  Zd Zy)0TestLongMessage.setUp.<locals>.TestableTestFalseFc                      y r'   r(   r   s    r   testTestz9TestLongMessage.setUp.<locals>.TestableTestFalse.testTest       r   Nr=   r>   r?   longMessager   r`   r   s   r   TestableTestFalser^      s    K#44r   rd   c                   2    e Zd ZdZW  j                  Zd Zy)/TestLongMessage.setUp.<locals>.TestableTestTrueTc                      y r'   r(   r   s    r   r`   z8TestLongMessage.setUp.<locals>.TestableTestTrue.testTest   ra   r   Nrb   r   s   r   TestableTestTruerf      s    K#44r   rh   r`   )rP   rQ   testableTruetestableFalse)r   rd   rh   s   `  r   setUpzTestLongMessage.setUp   sC    	 1 1 		x00 	 -Z8.z:r   c                 V    | j                  t        j                  j                         y r'   )
assertTruerP   rQ   rc   r   s    r   testDefaultzTestLongMessage.testDefault   s    ))556r   c                    | j                  | j                  j                  d d      d       | j                  | j                  j                  dd      d       | j                  | j                  j                  d d      d       | j                  | j                  j                  dd      d       | j                  j                  t	               d       y )NrI   barz	bar : foo)assertEqualrj   _formatMessageri   objectr   s    r   test_formatMsgzTestLongMessage.test_formatMsg   s    ++::4GO++::5%H%P**99$FN**99%GU 	((59r   c                 ~    dj                  d t        d      D              }| j                  j                  |d       y )N c              3   2   K   | ]  }t        |        y wr'   )chr).0is     r   	<genexpr>zCTestLongMessage.test_formatMessage_unicode_error.<locals>.<genexpr>   s     1c!f1s      u   �)joinrangeri   rr   )r   ones     r    test_formatMessage_unicode_errorz0TestLongMessage.test_formatMessage_unicode_error   s0    gg1eCj11((h7r   c                       fd}t        |      D ]H  \  }} ||      }i }|dz  }	|	rddi} j                   j                  |      5   ||i | ddd       J y# 1 sw Y   UxY w)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                 \    | dk  }|rj                   }nj                  }t        |      S )Nr   )rj   ri   getattr)rz   useTestableFalsetest
methodNamer   s      r   	getMethodz1TestLongMessage.assertMessages.<locals>.getMethod   s3     !A))((4,,r   r   msgoops)expected_regexN)	enumerateassertRaisesRegexr   )
r   r   rX   errorsr   rz   r   
testMethodkwargswithMsgs
   ``        r   assertMessageszTestLongMessage.assertMessages   s    	- "+6!2 		,A~"1JF!eG''(=(=7E ( G ,D+F+, ,		,, ,s   	A  A)	c                 .    | j                  ddg d       y )Nrm   )F)^False is not true$^oops$r   z^False is not true : oops$r   r   s    r   testAssertTruezTestLongMessage.testAssertTrue   s    L(;	<r   c                 .    | j                  ddg d       y )NassertFalse)T)^True is not false$r   r   z^True is not false : oops$r   r   s    r   testAssertFalsezTestLongMessage.testAssertFalse   s    M7;	<r   c                 .    | j                  ddg d       y )NassertNotEqualr   r   )^1 == 1$r   r   z^1 == 1 : oops$r   r   s    r   testNotEqualzTestLongMessage.testNotEqual   s    ,f0	1r   c                 .    | j                  ddg d       y )Nr   r   r   ))^1 != 2 within 7 places \(1 difference\)$r   r   z0^1 != 2 within 7 places \(1 difference\) : oops$r   r   s    r   testAlmostEqualzTestLongMessage.testAlmostEqual   s    B	Cr   c                 .    | j                  ddg d       y )Nr   r   )^1 == 1 within 7 places$r   r   z^1 == 1 within 7 places : oops$r   r   s    r   testNotAlmostEqualz"TestLongMessage.testNotAlmostEqual   s    2F\	]r   c                 .    | j                  ddg d       y )N_baseAssertEqualr   )^1 != 2$r   r   z^1 != 2 : oops$r   r   s    r   test_baseAssertEqualz$TestLongMessage.test_baseAssertEqual   s    .Q	Sr   c                 4    | j                  dg d gfg d       y )NassertSequenceEqual)\+ \[None\]$r   r   z\+ \[None\] : oops$r   r   s    r   testAssertSequenceEqualz'TestLongMessage.testAssertSequenceEqual   s"     	1B<5	6r   c                 V    | j                  dt               t        d g      fg d       y )NassertSetEqual)None$r   r   zNone : oops$)r   setr   s    r   testAssertSetEqualz"TestLongMessage.testAssertSetEqual   s'    ,suc4&k.B-	.r   c                 2    | j                  dd g fg d       y )Nr1   )^None not found in \[\]$r   r   z^None not found in \[\] : oops$r   r   s    r   testAssertInzTestLongMessage.testAssertIn   s    Jr
A	Br   c                 4    | j                  dd d gfg d       y )NassertNotIn)%^None unexpectedly found in \[None\]$r   r   z,^None unexpectedly found in \[None\] : oops$r   r   s    r   testAssertNotInzTestLongMessage.testAssertNotIn  s!    MD4&>N	Or   c                 6    | j                  di ddifg d       y )NassertDictEqualr+   value)\+ \{'key': 'value'\}$r   r   z\+ \{'key': 'value'\} : oops$r   r   s    r   testAssertDictEqualz#TestLongMessage.testAssertDictEqual  s%    -UG4D/E?	@r   c                 .    | j                  ddg d       y )NassertMultiLineEqual)rv   rI   )	\+ foo\n$r   r   z\+ foo\n : oops$r   r   s    r   testAssertMultiLineEqualz(TestLongMessage.testAssertMultiLineEqual  s    2K2	3r   c                 .    | j                  ddg d       y )N
assertLessr   r   )^2 not less than 1$r   r   z^2 not less than 1 : oops$r   r   s    r   testAssertLesszTestLongMessage.testAssertLess  s    L&R	Sr   c                 .    | j                  ddg d       y )NassertLessEqualr   )^2 not less than or equal to 1$r   r   z&^2 not less than or equal to 1 : oops$r   r   s    r   testAssertLessEqualz#TestLongMessage.testAssertLessEqual  s    -vG	Hr   c                 .    | j                  ddg d       y )NassertGreaterr   )^1 not greater than 2$r   r   z^1 not greater than 2 : oops$r   r   s    r   testAssertGreaterz!TestLongMessage.testAssertGreater#  s    OV>	?r   c                 .    | j                  ddg d       y )NassertGreaterEqualr   )"^1 not greater than or equal to 2$r   r   z)^1 not greater than or equal to 2 : oops$r   r   s    r   testAssertGreaterEqualz&TestLongMessage.testAssertGreaterEqual)  s    0&J	Kr   c                 .    | j                  ddg d       y )NrS   )znot None)^'not None' is not None$r   r   z^'not None' is not None : oops$r   r   s    r   testAssertIsNonez TestLongMessage.testAssertIsNone/  s    NM@	Ar   c                 .    | j                  ddg d       y )NassertIsNotNoner'   )^unexpectedly None$r   r   z^unexpectedly None : oops$r   r   s    r   testAssertIsNotNonez#TestLongMessage.testAssertIsNotNone5  s    -w;	<r   c                 .    | j                  ddg d       y )Nr5   NrI   )^None is not 'foo'$r   r   z^None is not 'foo' : oops$r   r   s    r   testAssertIszTestLongMessage.testAssertIs;  s    J;	<r   c                 .    | j                  ddg d       y )NassertIsNot)NN)^unexpectedly identical: None$r   r   z%^unexpectedly identical: None : oops$r   r   s    r   testAssertIsNotzTestLongMessage.testAssertIsNotA  s    M<F	Gr   c                 .    | j                  ddg d       y )NassertRegex)rI   rp   )^Regex didn't match:r   r   z!^Regex didn't match: (.*) : oops$r   r   s    r   testAssertRegexzTestLongMessage.testAssertRegexG  s    M>B	Cr   c                 .    | j                  ddg d       y )NrW   )rI   rI   )^Regex matched:r   r   z^Regex matched: (.*) : oops$r   r   s    r   rY   z"TestLongMessage.testAssertNotRegexN  s    ,n=	>r   c                 @   t        | j                  | j                  fi ddif      }t        ||      D ]Q  \  \  }}}t	        ||      }	| j                  |j                  |      5   |	|i |5 }
 |        ddd       ddd       S y# 1 sw Y   xY w# 1 sw Y   jxY w)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;
        r   r   N)r   rj   ri   zipr   r   r   )r   r   rX   funcr   pclsr   errmethodr7   s              r   assertMessagesCMz TestLongMessage.assertMessagesCMV  s     T''):):;%)+"%a. 	MS&3S*-F''(<(<cB T,V, F 	  s$   $	B-B5BBBB	c                 <    | j                  dt        fd g d       y )Nr   c                       y r'   r(   r(   r   r   r-   z2TestLongMessage.testAssertRaises.<locals>.<lambda>j  r.   r   ^TypeError not raised$r   r   z^TypeError not raised : oops$r   r   r   s    r   testAssertRaisesz TestLongMessage.testAssertRaisesi  s    nylL@	Ar   c                 |    | j                  dt        dfd g d       d }| j                  dt        df|g d       y )Nr   unused regexc                       y r'   r(   r(   r   r   r-   z7TestLongMessage.testAssertRaisesRegex.<locals>.<lambda>r  r.   r   r   c                      t        d      r   )r   r(   r   r   raise_wrong_messagezBTestLongMessage.testAssertRaisesRegex.<locals>.raise_wrong_messagew  s    E""r   regex^"regex" does not match "foo"$r   r   z%^"regex" does not match "foo" : oops$r   r   r   s     r   testAssertRaisesRegexz%TestLongMessage.testAssertRaisesRegexo  sK    1I~3N*@	A	#1Iw3G1H	Ir   c                 <    | j                  dt        fd g d       y )NassertWarnsc                       y r'   r(   r(   r   r   r-   z1TestLongMessage.testAssertWarns.<locals>.<lambda>  r.   r   ^UserWarning not triggered$r   r  z"^UserWarning not triggered : oops$r   UserWarningr   s    r   testAssertWarnszTestLongMessage.testAssertWarns  s    mk^\E	Fr   c                 |    | j                  dt        dfd g d       d }| j                  dt        df|g d       y )NassertWarnsRegexr   c                       y r'   r(   r(   r   r   r-   z6TestLongMessage.testAssertWarnsRegex.<locals>.<lambda>  r.   r   r  c                  .    t        j                  d       y r   )warningswarnr(   r   r   r   zATestLongMessage.testAssertWarnsRegex.<locals>.raise_wrong_message  s    MM% r   r   r   r  r   s     r   testAssertWarnsRegexz$TestLongMessage.testAssertWarnsRegex  sK    0;2O*E	F	!0;2H1H	Ir   N)$r=   r>   r?   __doc__rk   rn   rt   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rY   r   r   r  r	  r  r(   r   r   r[   r[      s    %;$7:8
,8<
<
1
C]
S6.
BO@3S
H?KA<<GC>&AI FIr   r[   __main__)r   r  rD   rP   test.supportr   	itertoolsr   rQ   r   r[   r=   mainr(   r   r   <module>r     s]        # D<h'' D<NCIh'' CIL zHMMO r   