a
    zeC                     @   s  d dl Z d dlZd dlZd dlZd dlZd dlZ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mZmZmZmZ dZe ZdZG dd deZG d	d
 d
eZG dd deZG dd deZdd Zg Zdd Zdd Zdd Zdd Z dd Z!dd Z"dd Z#G dd  d Z$G d!d" d"e$Z%G d#d$ d$e%Z&G d%d& d&e%Z'G d'd( d(ej(Z)G d)d* d*eZ*G d+d, d,e*Z+G d-d. d.e*Z,dS )/    N   )result)strclass	safe_repr_count_diff_all_purpose_count_diff_hashable_common_shorten_reprTz@
Diff is %s characters long. Set self.maxDiff to None to see it.c                   @   s   e Zd ZdS )SkipTestN__name__
__module____qualname__ r   r   #/usr/lib/python3.9/unittest/case.pyr	      s   r	   c                   @   s   e Zd ZdS )_ShouldStopNr
   r   r   r   r   r   !   s   r   c                   @   s   e Zd ZdS )_UnexpectedSuccessNr
   r   r   r   r   r   &   s   r   c                   @   s&   e Zd ZdddZejdddZdS )	_OutcomeNc                 C   s4   d| _ || _t|d| _d| _g | _d | _g | _d S )NF
addSubTestT)expecting_failurer   hasattrresult_supports_subtestssuccessskippedexpectedFailureerrors)selfr   r   r   r   __init__-   s    z_Outcome.__init__Fc              
   c   s   | j }d| _ zz
d V  W n ty,    Y n tyh } z&d| _ | j|t|f W Y d }~npd }~0  tyx   Y nX   t }| j	r|| _
nd| _ | j||f d }Y n0 | jr| j r| j|d f W | j o|| _ n| j o|| _ 0 d S )NTF)r   KeyboardInterruptr	   r   appendstrr   sysexc_infor   r   r   r   )r   	test_caseisTestZold_successer!   r   r   r   testPartExecutor6   s*    
(
z_Outcome.testPartExecutor)N)F)r   r   r   r   
contextlibcontextmanagerr%   r   r   r   r   r   ,   s   
	r   c                 C   s   | S Nr   )objr   r   r   _idT   s    r*   c                O   s   t | ||f d S r(   )_module_cleanupsr   )functionargskwargsr   r   r   addModuleCleanupY   s    r/   c               
   C   sj   g } t rZt  \}}}z||i | W q tyV } z| | W Y d }~qd }~0 0 q| rf| d d S Nr   )r+   pop	Exceptionr   )
exceptionsr,   r-   r.   excr   r   r   doModuleCleanups_   s    "r5   c                    s,    fdd}t  tjr( }d ||S |S )Nc                    s4   t | ts$t|  fdd}|} d| _ | _| S )Nc                     s   t  d S r(   r	   r-   r.   reasonr   r   skip_wrapperu   s    z-skip.<locals>.decorator.<locals>.skip_wrapperT)
isinstancetype	functoolswraps__unittest_skip____unittest_skip_why__)	test_itemr:   r8   r   r   	decorators   s    
zskip.<locals>.decorator )r;   typesFunctionType)r9   rB   rA   r   r8   r   skipo   s    
rF   c                 C   s   | rt |S tS r(   rF   r*   Z	conditionr9   r   r   r   skipIf   s    rI   c                 C   s   | st |S tS r(   rG   rH   r   r   r   
skipUnless   s    rJ   c                 C   s
   d| _ | S )NT)__unittest_expecting_failure__)rA   r   r   r   r      s    r   c                    s4   t | tr t fdd| D S t | to2t|  S )Nc                 3   s   | ]}t | V  qd S r(   )_is_subtype).0r$   basetyper   r   	<genexpr>       z_is_subtype.<locals>.<genexpr>)r;   tupleallr<   
issubclass)expectedrO   r   rN   r   rL      s    
rL   c                   @   s   e Zd Zdd Zdd ZdS )_BaseTestCaseContextc                 C   s
   || _ d S r(   )r"   )r   r"   r   r   r   r      s    z_BaseTestCaseContext.__init__c                 C   s    | j | j|}| j |d S r(   )r"   _formatMessagemsgfailureException)r   standardMsgrX   r   r   r   _raiseFailure   s    z"_BaseTestCaseContext._raiseFailureN)r   r   r   r   r[   r   r   r   r   rV      s   rV   c                   @   s   e Zd ZdddZdd ZdS )_AssertRaisesBaseContextNc                 C   s@   t | | || _|| _|d ur*t|}|| _d | _d | _d S r(   )	rV   r   rU   r"   recompileexpected_regexobj_namerX   )r   rU   r"   r_   r   r   r   r      s    
z!_AssertRaisesBaseContext.__init__c                 C   s   zt | j| js"td|| jf |sX|dd | _|rNtdtt|f | W d } S |^}}z|j	| _
W n ty   t|| _
Y n0 |  ||i | W d    n1 s0    Y  W d } nd } 0 d S )Nz%s() arg 1 must be %srX   z3%r is an invalid keyword argument for this function)rL   rU   
_base_type	TypeError_base_type_strr1   rX   nextiterr   r`   AttributeErrorr   )r   namer-   r.   Zcallable_objr   r   r   handle   s,    .z_AssertRaisesBaseContext.handle)N)r   r   r   r   rh   r   r   r   r   r\      s   

r\   c                   @   s.   e Zd ZeZdZdd Zdd Zee	j
ZdS )_AssertRaisesContextz-an exception type or tuple of exception typesc                 C   s   | S r(   r   r   r   r   r   	__enter__   s    z_AssertRaisesContext.__enter__c                 C   s   |d u r`z| j j}W n ty0   t| j }Y n0 | jrN| d|| j qj| d| n
t| t	|| j szdS |
d | _| jd u rdS | j}|t|s| d|jt| dS )Nz{} not raised by {}z{} not raisedFT"{}" does not match "{}")rU   r   rf   r   r`   r[   format	tracebackclear_framesrT   with_traceback	exceptionr_   searchpattern)r   exc_type	exc_valuetbexc_namer_   r   r   r   __exit__   s,    



z_AssertRaisesContext.__exit__N)r   r   r   BaseExceptionra   rc   rk   rx   classmethodrD   GenericAlias__class_getitem__r   r   r   r   ri      s
   ri   c                   @   s$   e Zd ZeZdZdd Zdd ZdS )_AssertWarnsContextz(a warning type or tuple of warning typesc                 C   sR   t tj D ]}t|dd ri |_qtjdd| _| j	 | _t
d| j | S )N__warningregistry__T)recordalways)listr    modulesvaluesgetattrr~   warningscatch_warningswarnings_managerrk   simplefilterrU   )r   vr   r   r   rk      s    z_AssertWarnsContext.__enter__c                 C   s   | j ||| |d urd S z| jj}W n tyD   t| j}Y n0 d }| jD ]Z}|j}t|| jshqP|d u rt|}| j	d ur| j	
t|sqP|| _|j| _|j| _ d S |d ur| d| j	jt| | jr| d|| j n| d| d S )Nrl   z{} not triggered by {}z{} not triggered)r   rx   rU   r   rf   r   r   messager;   r_   rr   warningfilenamelinenor[   rm   rs   r`   )r   rt   ru   rv   rw   Zfirst_matchingmwr   r   r   rx     s>    


z_AssertWarnsContext.__exit__N)r   r   r   Warningra   rc   rk   rx   r   r   r   r   r}      s   r}   c                   @   s   e Zd Zdd ZdS )_OrderedChainMapc                 c   s8   t  }| jD ]&}|D ]}||vr|| |V  qqd S r(   )setmapsadd)r   seenmappingkr   r   r   __iter__,  s    

z_OrderedChainMap.__iter__N)r   r   r   r   r   r   r   r   r   +  s   r   c                   @   s  e Zd ZeZdZdZdZdZg Z	dddZ
dd	 Zd
d Zedd Zdd Zdd Zedd Ze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ejefd(d)Zd*d+ Z d,d- Z!d.d/ Z"d0d1 Z#d2d3 Z$d4d5 Z%d6d7 Z&dd9d:Z'd;d< Z(ed=d> Z)d?d@ Z*dAdB Z+dCdD Z,ddEdFZ-ddGdHZ.ddIdJZ/dKdL Z0dMdN Z1dOdP Z2ddQdRZ3dSdT Z4ddUdVZ5ddWdXZ6ddYdZZ7dd[d\Z8dd]d^Z9dd_d`Z:dadb Z;ddcddZ<ddedfZ=ddgdhZ>ddidjZ?ddkdlZ@ddmdnZAddodpZBddqdrZCddsdtZDddudvZEddwdxZFddydzZGdd{d|ZHdd}d~ZIdddZJdddZKdddZLdddZMdddZNdd ZOdd ZPdddZQdddZRdd ZSeSe6 ZTZUeSe7 ZVZWeSe8 ZXZYeSe9 ZZZ[eSe/ Z\Z]eSe1Z^eSe.Z_eSeOZ`eSeQZaeSeRZbd8S )TestCaseTi  i   FrunTestc                 C   s   || _ d | _d| _zt| |}W n, tyL   |dkrHtd| j|f Y n
0 |j| _g | _d | _	i | _
| td | td | td | td | td | td d S )	NzNo testr   zno such test method in %s: %sassertDictEqualassertListEqualassertTupleEqualassertSetEqualassertMultiLineEqual)_testMethodName_outcome_testMethodDocr   rf   
ValueError	__class____doc__	_cleanups_subtest_type_equality_funcsaddTypeEqualityFuncdictr   rR   r   	frozensetr   )r   Z
methodName
testMethodr   r   r   r   f  s(    zTestCase.__init__c                 C   s   || j |< d S r(   )r   )r   Ztypeobjr,   r   r   r   r     s    zTestCase.addTypeEqualityFuncc                O   s   | j |||f d S r(   )r   r   r   r,   r-   r.   r   r   r   
addCleanup  s    zTestCase.addCleanupc                O   s   | j |||f d S r(   )_class_cleanupsr   clsr,   r-   r.   r   r   r   addClassCleanup  s    zTestCase.addClassCleanupc                 C   s   d S r(   r   rj   r   r   r   setUp  s    zTestCase.setUpc                 C   s   d S r(   r   rj   r   r   r   tearDown  s    zTestCase.tearDownc                 C   s   d S r(   r   r   r   r   r   
setUpClass  s    zTestCase.setUpClassc                 C   s   d S r(   r   r   r   r   r   tearDownClass  s    zTestCase.tearDownClassc                 C   s   dS )Nr   r   rj   r   r   r   countTestCases  s    zTestCase.countTestCasesc                 C   s   t  S r(   )r   Z
TestResultrj   r   r   r   defaultTestResult  s    zTestCase.defaultTestResultc                 C   s$   | j }|r | dd  S d S N
r   )r   stripsplitr   docr   r   r   shortDescription  s    zTestCase.shortDescriptionc                 C   s   dt | j| jf S )Nz%s.%sr   r   r   rj   r   r   r   id  s    zTestCase.idc                 C   s    t | t |urtS | j|jkS r(   )r<   NotImplementedr   r   otherr   r   r   __eq__  s    zTestCase.__eq__c                 C   s   t t| | jfS r(   )hashr<   r   rj   r   r   r   __hash__  s    zTestCase.__hash__c                 C   s   d| j t| jf S Nz%s (%s))r   r   r   rj   r   r   r   __str__  s    zTestCase.__str__c                 C   s   dt | j| jf S )Nz<%s testMethod=%s>r   rj   r   r   r   __repr__  s    zTestCase.__repr__c                 C   s<   t |dd }|d ur ||| ntdtd || d S )NaddSkipz4TestResult has no addSkip method, skips not reported   )r   r   warnRuntimeWarning
addSuccess)r   r   r"   r9   r   r   r   r   _addSkip  s    zTestCase._addSkipc                 k   s   | j d u s| j jsd V  d S | j}|d u r4t|}n|j|}t| ||| _zr| j j| jdd d V  W d    n1 s~0    Y  | j js| j j	}|d ur|j
rtn| j jrtW || _n|| _0 d S )NTr#   )r   r   r   r   params	new_child_SubTestr%   r   r   Zfailfastr   r   )r   rX   r   parentZ
params_mapr   r   r   r   subTest  s$    
$zTestCase.subTestc                 C   s`   |D ]V\}}t |tr(||j|| q|d urt|d | jrN||| q||| qd S r0   )r;   r   r   r"   rT   rY   
addFailureZaddError)r   r   r   testr!   r   r   r   _feedErrorsToResult  s    
zTestCase._feedErrorsToResultc                 C   sB   z
|j }W n( ty2   tdt ||  Y n0 || | d S )Nz@TestResult has no addExpectedFailure method, reporting as passes)addExpectedFailurerf   r   r   r   r   )r   r   r!   r   r   r   r   _addExpectedFailure	  s    
zTestCase._addExpectedFailurec                 C   sd   z
|j }W nL tyV   tdt z
td W n" tyP   || t  Y n0 Y n
0 ||  d S )NzCTestResult has no addUnexpectedSuccess method, reporting as failure)	addUnexpectedSuccessrf   r   r   r   r   r   r    r!   )r   r   r   r   r   r   _addUnexpectedSuccess  s    

zTestCase._addUnexpectedSuccessc                 C   s   |    d S r(   )r   rj   r   r   r   
_callSetUp"  s    zTestCase._callSetUpc                 C   s
   |  d S r(   r   )r   methodr   r   r   _callTestMethod%  s    zTestCase._callTestMethodc                 C   s   |    d S r(   )r   rj   r   r   r   _callTearDown(  s    zTestCase._callTearDownc                O   s   ||i | d S r(   r   r   r   r   r   _callCleanup+  s    zTestCase._callCleanupNc           
   	   C   s  |d u r8|   }t|dd }t|dd }|d ur<|  nd }||  z,t| | j}t| jddspt|ddrt| jddpt|dd}| || | |W ||  |d ur|  S t| ddpt|dd}t|}zf|| _|	|  | 
  W d    n1 s
0    Y  |jr||_|j	| dd	 | | W d    n1 sR0    Y  d|_|	|  |   W d    n1 s0    Y  |   |jD ]\}}	| |||	 q| ||j |jr|r|jr| ||j n
| | n
||  |W |j  d |_d | _W ||  |d ur>|  S |j  d |_d | _0 W ||  |d ur|  n||  |d ur|  0 d S )
NstartTestRunstopTestRunr?   Fr@   rC   rK   Tr   )r   r   Z	startTestr   r   r   ZstopTestr   r   r%   r   r   r   r   r   
doCleanupsr   r   r   r   r   r   r   clear)
r   r   r   r   r   skip_whyr   outcomer   r9   r   r   r   run.  s    


,

(*(



   





zTestCase.runc                 C   sl   | j p
t }| jrf| j \}}}|| ( | j|g|R i | W d    q1 sZ0    Y  q|jS r(   )r   r   r   r1   r%   r   r   )r   r   r,   r-   r.   r   r   r   r   q  s    8zTestCase.doCleanupsc                 C   sX   g | _ | jrT| j \}}}z||i | W q tyP   | j t  Y q0 qd S r(   )ZtearDown_exceptionsr   r1   r2   r   r    r!   r   r   r   r   doClassCleanups~  s    zTestCase.doClassCleanupsc                 O   s   | j |i |S r(   )r   )r   r-   kwdsr   r   r   __call__  s    zTestCase.__call__c                 C   s   t | | j}t | jdds&t |ddrHt | jddp>t |dd}t||   | | |   | jr| j \}}}| j	|g|R i | qbd S )Nr?   Fr@   rC   )
r   r   r   r	   r   r   r   r   r1   r   )r   r   r   r,   r-   r.   r   r   r   debug  s    


zTestCase.debugc                 C   s   t |d S r(   r6   )r   r9   r   r   r   skipTest  s    zTestCase.skipTestc                 C   s   |  |d S r(   )rY   )r   rX   r   r   r   fail  s    zTestCase.failc                 C   s&   |r"|  |dt| }| |d S )Nz%s is not falserW   r   rY   r   exprrX   r   r   r   assertFalse  s    zTestCase.assertFalsec                 C   s&   |s"|  |dt| }| |d S )Nz%s is not truer   r   r   r   r   
assertTrue  s    zTestCase.assertTruec                 C   sT   | j s|p|S |d u r|S zd||f W S  tyN   dt|t|f  Y S 0 d S )Nz%s : %s)longMessageUnicodeDecodeErrorr   )r   rX   rZ   r   r   r   rW     s    
zTestCase._formatMessagec                 O   s*   t || }z|d||W d }S d }0 d S )NassertRaisesri   rh   )r   expected_exceptionr-   r.   contextr   r   r   r     s    
zTestCase.assertRaisesc                 O   s   t || }|d||S )NassertWarnsr}   rh   )r   expected_warningr-   r.   r   r   r   r   r     s    
zTestCase.assertWarnsc                 C   s   ddl m} || ||S )Nr   )_AssertLogsContext)_logr   )r   loggerlevelr   r   r   r   
assertLogs  s    zTestCase.assertLogsc                 C   sF   t |t |u r@| jt |}|d ur@t|tr<t| |}|S | jS r(   )r<   r   getr;   r   r   _baseAssertEqual)r   firstsecondZasserterr   r   r   _getAssertEqualityFunc  s    

zTestCase._getAssertEqualityFuncc                 C   s0   ||ks,dt || }| ||}| |d S )N%s != %s)r   rW   rY   )r   r  r  rX   rZ   r   r   r   r  9  s    zTestCase._baseAssertEqualc                 C   s   |  ||}||||d d S )N)rX   )r  )r   r  r  rX   Zassertion_funcr   r   r   assertEqual@  s    zTestCase.assertEqualc                 C   s2   ||ks.|  |dt|t|f }| |d S )Nz%s == %sr   )r   r  r  rX   r   r   r   assertNotEqualG  s
    zTestCase.assertNotEqualc                 C   s   ||krd S |d ur$|d ur$t dt|| }|d urf||krDd S dt|t|t|t|f }n:|d u rrd}t||dkrd S dt|t||t|f }| ||}| |d S )N specify delta or places not bothz(%s != %s within %s delta (%s difference)   r   z)%s != %s within %r places (%s difference)rb   absr   roundrW   rY   r   r  r  ZplacesrX   ZdeltadiffrZ   r   r   r   assertAlmostEqualP  s4    zTestCase.assertAlmostEqualc                 C   s   |d ur|d urt dt|| }|d urb||ks@||kr@d S dt|t|t|t|f }n<|d u rnd}||kst||dkrd S dt|t||f }| ||}| |d S )Nr  z(%s == %s within %s delta (%s difference)r  r   z%s == %s within %r placesr  r  r   r   r   assertNotAlmostEqual}  s,    zTestCase.assertNotAlmostEqualc                 C   s  |d urP|j }t||s.| d|t|f t||sT| d|t|f nd}d }zt|}W n ttfy   d| }Y n0 |d u rzt|}W n ttfy   d| }Y n0 |d u r||krd S d| ft||  }t	t
||D ]}	z||	 }
W n2 tttfy6   |d|	|f 7 }Y  qY n0 z||	 }W n2 tttfyv   |d|	|f 7 }Y  qY n0 |
|kr|d	|	ft|
|  7 } qq||kr|d u rt|t|krd S ||kr2|d
||| f 7 }z|d|t|| f 7 }W n* tttfy.   |d||f 7 }Y n0 nf||k r|d||| f 7 }z|d|t|| f 7 }W n* tttfy   |d||f 7 }Y n0 |}ddtt| t|  }| ||}| ||}| | d S )NzFirst sequence is not a %s: %szSecond sequence is not a %s: %sZsequencez(First %s has no length.    Non-sequence?z)Second %s has no length.    Non-sequence?z%ss differ: %s != %s
z(
Unable to index element %d of first %s
z)
Unable to index element %d of second %s
z#
First differing element %d:
%s
%s
z+
First %s contains %d additional elements.
zFirst extra element %d:
%s
z'Unable to index element %d of first %s
z,
Second %s contains %d additional elements.
z(Unable to index element %d of second %s
r   )r   r;   rY   r   lenrb   NotImplementedError
capitalizer   rangemin
IndexErrorr<   joindifflibndiffpprintpformat
splitlines_truncateMessagerW   r   )r   Zseq1Zseq2rX   seq_typeZseq_type_nameZ	differingZlen1Zlen2iZitem1Zitem2rZ   diffMsgr   r   r   assertSequenceEqual  s    












zTestCase.assertSequenceEqualc                 C   s2   | j }|d u st||kr"|| S |tt|  S r(   )maxDiffr  DIFF_OMITTED)r   r   r  Zmax_diffr   r   r   r!    s    zTestCase._truncateMessagec                 C   s   | j |||td d S N)r"  )r%  r   )r   Zlist1Zlist2rX   r   r   r   r   	  s    
zTestCase.assertListEqualc                 C   s   | j |||td d S r(  )r%  rR   )r   Ztuple1Ztuple2rX   r   r   r   r     s    	zTestCase.assertTupleEqualc           
   
   C   sh  z| |}W nb ty@ } z| d|  W Y d }~n:d }~0  typ } z| d|  W Y d }~n
d }~0 0 z| |}W nb ty } z| d|  W Y d }~n:d }~0  ty } z| d|  W Y d }~n
d }~0 0 |s|sd S g }|r|d |D ]}|t| q|rH|d |D ]}|t| q2d|}	| | ||	 d S )Nz/invalid type when attempting set difference: %sz2first argument does not support set difference: %sz3second argument does not support set difference: %sz*Items in the first set but not the second:z*Items in the second set but not the first:r   )
differencerb   r   rf   r   reprr  rW   )
r   Zset1Zset2rX   Zdifference1r$   Zdifference2linesitemrZ   r   r   r   r      s2    "$"$


zTestCase.assertSetEqualc                 C   s2   ||vr.dt |t |f }| | || d S )Nz%s not found in %sr   r   rW   r   member	containerrX   rZ   r   r   r   assertInK  s
    zTestCase.assertInc                 C   s2   ||v r.dt |t |f }| | || d S )Nz%s unexpectedly found in %sr-  r.  r   r   r   assertNotInR  s
    zTestCase.assertNotInc                 C   s2   ||ur.dt |t |f }| | || d S )Nz%s is not %sr-  r   Zexpr1Zexpr2rX   rZ   r   r   r   assertIsY  s
    zTestCase.assertIsc                 C   s,   ||u r(dt |f }| | || d S )Nzunexpectedly identical: %sr-  r3  r   r   r   assertIsNot`  s    zTestCase.assertIsNotc              	   C   s~   |  |td |  |td ||krzdt|| }ddtt| t|  }| 	||}| 
| || d S )Nz"First argument is not a dictionaryz#Second argument is not a dictionaryr	  r   )assertIsInstancer   r   r  r  r  r  r  r   r!  r   rW   )r   Zd1Zd2rX   rZ   r  r   r   r   r   f  s    
zTestCase.assertDictEqualc           	   	   C   s   t dt g }g }| D ]L\}}||vr8|| q||| kr|dt|t|t|| f  q|sv|svd S d}|rdddd |D  }|r|r|d7 }|d	d| 7 }| | || d S )
Nz&assertDictContainsSubset is deprecatedz%s, expected: %s, actual: %srC   zMissing: %s,c                 s   s   | ]}t |V  qd S r(   )r   )rM   r   r   r   r   rP     rQ   z4TestCase.assertDictContainsSubset.<locals>.<genexpr>z; zMismatched values: %s)	r   r   DeprecationWarningitemsr   r   r  r   rW   )	r   ZsubsetZ
dictionaryrX   missingZ
mismatchedkeyvaluerZ   r   r   r   assertDictContainsSubsetr  s4    

z!TestCase.assertDictContainsSubsetc           
      C   s   t |t | }}zt|}t|}W n tyF   t||}Y n0 ||krTd S t||}|rd}dd |D }d|}	| ||	}| ||}| 	| d S )NzElement counts were not equal:
c                 S   s   g | ]}d | qS )z First has %d, Second has %d:  %rr   )rM   r  r   r   r   
<listcomp>  rQ   z-TestCase.assertCountEqual.<locals>.<listcomp>r   )
r   collectionsCounterrb   r   r   r  r!  rW   r   )
r   r  r  rX   Z	first_seqZ
second_seqZdifferencesrZ   r+  r$  r   r   r   assertCountEqual  s     


zTestCase.assertCountEqualc                 C   s   |  |td |  |td ||krt|| jks@t|| jkrN| ||| |jdd}|jdd}t|dkr|d|kr|d g}|d g}dt|| }dd	t	
|| }| ||}| | || d S )
NzFirst argument is not a stringzSecond argument is not a stringT)keependsr   z
r   r	  rC   )r6  r   r  _diffThresholdr  r   r   r   r  r  r  r!  r   rW   )r   r  r  rX   Z
firstlinesZsecondlinesrZ   r  r   r   r   r     s     

zTestCase.assertMultiLineEqualc                 C   s2   ||k s.dt |t |f }| | || d S )Nz%s not less than %sr-  r   abrX   rZ   r   r   r   
assertLess  s    zTestCase.assertLessc                 C   s2   ||ks.dt |t |f }| | || d S )Nz%s not less than or equal to %sr-  rD  r   r   r   assertLessEqual  s    zTestCase.assertLessEqualc                 C   s2   ||ks.dt |t |f }| | || d S )Nz%s not greater than %sr-  rD  r   r   r   assertGreater  s    zTestCase.assertGreaterc                 C   s2   ||ks.dt |t |f }| | || d S )Nz"%s not greater than or equal to %sr-  rD  r   r   r   assertGreaterEqual  s    zTestCase.assertGreaterEqualc                 C   s,   |d ur(dt |f }| | || d S )Nz%s is not Noner-  r   r)   rX   rZ   r   r   r   assertIsNone  s    zTestCase.assertIsNonec                 C   s"   |d u rd}|  | || d S )Nzunexpectedly None)r   rW   rK  r   r   r   assertIsNotNone  s    zTestCase.assertIsNotNonec                 C   s0   t ||s,dt||f }| | || d S )Nz%s is not an instance of %rr;   r   r   rW   r   r)   r   rX   rZ   r   r   r   r6    s    
zTestCase.assertIsInstancec                 C   s0   t ||r,dt||f }| | || d S )Nz%s is an instance of %rrN  rO  r   r   r   assertNotIsInstance  s    
zTestCase.assertNotIsInstancec                 O   s   t || |}|d||S )NassertRaisesRegexr   )r   r   r_   r-   r.   r   r   r   r   rQ    s    zTestCase.assertRaisesRegexc                 O   s   t || |}|d||S )NassertWarnsRegexr   )r   r   r_   r-   r.   r   r   r   r   rR    s    zTestCase.assertWarnsRegexc                 C   sJ   t |ttfrt|}||sFd|j|f }| ||}| |d S )Nz&Regex didn't match: %r not found in %r)	r;   r   bytesr]   r^   rr   rs   rW   rY   )r   textr_   rX   rZ   r   r   r   assertRegex  s    

zTestCase.assertRegexc                 C   s`   t |ttfrt|}||}|r\d|| |  |j|f }| 	||}| 
|d S )Nz"Regex matched: %r matches %r in %r)r;   r   rS  r]   r^   rr   startendrs   rW   rY   )r   rT  Zunexpected_regexrX   matchrZ   r   r   r   assertNotRegex#  s    

zTestCase.assertNotRegexc                    s    fdd}|S )Nc                     s$   t d jtd  | i |S )NzPlease use {0} instead.r   )r   r   rm   r   r8  r7   original_funcr   r   deprecated_func3  s
    
z,TestCase._deprecate.<locals>.deprecated_funcr   )r[  r\  r   rZ  r   
_deprecate2  s    zTestCase._deprecate)r   )N)N)N)N)NN)N)N)N)NNN)NNN)NN)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)cr   r   r   AssertionErrorrY   r   r&  rC  Z_classSetupFailedr   r   r   r   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r&   r'   _subtest_msg_sentinelr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rW   r   r   r  r  r  r
  r  r  r  r%  r!  r   r   r   r1  r2  r4  r5  r   r=  rA  r   rG  rH  rI  rJ  rL  rM  r6  rP  rQ  rR  rU  rY  r]  ZfailUnlessEqualZassertEqualsZfailIfEqualZassertNotEqualsZfailUnlessAlmostEqualZassertAlmostEqualsZfailIfAlmostEqualZassertNotAlmostEqualsZ
failUnlessZassert_ZfailUnlessRaisesZfailIfZassertRaisesRegexpZassertRegexpMatchesZassertNotRegexpMatchesr   r   r   r   r   5  s   !
 


	


C



!



	  
-  
#
c


+






 










	r   c                       sf   e Zd Zd f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  ZS )FunctionTestCaseNc                    s*   t t|   || _|| _|| _|| _d S r(   )superr`  r   
_setUpFunc_tearDownFunc	_testFunc_description)r   ZtestFuncr   r   descriptionr   r   r   r   Q  s
    zFunctionTestCase.__init__c                 C   s   | j d ur|    d S r(   )rb  rj   r   r   r   r   X  s    
zFunctionTestCase.setUpc                 C   s   | j d ur|    d S r(   )rc  rj   r   r   r   r   \  s    
zFunctionTestCase.tearDownc                 C   s   |    d S r(   )rd  rj   r   r   r   r   `  s    zFunctionTestCase.runTestc                 C   s   | j jS r(   )rd  r   rj   r   r   r   r   c  s    zFunctionTestCase.idc                 C   s@   t || jstS | j|jko>| j|jko>| j|jko>| j|jkS r(   )r;   r   r   rb  rc  rd  re  r   r   r   r   r   f  s    


zFunctionTestCase.__eq__c                 C   s   t t| | j| j| j| jfS r(   )r   r<   rb  rc  rd  re  rj   r   r   r   r   o  s    zFunctionTestCase.__hash__c                 C   s   dt | j| jjf S r   )r   r   rd  r   rj   r   r   r   r   s  s    
zFunctionTestCase.__str__c                 C   s   dt | j| jf S )Nz<%s tec=%s>)r   r   rd  rj   r   r   r   r   w  s    
zFunctionTestCase.__repr__c                 C   s2   | j d ur| j S | jj}|r.|dd  p0d S r   )re  rd  r   r   r   r   r   r   r   r   {  s    
z!FunctionTestCase.shortDescription)NNN)r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   r   rg  r   r`  H  s   		r`  c                       sD   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Z  Z	S )r   c                    s(   t    || _|| _|| _|j| _d S r(   )ra  r   _messager"   r   rY   )r   r"   r   r   rg  r   r   r     s
    
z_SubTest.__init__c                 C   s   t dd S )Nzsubtests cannot be run directly)r  rj   r   r   r   r     s    z_SubTest.runTestc                 C   s^   g }| j tur |d| j  | jrPddd | j D }|d| d|p\dS )Nz[{}]z, c                 s   s   | ]\}}d  ||V  qdS )z{}={!r}N)rm   )rM   r   r   r   r   r   rP     s   z+_SubTest._subDescription.<locals>.<genexpr>z({}) z(<subtest>))ri  r_  r   rm   r   r  r9  )r   partsZparams_descr   r   r   _subDescription  s    

z_SubTest._subDescriptionc                 C   s   d | j |  S Nz{} {})rm   r"   r   rl  rj   r   r   r   r     s    z_SubTest.idc                 C   s
   | j  S r(   )r"   r   rj   r   r   r   r     s    z_SubTest.shortDescriptionc                 C   s   d | j|  S rm  )rm   r"   rl  rj   r   r   r   r     s    z_SubTest.__str__)
r   r   r   r   r   rl  r   r   r   rh  r   r   rg  r   r     s   r   )-r    r=   r  r  r]   r   r?  r&   rn   rD   rC   r   utilr   r   r   r   r   Z
__unittestobjectr_  r'  r2   r	   r   r   r   r*   r+   r/   r5   rF   rI   rJ   r   rL   rV   r\   ri   r}   ChainMapr   r   r`  r   r   r   r   r   <module>   sV   (	*'5
        :