
W}B                 @   s   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l m Z Gd d   d e j  Z Gd d   d e j  Z e	 d k r e j
   d S)    N)productc               @   sL   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d S)Test_Assertionsc             C   sH  |  j  d d  |  j d d  |  j |  j |  j  d d  |  j |  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 |  j  t d
  t d
   |  j |  j |  j t d
  t d
   d  S)Ng1  ?g      ?g  ?g?placesr      g?y        ?infy??y??y??y??)assertAlmostEqualassertNotAlmostEqualassertRaisesfailureExceptionfloat)self r   D/afs/.cs/s/python-3.5.2/amd64_ubu14/lib/python3.5/test_assertions.pytest_AlmostEqual	   s$    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 d |  j t |  j d d d d d d t j j   } | t j d d	  } |  j  | | d t j d d
  |  j | | d t j d d  d  S)Ng?g      ?Zdeltag      ?g?r      Zseconds
         )r   r   r	   r
   	TypeErrordatetimeZnowZ	timedelta)r   firstsecondr   r   r   test_AmostEqualWithDelta    s*    z(Test_Assertions.test_AmostEqualWithDeltac          O   C   s  d d   } |  j  t | t  |  j  t | t d   y |  j  t d d    Wn> |  j k
 r } z |  j d t |   WYd  d  } ~ Xn X|  j d  y |  j  t | t  Wn t k
 r Yn X|  j d  |  j  t  B } y
 t  Wn. t k
 r%} z | }   WYd  d  } ~ Xn XWd  QRX|  j | j	 |  |  j  t   t d   Wd  QRXy |  j  t   Wd  QRXWn> |  j k
 r} z |  j d t |   WYd  d  } ~ Xn X|  j d  y! |  j  t   t  Wd  QRXWn t k
 rYn X|  j 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)Nr   r   r   r   r   <lambda>A   s    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    )
)z!Test_Assertions.test_assertRaisesc                s   Gd d   d    d   G   f d d   d t  j  } | d  j   |  j     | d  j   |  j     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   Ah   s   r+   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                sA       } t  j |   y
 t  Wn t k
 r< t  Yn Xd  S)N)weakrefrefIOErrorr!   )r   a)r+   wrr   r   foon   s    	
zBTest_Assertions.test_assertRaises_frames_survival.<locals>.Foo.fooc             S   s   |  j  t |  j  d  S)N)r	   r!   r1   )r   r   r   r   test_functionalw   s    zNTest_Assertions.test_assertRaises_frames_survival.<locals>.Foo.test_functionalc          	   S   s%   |  j  t   |  j   Wd  QRXd  S)N)r	   r!   r1   )r   r   r   r   	test_withz   s    zHTest_Assertions.test_assertRaises_frames_survival.<locals>.Foo.test_withN)r(   r)   r*   r1   r2   r3   r   )r+   r0   r   r   Fool   s   	r4   r2   r3   )unittestTestCaserunassertIsNone)r   r4   r   )r+   r0   r   !test_assertRaises_frames_survivale   s    "z1Test_Assertions.test_assertRaises_frames_survivalc             C   sz   |  j  d d  y |  j  d d d  Wn? |  j k
 rh } z |  j d | j d  WYd  d  } ~ Xn X|  j 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(   r)   r*   r   r   r'   r9   r<   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 d0 d1   Z d2 d3   Z d4 d5   Z d6 d7   Z d8 d9   Z d: d;   Z  d< d=   Z! d> d?   Z" d@ dA   Z# dB dC   Z$ dD S)ETestLongMessagezTest that the individual asserts honour longMessage.
    This actually tests all the message behaviour for
    asserts that use longMessage.c                s`   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)Nr   )r   r   r   r   testTest   s    z9TestLongMessage.setUp.<locals>.TestableTestFalse.testTestN)r(   r)   r*   longMessager
   r>   r   )r   r   r   TestableTestFalse   s   	r@   c                   s+   e  Z d  Z d Z   j Z d d   Z d S)z/TestLongMessage.setUp.<locals>.TestableTestTrueTc             S   s   d  S)Nr   )r   r   r   r   r>      s    z8TestLongMessage.setUp.<locals>.TestableTestTrue.testTestN)r(   r)   r*   r?   r
   r>   r   )r   r   r   TestableTestTrue   s   	rA   r>   )r5   r6   testableTruetestableFalse)r   r@   rA   r   )r   r   setUp   s    zTestLongMessage.setUpc             C   s   |  j  t j j  d  S)N)
assertTruer5   r6   r?   )r   r   r   r   testDefault   s    zTestLongMessage.testDefaultc             C   s   |  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  d  S)Nr1   barz	bar : foo)ZassertEqualrC   _formatMessagerB   object)r   r   r   r   test_formatMsg   s
    zTestLongMessage.test_formatMsgc             C   s9   d j  d d   t d  D  } |  j j | d  d  S)N c             s   s   |  ] } t  |  Vq d  S)N)chr).0ir   r   r   	<genexpr>   s    zCTestLongMessage.test_formatMessage_unicode_error.<locals>.<genexpr>   u   �)joinrangerB   rH   )r   Zoner   r   r    test_formatMessage_unicode_error   s    "z0TestLongMessage.test_formatMessage_unicode_errorc       
         s      f d d   } xu t  |  D]g \ } } | |  } i  } | d }	 |	 r\ d d i }  j  j d |  | | |   Wd QRXq" Wd 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                s4   |  d k  } | r  j  } n	  j } t |    S)Nr   )rC   rB   getattr)rN   ZuseTestableFalsetest)
methodNamer   r   r   	getMethod   s
    	z1TestLongMessage.assertMessages.<locals>.getMethodr   msgoopsexpected_regexN)	enumerateassertRaisesRegexr
   )
r   rV   r;   errorsrW   rN   rZ   Z
testMethodkwargsZwithMsgr   )rV   r   r   assertMessages   s    	

zTestLongMessage.assertMessagesc             C   s#   |  j  d d d d d d g  d  S)NrE   Fz^False is not true$z^oops$z^False is not true : oops$)F)r_   )r   r   r   r   testAssertTrue   s    	zTestLongMessage.testAssertTruec             C   s#   |  j  d d d d d d g  d  S)NZassertFalseTz^True is not false$z^oops$z^True is not false : oops$)T)r_   )r   r   r   r   testAssertFalse   s    	zTestLongMessage.testAssertFalsec             C   s#   |  j  d d d d d d g  d  S)NZassertNotEqualr   z^1 == 1$z^oops$z^1 == 1 : oops$)r   r   )r_   )r   r   r   r   testNotEqual   s    	zTestLongMessage.testNotEqualc             C   s#   |  j  d d d d d d g  d  S)Nr   r   r   z^1 != 2 within 7 places$z^oops$z^1 != 2 within 7 places : oops$)r   r   )r_   )r   r   r   r   testAlmostEqual   s    zTestLongMessage.testAlmostEqualc             C   s#   |  j  d d d d d d g  d  S)Nr   r   z^1 == 1 within 7 places$z^oops$z^1 == 1 within 7 places : oops$)r   r   )r_   )r   r   r   r   testNotAlmostEqual   s    z"TestLongMessage.testNotAlmostEqualc             C   s#   |  j  d d d d d d g  d  S)NZ_baseAssertEqualr   r   z^1 != 2$z^oops$z^1 != 2 : oops$)r   r   )r_   )r   r   r   r   test_baseAssertEqual   s    z$TestLongMessage.test_baseAssertEqualc             C   s,   |  j  d g  d  g f d d d d g  d  S)NZassertSequenceEqualz\+ \[None\]$z^oops$z\+ \[None\] : oops$)r_   )r   r   r   r   testAssertSequenceEqual   s    	z'TestLongMessage.testAssertSequenceEqualc             C   s5   |  j  d t   t d  g  f d d d d g  d  S)NZassertSetEqualzNone$z^oops$zNone : oops$)r_   set)r   r   r   r   testAssertSetEqual   s    	z"TestLongMessage.testAssertSetEqualc             C   s)   |  j  d d  g  f d d d d g  d  S)Nr   z^None not found in \[\]$z^oops$z^None not found in \[\] : oops$)r_   )r   r   r   r   testAssertIn   s    zTestLongMessage.testAssertInc             C   s,   |  j  d d  d  g f d d d d g  d  S)NZassertNotInz%^None unexpectedly found in \[None\]$z^oops$z,^None unexpectedly found in \[None\] : oops$)r_   )r   r   r   r   testAssertNotIn  s    zTestLongMessage.testAssertNotInc             C   s/   |  j  d i  d d i f d d d d g  d  S)NZassertDictEqualr   valuez\+ \{'key': 'value'\}$z^oops$z\+ \{'key': 'value'\} : oops$)r_   )r   r   r   r   testAssertDictEqual  s    z#TestLongMessage.testAssertDictEqualc             C   sS   t  j   @ t  j d t  |  j d d d i i  f d d d d g  Wd  QRXd  S)NignoreZassertDictContainsSubsetr   rk   z^Missing: 'key'$z^oops$z^Missing: 'key' : oops$)warningscatch_warningssimplefilterDeprecationWarningr_   )r   r   r   r   testAssertDictContainsSubset  s    z,TestLongMessage.testAssertDictContainsSubsetc             C   s#   |  j  d d d d d d g  d  S)NZassertMultiLineEqualrK   r1   z\+ foo$z^oops$z\+ foo : oops$)rK   zfoo)r_   )r   r   r   r   testAssertMultiLineEqual  s    z(TestLongMessage.testAssertMultiLineEqualc             C   s#   |  j  d d d d d d g  d  S)NZ
assertLessr   r   z^2 not less than 1$z^oops$z^2 not less than 1 : oops$)r   r   )r_   )r   r   r   r   testAssertLess  s    zTestLongMessage.testAssertLessc             C   s#   |  j  d d d d d d g  d  S)NZassertLessEqualr   r   z^2 not less than or equal to 1$z^oops$z&^2 not less than or equal to 1 : oops$)r   r   )r_   )r   r   r   r   testAssertLessEqual!  s    z#TestLongMessage.testAssertLessEqualc             C   s#   |  j  d d d d d d g  d  S)NZassertGreaterr   r   z^1 not greater than 2$z^oops$z^1 not greater than 2 : oops$)r   r   )r_   )r   r   r   r   testAssertGreater'  s    z!TestLongMessage.testAssertGreaterc             C   s#   |  j  d d d d d d g  d  S)NZassertGreaterEqualr   r   z"^1 not greater than or equal to 2$z^oops$z)^1 not greater than or equal to 2 : oops$)r   r   )r_   )r   r   r   r   testAssertGreaterEqual-  s    z&TestLongMessage.testAssertGreaterEqualc             C   s#   |  j  d d d d d d g  d  S)Nr8   not Nonez^'not None' is not None$z^oops$z^'not None' is not None : oops$)rx   )r_   )r   r   r   r   testAssertIsNone3  s    z TestLongMessage.testAssertIsNonec             C   s#   |  j  d d d d d d g  d  S)NZassertIsNotNonez^unexpectedly None$z^oops$z^unexpectedly None : oops$)N)r_   )r   r   r   r   testAssertIsNotNone9  s    z#TestLongMessage.testAssertIsNotNonec             C   s#   |  j  d d d d d d g  d  S)Nr#   r1   z^None is not 'foo'$z^oops$z^None is not 'foo' : oops$)Nzfoo)r_   )r   r   r   r   testAssertIs?  s    zTestLongMessage.testAssertIsc             C   s#   |  j  d d d d d d g  d  S)NZassertIsNotz^unexpectedly identical: None$z^oops$z%^unexpectedly identical: None : oops$)NN)r_   )r   r   r   r   testAssertIsNotE  s    zTestLongMessage.testAssertIsNotc             C   s#   |  j  d d d d d d g  d  S)NZassertRegexr1   rG   z^Regex didn't match:z^oops$z!^Regex didn't match: (.*) : oops$)zfoozbar)r_   )r   r   r   r   testAssertRegexK  s
    zTestLongMessage.testAssertRegexc             C   s#   |  j  d d d d d d g  d  S)Nr:   r1   z^Regex matched:z^oops$z^Regex matched: (.*) : oops$)foor~   )r_   )r   r   r   r   r<   R  s
    z"TestLongMessage.testAssertNotRegexc             C   s   t  |  j |  j f i  d d i f  } xo t | |  D]^ \ \ } } } t | |  }	 |  j | j |  % |	 | |    }
 |   Wd QRXWd QRXq7 Wd 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;
        rX   rY   N)r   rC   rB   ziprT   r\   r
   )r   rV   r;   funcr]   pclsr^   errmethodr%   r   r   r   assertMessagesCMZ  s    "z TestLongMessage.assertMessagesCMc             C   s/   |  j  d t f d d   d d d d g  d  S)Nr	   c               S   s   d  S)Nr   r   r   r   r   r   n  s    z2TestLongMessage.testAssertRaises.<locals>.<lambda>z^TypeError not raised$z^oops$z^TypeError not raised : oops$)r   r   )r   r   r   r   testAssertRaisesm  s    z TestLongMessage.testAssertRaisesc             C   sf   |  j  d t d f d d   d d d d g  d d	   } |  j  d t d
 f | d d d d g  d  S)Nr\   zunused regexc               S   s   d  S)Nr   r   r   r   r   r   v  s    z7TestLongMessage.testAssertRaisesRegex.<locals>.<lambda>z^TypeError not raised$z^oops$z^TypeError not raised : oops$c               S   s   t  d   d  S)Nr1   )r   r   r   r   r   raise_wrong_message{  s    zBTestLongMessage.testAssertRaisesRegex.<locals>.raise_wrong_messageregexz^"regex" does not match "foo"$z%^"regex" does not match "foo" : oops$)r   r   )r   r   r   r   r   testAssertRaisesRegexs  s    	
z%TestLongMessage.testAssertRaisesRegexc             C   s/   |  j  d t f d d   d d d d g  d  S)NZassertWarnsc               S   s   d  S)Nr   r   r   r   r   r     s    z1TestLongMessage.testAssertWarns.<locals>.<lambda>z^UserWarning not triggered$z^oops$z"^UserWarning not triggered : oops$)r   UserWarning)r   r   r   r   testAssertWarns  s    zTestLongMessage.testAssertWarnsc             C   sf   |  j  d t d f d d   d d d d g  d d	   } |  j  d t d
 f | d d d d g  d  S)NZassertWarnsRegexzunused regexc               S   s   d  S)Nr   r   r   r   r   r     s    z6TestLongMessage.testAssertWarnsRegex.<locals>.<lambda>z^UserWarning not triggered$z^oops$z"^UserWarning not triggered : oops$c               S   s   t  j d  d  S)Nr1   )rn   warnr   r   r   r   r     s    zATestLongMessage.testAssertWarnsRegex.<locals>.raise_wrong_messager   z^"regex" does not match "foo"$z%^"regex" does not match "foo" : oops$)r   r   )r   r   r   r   r   testAssertWarnsRegex  s    	
z$TestLongMessage.testAssertWarnsRegexN)%r(   r)   r*   __doc__rD   rF   rJ   rS   r_   r`   ra   rb   rc   rd   re   rf   rh   ri   rj   rl   rr   rs   rt   ru   rv   rw   ry   rz   r{   r|   r}   r<   r   r   r   r   r   r   r   r   r   r=      sD   
	r=   __main__)r   rn   r,   r5   	itertoolsr   r6   r   r=   r(   mainr   r   r   r   <module>   s    