Your IP : 216.73.216.85


Current Path : /opt/alt/python310/lib64/python3.10/unittest/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/unittest/test/__pycache__/test_assertions.cpython-310.pyc

o

0�i8C�@stddlZddlZddlZddlZddlmZddlmZGdd�dej�Z	Gdd�dej�Z
edkr8e��dSdS)	�N)�
gc_collect)�productc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�Test_AssertionscCs�|�dd�|�dd�|�|j|jdd�|�|j|jdd�|jdddd�|j|j|jdddd�|jdddd�|jdddd�|j|j|jdddd�|j|j|jdddd�|�td	�td	��|�|j|jtd	�td	��dS)
Ng�1��?��?g����?皙�����?r)�places�y�������?�������?�inf)�assertAlmostEqual�assertNotAlmostEqual�assertRaises�failureException�float��self�r�D/opt/alt/python310/lib64/python3.10/unittest/test/test_assertions.py�test_AlmostEqual
s0��
�
�
��z Test_Assertions.test_AlmostEqualcCs|jdddd�|jdddd�|jdddd�|jdddd�|jdddd�|j|j|jdddd�|j|j|jdddd�|j|j|jdddd�|jt|jddddd�|jt|jddddd�tj��}|tjdd	�}|j||tjd
d	�d�|j||tjdd	�d�dS)Nrrg�?)�deltag�������?�)rr�
)Zseconds��)r
rrr
�	TypeError�datetimeZnowZ	timedelta)r�first�secondrrr�test_AmostEqualWithDelta!s8���
�
�

�

�z(Test_Assertions.test_AmostEqualWithDeltacCs�dd�}|�t|t�|�t|td��z
|�tdd��Wn|jy9}z|�dt|��WYd}~n
d}~ww|�d�z	|�t|t�Wn	tyQYnw|�d�|�t��}zt�tyn}z|}�d}~ww1srwY|�|j	|�|�t��td��1s�wYz|�t��Wd�n1s�wYWn|jy�}z|�dt|��WYd}~n
d}~ww|�d�z|�t��t�1s�wYWn
ty�YdSw|�d�dS)	NcSs|��Nr)�errr�_raise=�z1Test_Assertions.test_assertRaises.<locals>._raise�keycS�dSrrrrrr�<lambda>B�z3Test_Assertions.test_assertRaises.<locals>.<lambda>zKeyError not raisedzassertRaises() didn't failz0assertRaises() didn't let exception pass through)
r�KeyErrorr
�assertIn�str�fail�
ValueError�	Exception�assertIsZ	exception)rr r�cm�excrrr�test_assertRaises<s^��
�
��������
��z!Test_Assertions.test_assertRaisescsjGdd�d��d�G��fdd�dtj�}|d���t�|����|d���t�|����dS)Nc@seZdZdS)z<Test_Assertions.test_assertRaises_frames_survival.<locals>.AN)�__name__�
__module__�__qualname__rrrr�Aisr3cs*eZdZ��fdd�Zdd�Zdd�ZdS)z>Test_Assertions.test_assertRaises_frames_survival.<locals>.Foocs(��}t�|��zt�tyt�wr)�weakref�ref�OSErrorr*)r�a�r3Zwrrr�fooos
�zBTest_Assertions.test_assertRaises_frames_survival.<locals>.Foo.foocSs|�t|j�dSr�rr*r9rrrr�test_functionalx�zNTest_Assertions.test_assertRaises_frames_survival.<locals>.Foo.test_functionalcSs8|�t��
|��Wd�dS1swYdSrr:rrrr�	test_with{s
"�zHTest_Assertions.test_assertRaises_frames_survival.<locals>.Foo.test_withN)r0r1r2r9r;r=rr8rr�Fooms	r>r;r=)�unittest�TestCase�runr�assertIsNone)rr>rr8r�!test_assertRaises_frames_survivalfsz1Test_Assertions.test_assertRaises_frames_survivalc
Csh|�dd�z	|�ddd�Wn|jy,}z|�d|jd�WYd}~dSd}~ww|�d�dS)NzAla ma kotazr+zk.tZMessagerz"assertNotRegex should have failed.)�assertNotRegexr
r'�argsr))rrrrr�testAssertNotRegex�s ��z"Test_Assertions.testAssertNotRegexN)r0r1r2rrr/rCrFrrrrr	s* rc@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDS)E�TestLongMessagez�Test that the individual asserts honour longMessage.
    This actually tests all the message behaviour for
    asserts that use longMessage.csDG�fdd�dtj�}G�fdd�dtj�}|d��_|d��_dS)Nc�eZdZdZ�jZdd�ZdS)z0TestLongMessage.setUp.<locals>.TestableTestFalseFcSr#rrrrrr�testTest�r!z9TestLongMessage.setUp.<locals>.TestableTestFalse.testTestN�r0r1r2�longMessager
rIrrrr�TestableTestFalse��rLcrH)z/TestLongMessage.setUp.<locals>.TestableTestTrueTcSr#rrrrrrrI�r!z8TestLongMessage.setUp.<locals>.TestableTestTrue.testTestNrJrrrr�TestableTestTrue�rMrNrI)r?r@�testableTrue�
testableFalse)rrLrNrrr�setUp�s
zTestLongMessage.setUpcCs|�tjj�dSr)�
assertTruer?r@rKrrrr�testDefault�r<zTestLongMessage.testDefaultcCsl|�|j�dd�d�|�|j�dd�d�|�|j�dd�d�|�|j�dd�d�|j�t�d�dS)Nr9�barz	bar : foo)ZassertEqualrP�_formatMessagerO�objectrrrr�test_formatMsg�s
zTestLongMessage.test_formatMsgcCs*d�dd�td�D��}|j�|d�dS)N�css�|]}t|�VqdSr)�chr)�.0�irrr�	<genexpr>�s�zCTestLongMessage.test_formatMessage_unicode_error.<locals>.<genexpr>�u�)�join�rangerOrU)rZonerrr� test_formatMessage_unicode_error�sz0TestLongMessage.test_formatMessage_unicode_errorc
	s���fdd�}t|�D]3\}}||�}i}|d}	|	rddi}�j�j|d��||i|��Wd�n1s9wYqdS)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;
        cs$|dk}|r
�j}n�j}t|��S)Nr)rPrO�getattr)r[ZuseTestableFalse�test��
methodNamerrr�	getMethod�s

z1TestLongMessage.assertMessages.<locals>.getMethodr�msg�oops)�expected_regexN)�	enumerate�assertRaisesRegexr
)
rrdrE�errorsrer[rhZ
testMethod�kwargsZwithMsgrrcr�assertMessages�s	����zTestLongMessage.assertMessagescC�|�ddgd��dS)NrR)F)�^False is not true$�^oops$roz^False is not true : oops$�rmrrrr�testAssertTrue���zTestLongMessage.testAssertTruecCrn)NZassertFalse)T)�^True is not false$rprtz^True is not false : oops$rqrrrr�testAssertFalse�rszTestLongMessage.testAssertFalsecCrn)NZassertNotEqual�rr)�^1 == 1$rprwz^1 == 1 : oops$rqrrrr�testNotEqual�rszTestLongMessage.testNotEqualcCrn)Nr
�rr)�)^1 != 2 within 7 places \(1 difference\)$rprzz0^1 != 2 within 7 places \(1 difference\) : oops$rqrrrr�testAlmostEqual�s�zTestLongMessage.testAlmostEqualcCrn)Nrrv)�^1 == 1 within 7 places$rpr|z^1 == 1 within 7 places : oops$rqrrrr�testNotAlmostEqual�rsz"TestLongMessage.testNotAlmostEqualcCrn)NZ_baseAssertEqualry)�^1 != 2$rpr~z^1 != 2 : oops$rqrrrr�test_baseAssertEqual�rsz$TestLongMessage.test_baseAssertEqualcCs|�dgdgfgd��dS)NZassertSequenceEqual)�\+ \[None\]$rpr�z\+ \[None\] : oops$rqrrrr�testAssertSequenceEqual�s�z'TestLongMessage.testAssertSequenceEqualcCs"|�dt�tdg�fgd��dS)NZassertSetEqual)�None$rpr�zNone : oops$)rm�setrrrr�testAssertSetEqual�s�z"TestLongMessage.testAssertSetEqualcCs|�ddgfgd��dS)Nr')�^None not found in \[\]$rpr�z^None not found in \[\] : oops$rqrrrr�testAssertIns�zTestLongMessage.testAssertIncCs|�dddgfgd��dS)NZassertNotIn)�%^None unexpectedly found in \[None\]$rpr�z,^None unexpectedly found in \[None\] : oops$rqrrrr�testAssertNotIns�zTestLongMessage.testAssertNotIncCs|�diddifgd��dS)NZassertDictEqualr"�value)�\+ \{'key': 'value'\}$rpr�z\+ \{'key': 'value'\} : oops$rqrrrr�testAssertDictEqual��z#TestLongMessage.testAssertDictEqualcCsTt���t�dt�|�dddiifgd��Wd�dS1s#wYdS)N�ignoreZassertDictContainsSubsetr"r�)�^Missing: 'key'$rpr�z^Missing: 'key' : oops$)�warnings�catch_warnings�simplefilter�DeprecationWarningrmrrrr�testAssertDictContainsSubsets
�"�z,TestLongMessage.testAssertDictContainsSubsetcCrn)NZassertMultiLineEqual)rXr9)�\+ foo$rpr�z\+ foo : oops$rqrrrr�testAssertMultiLineEqualrsz(TestLongMessage.testAssertMultiLineEqualcCrn)NZ
assertLess�rr)�^2 not less than 1$rpr�z^2 not less than 1 : oops$rqrrrr�testAssertLess!rszTestLongMessage.testAssertLesscCrn)NZassertLessEqualr�)�^2 not less than or equal to 1$rpr�z&^2 not less than or equal to 1 : oops$rqrrrr�testAssertLessEqual&rsz#TestLongMessage.testAssertLessEqualcCrn)NZ
assertGreaterry)�^1 not greater than 2$rpr�z^1 not greater than 2 : oops$rqrrrr�testAssertGreater,rsz!TestLongMessage.testAssertGreatercCrn)NZassertGreaterEqualry)�"^1 not greater than or equal to 2$rpr�z)^1 not greater than or equal to 2 : oops$rqrrrr�testAssertGreaterEqual2rsz&TestLongMessage.testAssertGreaterEqualcCrn)NrB)znot None)�^'not None' is not None$rpr�z^'not None' is not None : oops$rqrrrr�testAssertIsNone8rsz TestLongMessage.testAssertIsNonecCrn)NZassertIsNotNoner)�^unexpectedly None$rpr�z^unexpectedly None : oops$rqrrrr�testAssertIsNotNone>rsz#TestLongMessage.testAssertIsNotNonecCrn)Nr,�Nr9)�^None is not 'foo'$rpr�z^None is not 'foo' : oops$rqrrrr�testAssertIsDrszTestLongMessage.testAssertIscCrn)NZassertIsNot)NN)�^unexpectedly identical: None$rpr�z%^unexpectedly identical: None : oops$rqrrrr�testAssertIsNotJrszTestLongMessage.testAssertIsNotcCrn)NZassertRegex)r9rT)�^Regex didn't match:rpr�z!^Regex didn't match: (.*) : oops$rqrrrr�testAssertRegexPrszTestLongMessage.testAssertRegexcCrn)NrD)r9r9)�^Regex matched:rpr�z^Regex matched: (.*) : oops$rqrrrrrFWrsz"TestLongMessage.testAssertNotRegexc
Cs�t|j|jfiddif�}t||�D]<\\}}}t||�}	|�|j|��"|	|i|���}
|�Wd�n1s:wYWd�n1sIwYqdS)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;
        rfrgN)rrPrO�ziprarjr
)rrdrE�funcrk�p�clsrl�err�methodr-rrr�assertMessagesCM_s
�
�����z TestLongMessage.assertMessagesCMcC�|�dtfdd�gd��dS)NrcSr#rrrrrrr$sr%z2TestLongMessage.testAssertRaises.<locals>.<lambda>��^TypeError not raised$rpr�z^TypeError not raised : oops$�r�rrrrr�testAssertRaisesrr�z TestLongMessage.testAssertRaisescC�@|�dtdfdd�gd��dd�}|�dtdf|gd	��dS)
Nrj�unused regexcSr#rrrrrrr${r%z7TestLongMessage.testAssertRaisesRegex.<locals>.<lambda>r�cSstd��r�)rrrrr�raise_wrong_message�szBTestLongMessage.testAssertRaisesRegex.<locals>.raise_wrong_message�regex��^"regex" does not match "foo"$rpr�z%^"regex" does not match "foo" : oops$r��rr�rrr�testAssertRaisesRegexx���z%TestLongMessage.testAssertRaisesRegexcCr�)NZassertWarnscSr#rrrrrrr$�r%z1TestLongMessage.testAssertWarns.<locals>.<lambda>��^UserWarning not triggered$rpr�z"^UserWarning not triggered : oops$�r��UserWarningrrrr�testAssertWarns�r�zTestLongMessage.testAssertWarnscCr�)
NZassertWarnsRegexr�cSr#rrrrrrr$�r%z6TestLongMessage.testAssertWarnsRegex.<locals>.<lambda>r�cSst�d�dSr�)r��warnrrrrr��szATestLongMessage.testAssertWarnsRegex.<locals>.raise_wrong_messager�r�r�r�rrr�testAssertWarnsRegex�r�z$TestLongMessage.testAssertWarnsRegexN)%r0r1r2�__doc__rQrSrWr`rmrrrurxr{r}rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rFr�r�r�r�r�rrrrrG�sF
	rG�__main__)
rr�r4r?Ztest.supportr�	itertoolsrr@rrGr0�mainrrrr�<module>s�