U :eB@sdddlZddlZddlZddlZddlmZGdddejZGdddejZe dkr`e dS)N)productc@s4eZdZddZddZddZddZd d Zd S) 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) Ng1??g?皙?r)placesy??inf)assertAlmostEqualassertNotAlmostEqual assertRaisesfailureExceptionfloatselfrB/usr/local/python38/lib/python3.8/unittest/test/test_assertions.pytest_AlmostEqual sL   z Test_Assertions.test_AlmostEqualcCs|jdddd|jdddd|jdddd|jdddd|jdddd|j|j|jdddd|j|j|jdddd|j|j|jdddd|jt|jddddd|jt|jdddddtj}|tjdd }|j||tjd d d|j||tjd d ddS) Nrrg?)deltag?)rr )Zseconds)r r r r TypeErrordatetimeZnowZ timedelta)rfirstsecondrrrtest_AmostEqualWithDelta sP        z(Test_Assertions.test_AmostEqualWithDeltac Csdd}|t|t|t|tdz|tddWn4|jk rp}z|dt|W5d}~XYn X|dz|t|tWntk rYn X|d|t8}ztWn(tk r}z |}W5d}~XYnXW5QRX||j ||ttdW5QRXz|tW5QRXWn6|jk rr}z|dt|W5d}~XYn X|dz|t tW5QRXWntk rYn X|ddS) NcSs|dSNr)errr_raise<sz1Test_Assertions.test_assertRaises.._raisekeycSsdSrrrrrrAz3Test_Assertions.test_assertRaises..zKeyError not raisedzassertRaises() didn't failz0assertRaises() didn't let exception pass through) r KeyErrorr assertInstrfail ValueError ExceptionassertIs exception)rrrcmexcrrrtest_assertRaises;sD"     "  z!Test_Assertions.test_assertRaisescs^GddddGfdddtj}|d||d|dS)Nc@s eZdZdS)z.AN)__name__ __module__ __qualname__rrrrAhsr1cs*eZdZfddZddZddZdS)z>Test_Assertions.test_assertRaises_frames_survival..Foocs6}t|ztWntk r0tYnXdSr)weakrefrefOSErrorr')rar1wrrrfoons  zBTest_Assertions.test_assertRaises_frames_survival..Foo.foocSs|t|jdSrr r'r8rrrrtest_functionalwszNTest_Assertions.test_assertRaises_frames_survival..Foo.test_functionalc Ss"|t|W5QRXdSrr9rrrr test_withzs zHTest_Assertions.test_assertRaises_frames_survival..Foo.test_withN)r.r/r0r8r:r;rr6rrFools r<r:r;)unittestTestCaserun assertIsNone)rr<rr6r!test_assertRaises_frames_survivales   z1Test_Assertions.test_assertRaises_frames_survivalc Csd|ddz|dddWn6|jk rT}z|d|jdW5d}~XYn X|ddS)Nz Ala ma kotazr+zk.tZMessagerz"assertNotRegex should have failed.)assertNotRegexr r$argsr&)rrrrrtestAssertNotRegexs  $z"Test_Assertions.testAssertNotRegexN)r.r/r0rrr-rArDrrrrrs *rc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Z dd?Z"d@dAZ#dBdCZ$dDS)ETestLongMessagezTest that the individual asserts honour longMessage. This actually tests all the message behaviour for asserts that use longMessage.csDGfdddtj}Gfdddtj}|d_|d_dS)NcseZdZdZjZddZdS)z0TestLongMessage.setUp..TestableTestFalseFcSsdSrrrrrrtestTestsz9TestLongMessage.setUp..TestableTestFalse.testTestNr.r/r0 longMessager rFrrrrTestableTestFalsesrIcseZdZdZjZddZdS)z/TestLongMessage.setUp..TestableTestTrueTcSsdSrrrrrrrFsz8TestLongMessage.setUp..TestableTestTrue.testTestNrGrrrrTestableTestTruesrJrF)r=r> testableTrue testableFalse)rrIrJrrrsetUps zTestLongMessage.setUpcCs|tjjdSr) assertTruer=r>rHrrrr testDefaultszTestLongMessage.testDefaultcCsl||jddd||jddd||jddd||jddd|jtddS)Nr8barz bar : foo)Z assertEqualrL_formatMessagerKobjectrrrrtest_formatMsgs zTestLongMessage.test_formatMsgcCs*dddtdD}|j|ddS)Ncss|]}t|VqdSr)chr).0irrr szCTestLongMessage.test_formatMessage_unicode_error..u�)joinrangerKrQ)rZonerrr test_formatMessage_unicode_errorsz0TestLongMessage.test_formatMessage_unicode_errorc sjfdd}t|D]N\}}||}i}|d} | r>ddi}jj|d|||W5QRXqdS)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}|rj}nj}t|S)Nr)rLrKgetattr)rWZuseTestableFalsetest methodNamerrr getMethods z1TestLongMessage.assertMessages..getMethodrmsgoops)expected_regexN) enumerateassertRaisesRegexr ) rr`rCerrorsrarWrdZ testMethodkwargsZwithMsgrr_rassertMessagess zTestLongMessage.assertMessagescCs|ddddddgdS)NrN)Fz^False is not true$^oops$z^False is not true : oops$rirrrrtestAssertTrues zTestLongMessage.testAssertTruecCs|ddddddgdS)NZ assertFalse)Tz^True is not false$rjz^True is not false : oops$rkrrrrtestAssertFalses zTestLongMessage.testAssertFalsecCs|ddddddgdS)NZassertNotEqualrrz^1 == 1$rjz^1 == 1 : oops$rkrrrr testNotEquals zTestLongMessage.testNotEqualcCs|ddddddgdS)Nr rrz)^1 != 2 within 7 places \(1 difference\)$rjz0^1 != 2 within 7 places \(1 difference\) : oops$rkrrrrtestAlmostEqualszTestLongMessage.testAlmostEqualcCs|ddddddgdS)Nr rnz^1 == 1 within 7 places$rjz^1 == 1 within 7 places : oops$rkrrrrtestNotAlmostEquals z"TestLongMessage.testNotAlmostEqualcCs|ddddddgdS)NZ_baseAssertEqualrpz^1 != 2$rjz^1 != 2 : oops$rkrrrrtest_baseAssertEquals z$TestLongMessage.test_baseAssertEqualcCs |dgdgfddddgdS)NZassertSequenceEqualz \+ \[None\]$rjz\+ \[None\] : oops$rkrrrrtestAssertSequenceEquals z'TestLongMessage.testAssertSequenceEqualcCs&|dttdgfddddgdS)NZassertSetEqualzNone$rjz None : oops$)risetrrrrtestAssertSetEquals z"TestLongMessage.testAssertSetEqualcCs|ddgfddddgdS)Nr$z^None not found in \[\]$rjz^None not found in \[\] : oops$rkrrrr testAssertIns  zTestLongMessage.testAssertIncCs |dddgfddddgdS)NZ assertNotInz%^None unexpectedly found in \[None\]$rjz,^None unexpectedly found in \[None\] : oops$rkrrrrtestAssertNotIns zTestLongMessage.testAssertNotIncCs"|diddifddddgdS)NZassertDictEqualr valuez\+ \{'key': 'value'\}$rjz\+ \{'key': 'value'\} : oops$rkrrrrtestAssertDictEqual s z#TestLongMessage.testAssertDictEqualc CsBt0tdt|dddiifddddgW5QRXdS)NignoreZassertDictContainsSubsetr ryz^Missing: 'key'$rjz^Missing: 'key' : oops$)warningscatch_warnings simplefilterDeprecationWarningrirrrrtestAssertDictContainsSubsets  z,TestLongMessage.testAssertDictContainsSubsetcCs|ddddddgdS)NZassertMultiLineEqual)rTr8z\+ foo$rjz\+ foo : oops$rkrrrrtestAssertMultiLineEquals z(TestLongMessage.testAssertMultiLineEqualcCs|ddddddgdS)NZ assertLessrrz^2 not less than 1$rjz^2 not less than 1 : oops$rkrrrrtestAssertLesss zTestLongMessage.testAssertLesscCs|ddddddgdS)NZassertLessEqualrz^2 not less than or equal to 1$rjz&^2 not less than or equal to 1 : oops$rkrrrrtestAssertLessEqual#s z#TestLongMessage.testAssertLessEqualcCs|ddddddgdS)NZ assertGreaterrpz^1 not greater than 2$rjz^1 not greater than 2 : oops$rkrrrrtestAssertGreater)s z!TestLongMessage.testAssertGreatercCs|ddddddgdS)NZassertGreaterEqualrpz"^1 not greater than or equal to 2$rjz)^1 not greater than or equal to 2 : oops$rkrrrrtestAssertGreaterEqual/s z&TestLongMessage.testAssertGreaterEqualcCs|ddddddgdS)Nr@)znot Nonez^'not None' is not None$rjz^'not None' is not None : oops$rkrrrrtestAssertIsNone5s z TestLongMessage.testAssertIsNonecCs|ddddddgdS)NZassertIsNotNonerz^unexpectedly None$rjz^unexpectedly None : oops$rkrrrrtestAssertIsNotNone;s z#TestLongMessage.testAssertIsNotNonecCs|ddddddgdS)Nr)Nr8z^None is not 'foo'$rjz^None is not 'foo' : oops$rkrrrr testAssertIsAs zTestLongMessage.testAssertIscCs|ddddddgdS)NZ assertIsNot)NNz^unexpectedly identical: None$rjz%^unexpectedly identical: None : oops$rkrrrrtestAssertIsNotGs zTestLongMessage.testAssertIsNotcCs|ddddddgdS)NZ assertRegex)r8rPz^Regex didn't match:rjz!^Regex didn't match: (.*) : oops$rkrrrrtestAssertRegexMszTestLongMessage.testAssertRegexcCs|ddddddgdS)NrB)r8r8z^Regex matched:rjz^Regex matched: (.*) : oops$rkrrrrrDTsz"TestLongMessage.testAssertNotRegexc Csvt|j|jfiddif}t||D]L\\}}}t||} ||j|"| || } |W5QRXW5QRXq$dS)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; rbrcN)rrLrKzipr]rfr ) rr`rCfuncrgpclsrherrmethodr+rrrassertMessagesCM\s    z TestLongMessage.assertMessagesCMc Cs"|dtfddddddgdS)Nr cSsdSrrrrrrr!pr"z2TestLongMessage.testAssertRaises..^TypeError not raised$rj^TypeError not raised : oops$rrrrrrtestAssertRaisesos z TestLongMessage.testAssertRaisesc CsH|dtdfddddddgdd }|dtd f|d dd d gdS) Nrf unused regexcSsdSrrrrrrr!xr"z7TestLongMessage.testAssertRaisesRegex..rrjrcSs tddSr)rrrrrraise_wrong_message}szBTestLongMessage.testAssertRaisesRegex..raise_wrong_messageregex^"regex" does not match "foo"$%^"regex" does not match "foo" : oops$rrrrrrtestAssertRaisesRegexus  z%TestLongMessage.testAssertRaisesRegexc Cs"|dtfddddddgdS)NZ assertWarnscSsdSrrrrrrr!r"z1TestLongMessage.testAssertWarns..^UserWarning not triggered$rj"^UserWarning not triggered : oops$r UserWarningrrrrtestAssertWarnss zTestLongMessage.testAssertWarnsc CsH|dtdfddddddgdd }|dtd f|d dd d gdS) NZassertWarnsRegexrcSsdSrrrrrrr!r"z6TestLongMessage.testAssertWarnsRegex..rrjrcSstddSr)r|warnrrrrrszATestLongMessage.testAssertWarnsRegex..raise_wrong_messagerrrrrrrrtestAssertWarnsRegexs  z$TestLongMessage.testAssertWarnsRegexN)%r.r/r0__doc__rMrOrSr\rirlrmrorqrrrsrtrvrwrxrzrrrrrrrrrrrrDrrrrrrrrrrEsD  rE__main__) rr|r2r= itertoolsrr>rrEr.mainrrrrs