???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................__init__.cpython-38.pyc                                                                             0000644                 00000006070 15175327576 0010760 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   s   d Z ddddddddd	d
ddddddddddgZedddg dZddlmZ ddlmZ ddlm	Z	m
Z
mZmZmZmZmZmZ ddlmZmZ ddlmZmZmZmZmZ ddlmZmZ dd lmZmZ dd!lm Z m!Z!m"Z"m#Z# eZ$d"d# Z%d$S )%a  
Python unit testing framework, based on Erich Gamma's JUnit and Kent Beck's
Smalltalk testing framework (used with permission).

This module contains the core framework classes that form the basis of
specific test cases and suites (TestCase, TestSuite etc.), and also a
text-based utility class for running the tests and reporting the results
 (TextTestRunner).

Simple usage:

    import unittest

    class IntegerArithmeticTestCase(unittest.TestCase):
        def testAdd(self):  # test method names begin with 'test'
            self.assertEqual((1 + 2), 3)
            self.assertEqual(0 + 1, 1)
        def testMultiply(self):
            self.assertEqual((0 * 10), 0)
            self.assertEqual((5 * 8), 40)

    if __name__ == '__main__':
        unittest.main()

Further information is available in the bundled documentation, and from

  http://docs.python.org/library/unittest.html

Copyright (c) 1999-2003 Steve Purcell
Copyright (c) 2003-2010 Python Software Foundation
This module is free software, and you may redistribute it and/or modify
it under the same terms as Python itself, so long as this copyright message
and disclaimer are retained in their original form.

IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

TestResultTestCaseIsolatedAsyncioTestCase	TestSuiteTextTestRunner
TestLoaderFunctionTestCasemaindefaultTestLoaderSkipTestskipskipIf
skipUnlessexpectedFailureTextTestResultinstallHandlerregisterResultremoveResultremoveHandleraddModuleCleanupgetTestCaseNames	makeSuitefindTestCasesT   )r   )r   )r   r   r   r
   r   r   r   r   )BaseTestSuiter   )r   r	   r   r   r   )TestProgramr   )r   r   )r   r   r   r   c                 C   s"   dd l }|jt}| j||dS )N    )Z	start_dirpattern)Zos.pathpathdirname__file__Zdiscover)loaderZtestsr   osZthis_dir r"   )/usr/lib64/python3.8/unittest/__init__.py
load_testsL   s    r$   N)&__doc____all__extendZ
__unittestresultr   Z
async_caser   Zcaser   r   r   r
   r   r   r   r   Zsuiter   r   r    r   r	   r   r   r   r   r   Zrunnerr   r   Zsignalsr   r   r   r   Z_TextTestResultr$   r"   r"   r"   r#   <module>   s<   .           (                                                                                                                                                                                                                                                                                                                                                                                                                                                                        _base.cpython-38.opt-2.pyc                                                                          0000644                 00000033521 15175327576 0011233 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dY                  
   @   sp  d Z ddlZddlZddlZddlZdZdZdZdZdZ	dZ
d	Zd
ZdZe	e
eeegZe	de
dededediZe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G dd de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d%d& Zd3d'd(Ze d)d*Z!defd+d,Z"G d-d. d.eZ#G d/d0 d0eZ$G d1d2 d2e%Z&dS )4z"Brian Quinlan (brian@sweetapp.com)    NFIRST_COMPLETEDFIRST_EXCEPTIONALL_COMPLETED_AS_COMPLETEDPENDINGRUNNING	CANCELLEDCANCELLED_AND_NOTIFIEDFINISHEDpendingrunning	cancelledfinishedzconcurrent.futuresc                   @   s   e Zd ZdS )ErrorN__name__
__module____qualname__ r   r   0/usr/lib64/python3.8/concurrent/futures/_base.pyr   ,   s   r   c                   @   s   e Zd ZdS )CancelledErrorNr   r   r   r   r   r   0   s   r   c                   @   s   e Zd ZdS )TimeoutErrorNr   r   r   r   r   r   4   s   r   c                   @   s   e Zd ZdS )InvalidStateErrorNr   r   r   r   r   r   8   s   r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
_Waiterc                 C   s   t  | _g | _d S N)	threadingZEventeventfinished_futuresselfr   r   r   __init__>   s    
z_Waiter.__init__c                 C   s   | j | d S r   r   appendr   futurer   r   r   
add_resultB   s    z_Waiter.add_resultc                 C   s   | j | d S r   r!   r#   r   r   r   add_exceptionE   s    z_Waiter.add_exceptionc                 C   s   | j | d S r   r!   r#   r   r   r   add_cancelledH   s    z_Waiter.add_cancelledN)r   r   r   r    r%   r&   r'   r   r   r   r   r   <   s   r   c                       s@   e Zd Z fddZ fddZ fddZ fddZ  ZS )	_AsCompletedWaiterc                    s   t t|   t | _d S r   )superr(   r    r   Locklockr   	__class__r   r   r    N   s    z_AsCompletedWaiter.__init__c              	      s0   | j   tt| | | j  W 5 Q R X d S r   )r+   r)   r(   r%   r   setr#   r,   r   r   r%   R   s    z_AsCompletedWaiter.add_resultc              	      s0   | j   tt| | | j  W 5 Q R X d S r   )r+   r)   r(   r&   r   r.   r#   r,   r   r   r&   W   s    z _AsCompletedWaiter.add_exceptionc              	      s0   | j   tt| | | j  W 5 Q R X d S r   )r+   r)   r(   r'   r   r.   r#   r,   r   r   r'   \   s    z _AsCompletedWaiter.add_cancelled)r   r   r   r    r%   r&   r'   __classcell__r   r   r,   r   r(   K   s   r(   c                       s4   e Zd Z fddZ fddZ fddZ  ZS )_FirstCompletedWaiterc                    s   t  | | j  d S r   )r)   r%   r   r.   r#   r,   r   r   r%   d   s    z _FirstCompletedWaiter.add_resultc                    s   t  | | j  d S r   )r)   r&   r   r.   r#   r,   r   r   r&   h   s    z#_FirstCompletedWaiter.add_exceptionc                    s   t  | | j  d S r   )r)   r'   r   r.   r#   r,   r   r   r'   l   s    z#_FirstCompletedWaiter.add_cancelled)r   r   r   r%   r&   r'   r/   r   r   r,   r   r0   a   s   r0   c                       sH   e Zd Z fddZdd Z fddZ fddZ fd	d
Z  ZS )_AllCompletedWaiterc                    s$   || _ || _t | _t   d S r   )num_pending_callsstop_on_exceptionr   r*   r+   r)   r    )r   r2   r3   r,   r   r   r    s   s    
z_AllCompletedWaiter.__init__c              	   C   s4   | j $ |  jd8  _| js&| j  W 5 Q R X d S )N   )r+   r2   r   r.   r   r   r   r   _decrement_pending_callsy   s    z,_AllCompletedWaiter._decrement_pending_callsc                    s   t  | |   d S r   )r)   r%   r5   r#   r,   r   r   r%      s    z_AllCompletedWaiter.add_resultc                    s*   t  | | jr| j  n|   d S r   )r)   r&   r3   r   r.   r5   r#   r,   r   r   r&      s    z!_AllCompletedWaiter.add_exceptionc                    s   t  | |   d S r   )r)   r'   r5   r#   r,   r   r   r'      s    z!_AllCompletedWaiter.add_cancelled)	r   r   r   r    r5   r%   r&   r'   r/   r   r   r,   r   r1   p   s
   r1   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )_AcquireFuturesc                 C   s   t |td| _d S )N)key)sortedidfutures)r   r:   r   r   r   r       s    z_AcquireFutures.__init__c                 C   s   | j D ]}|j  qd S r   )r:   
_conditionacquirer#   r   r   r   	__enter__   s    
z_AcquireFutures.__enter__c                 G   s   | j D ]}|j  qd S r   )r:   r;   release)r   argsr$   r   r   r   __exit__   s    
z_AcquireFutures.__exit__N)r   r   r   r    r=   r@   r   r   r   r   r6      s   r6   c                 C   s   |t krt }nZ|tkr t }nJtdd | D }|tkrHt|dd}n"|tkr^t|dd}ntd| | D ]}|j	
| qn|S )Nc                 s   s   | ]}|j ttfkV  qd S r   _stater	   r
   .0fr   r   r   	<genexpr>   s    z._create_and_install_waiters.<locals>.<genexpr>T)r3   FzInvalid return condition: %r)r   r(   r   r0   sumr   r1   r   
ValueError_waitersr"   )fsreturn_whenwaiterZpending_countrE   r   r   r   _create_and_install_waiters   s    rM   c              	   c   sP   | rL| d }|D ]}| | q|j |j | W 5 Q R X ~|  V  q d S )N)remover;   rI   pop)rJ   rL   ref_collectrE   Zfutures_setr   r   r   _yield_finished_futures   s    rR   c           	      c   sB  |d k	r|t   }t| } t| }t| * tdd | D }| | }t| t}W 5 Q R X t|}zt||| fdE d H  |r|d krd }n(|t   }|dk rtdt||f |j| |j |j}g |_|j  W 5 Q R X |  t||| |fdE d H  q|W 5 | D ]$}|j |j	
| W 5 Q R X qX d S )Nc                 s   s    | ]}|j ttfkr|V  qd S r   rA   rC   r   r   r   rF      s   zas_completed.<locals>.<genexpr>)rQ   r   z%d (of %d) futures unfinished)time	monotonicr.   lenr6   rM   r   listr;   rI   rO   rR   r   r   waitr+   r   clearreverse)	rJ   timeoutend_timeZtotal_futuresr   r   rL   rE   Zwait_timeoutr   r   r   as_completed   sL    
 r\   DoneAndNotDoneFutureszdone not_donec              
   C   s
  t |  tdd | D }t| | }|tkrJ|rJt||W  5 Q R  S |tkr~|r~tdd |D r~t||W  5 Q R  S t|t| krt||W  5 Q R  S t| |}W 5 Q R X |j	| | D ]"}|j
 |j| W 5 Q R X q||j t|t| | S )Nc                 s   s    | ]}|j ttfkr|V  qd S r   rA   rC   r   r   r   rF   !  s    zwait.<locals>.<genexpr>c                 s   s&   | ]}|  s| d k	r|V  qd S r   )r   	exceptionrC   r   r   r   rF   (  s     )r6   r.   r   r]   r   anyrU   rM   r   rW   r;   rI   rO   updater   )rJ   rZ   rK   doneZnot_donerL   rE   r   r   r   rW     s"    
rW   c                   @   s   e 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dZdddZdd Zdd Zdd ZdS ) Futurec                 C   s,   t  | _t| _d | _d | _g | _g | _d S r   )	r   Z	Conditionr;   r   rB   _result
_exceptionrI   _done_callbacksr   r   r   r   r    <  s    
zFuture.__init__c              	   C   s>   | j D ]2}z||  W q tk
r6   td|  Y qX qd S Nz!exception calling callback for %r)re   	ExceptionLOGGERr^   )r   callbackr   r   r   _invoke_callbacksE  s
    
zFuture._invoke_callbacksc              
   C   s   | j  | jtkrx| jrHd| jjt| t| j | jjjf W  5 Q R  S d| jjt| t| j | jjjf W  5 Q R  S d| jjt| t| j f W  5 Q R  S Q R X d S )Nz<%s at %#x state=%s raised %s>z <%s at %#x state=%s returned %s>z<%s at %#x state=%s>)	r;   rB   r
   rd   r-   r   r9   _STATE_TO_DESCRIPTION_MAPrc   r   r   r   r   __repr__L  s(    
zFuture.__repr__c              	   C   sf   | j N | jttfkr$W 5 Q R  dS | jttfkr@W 5 Q R  dS t| _| j   W 5 Q R X |   dS )NFT)r;   rB   r   r
   r   r	   
notify_allrj   r   r   r   r   cancel`  s    zFuture.cancelc              
   C   s,   | j  | jttfkW  5 Q R  S Q R X d S r   )r;   rB   r   r	   r   r   r   r   r   s  s    zFuture.cancelledc              
   C   s(   | j  | jtkW  5 Q R  S Q R X d S r   )r;   rB   r   r   r   r   r   r   x  s    zFuture.runningc              
   C   s.   | j  | jtttfkW  5 Q R  S Q R X d S r   )r;   rB   r   r	   r
   r   r   r   r   ra   }  s    zFuture.donec                 C   s$   | j rz
| j W 5 d } X n| jS d S r   )rd   rc   r   r   r   r   Z__get_result  s
    
zFuture.__get_resultc              	   C   sn   | j 0 | jtttfkr2| j| W 5 Q R  d S W 5 Q R X z||  W n  tk
rh   t	d|  Y nX d S rf   )
r;   rB   r   r	   r
   re   r"   rg   rh   r^   )r   fnr   r   r   add_done_callback  s    zFuture.add_done_callbackNc              
   C   s   z| j  | jttfkr t n"| jtkrB|  W  5 Q R  W ZS | j | | jttfkrdt n(| jtkr|  W  5 Q R  W S t W 5 Q R X W 5 d } X d S r   )	r;   rB   r   r	   r   r
   _Future__get_resultrW   r   r   rZ   r   r   r   result  s    

zFuture.resultc              
   C   s   | j | | jttfkrt n| jtkr:| jW  5 Q R  S | j | | jttfkr\t n"| jtkrx| jW  5 Q R  S t W 5 Q R X d S r   )	r;   rB   r   r	   r   r
   rd   rW   r   rr   r   r   r   r^     s    

zFuture.exceptionc              	   C   s   | j t | jtkr<t| _| jD ]}||  qW 5 Q R  dS | jtkrZt| _W 5 Q R  dS t	dt
| | j tdW 5 Q R X d S )NFTz!Future %s in unexpected state: %szFuture in unexpected state)r;   rB   r   r	   rI   r'   r   r   rh   Zcriticalr9   RuntimeError)r   rL   r   r   r   set_running_or_notify_cancel  s    


z#Future.set_running_or_notify_cancelc              	   C   sl   | j T | jttthkr*td| j| || _t| _| jD ]}|	|  q<| j 
  W 5 Q R X |   d S Nz{}: {!r})r;   rB   r   r	   r
   r   formatrc   rI   r%   rm   rj   )r   rs   rL   r   r   r   
set_result  s    
zFuture.set_resultc              	   C   sl   | j T | jttthkr*td| j| || _t| _| jD ]}|	|  q<| j 
  W 5 Q R X |   d S rv   )r;   rB   r   r	   r
   r   rw   rd   rI   r&   rm   rj   )r   r^   rL   r   r   r   set_exception  s    
zFuture.set_exception)N)N)r   r   r   r    rj   rl   rn   r   r   ra   rq   rp   rs   r^   ru   rx   ry   r   r   r   r   rb   9  s   	

#
"(rb   c                   @   sD   e Zd Zdd Zde_dddddZdd
dZdd Zdd ZdS )Executorc                  O   s\   t | dkrnD| stdn6d|kr>dd l}|jdtdd ntdt | d  t d S )	N   z:descriptor 'submit' of 'Executor' object needs an argumentro   r   z.Passing 'fn' as keyword argument is deprecated)
stacklevelz6submit expected at least 1 positional argument, got %dr4   )rU   	TypeErrorwarningswarnDeprecationWarningNotImplementedError)r?   kwargsr~   r   r   r   submit.  s    	
 
zExecutor.submitz($self, fn, /, *args, **kwargs)Nr4   )rZ   	chunksizec                   sB   d k	rt    fddt| D  fdd}| S )Nc                    s   g | ]}j  f| qS r   )r   )rD   r?   )ro   r   r   r   
<listcomp>`  s     z Executor.map.<locals>.<listcomp>c               	   3   s\   zB  r@d kr&  V  q
  t  V  q
W 5 D ]} |    qHX d S r   )rn   rY   rP   rs   rS   rT   )r$   )r[   rJ   rZ   r   r   result_iteratord  s    z%Executor.map.<locals>.result_iterator)rS   rT   zip)r   ro   rZ   r   	iterablesr   r   )r[   ro   rJ   r   rZ   r   mapG  s
    zExecutor.mapTc                 C   s   d S r   r   )r   rW   r   r   r   shutdowns  s    zExecutor.shutdownc                 C   s   | S r   r   r   r   r   r   r=     s    zExecutor.__enter__c                 C   s   | j dd dS )NT)rW   F)r   )r   exc_typeZexc_valZexc_tbr   r   r   r@     s    zExecutor.__exit__)T)	r   r   r   r   __text_signature__r   r   r=   r@   r   r   r   r   rz   +  s   ,
rz   c                   @   s   e Zd ZdS )BrokenExecutorNr   r   r   r   r   r     s   r   )N)'
__author__collectionsZloggingr   rS   r   r   r   r   r   r   r   r	   r
   Z_FUTURE_STATESrk   Z	getLoggerrh   rg   r   r   r   r   objectr   r(   r0   r1   r6   rM   rR   r\   
namedtupler]   rW   rb   rz   rt   r   r   r   r   r   <module>   sh   	     	

> 1 s]                                                                                                                                                                               __init__.cpython-38.opt-2.pyc                                                                       0000644                 00000002527 15175327576 0011723 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   s   d ddddddddd	d
dddddddddgZ e dddg dZddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZ ddlmZmZ ddlmZmZmZmZmZ ddlmZmZ ddlmZmZ dd lmZm Z m!Z!m"Z" eZ#d!d" Z$d#S )$
TestResultTestCaseIsolatedAsyncioTestCase	TestSuiteTextTestRunner
TestLoaderFunctionTestCasemaindefaultTestLoaderSkipTestskipskipIf
skipUnlessexpectedFailureTextTestResultinstallHandlerregisterResultremoveResultremoveHandleraddModuleCleanupgetTestCaseNames	makeSuitefindTestCasesT   )r   )r   )r   r   r   r
   r   r   r   r   )BaseTestSuiter   )r   r	   r   r   r   )TestProgramr   )r   r   )r   r   r   r   c                 C   s"   dd l }|jt}| j||dS )N    )Z	start_dirpattern)Zos.pathpathdirname__file__Zdiscover)loaderZtestsr   osZthis_dir r"   )/usr/lib64/python3.8/unittest/__init__.py
load_testsL   s    r$   N)%__all__extendZ
__unittestresultr   Z
async_caser   Zcaser   r   r   r
   r   r   r   r   Zsuiter   r   r    r   r	   r   r   r   r   r   Zrunnerr   r   Zsignalsr   r   r   r   Z_TextTestResultr$   r"   r"   r"   r#   <module>/   s:              (                                                                                                                                                                         thread.cpython-38.opt-1.pyc                                                                         0000644                 00000013274 15175327576 0011433 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d@"                     @   s   d Z dZddlZddlmZ ddlZddlZddlZddlZddl	Z	e
 Zdadd Zee G dd	 d	eZd
d ZG dd dejZG dd dejZdS )zImplements ThreadPoolExecutor.z"Brian Quinlan (brian@sweetapp.com)    N)_baseFc                  C   sB   da tt } | D ]\}}|d  q| D ]\}}|  q,d S NT)	_shutdownlist_threads_queuesitemsputjoin)r   tq r   1/usr/lib64/python3.8/concurrent/futures/thread.py_python_exit!   s    r   c                   @   s   e Zd Zdd Zdd ZdS )	_WorkItemc                 C   s   || _ || _|| _|| _d S N)futurefnargskwargs)selfr   r   r   r   r   r   r   __init__.   s    z_WorkItem.__init__c              
   C   sf   | j  sd S z| j| j| j}W n2 tk
rT } z| j | d } W 5 d }~X Y nX | j | d S r   )r   Zset_running_or_notify_cancelr   r   r   BaseExceptionset_exceptionZ
set_result)r   resultexcr   r   r   run4   s    
z_WorkItem.runN)__name__
__module____qualname__r   r   r   r   r   r   r   -   s   r   c                 C   s   |d k	rRz||  W n< t k
rP   tjjddd |  }|d k	rJ|  Y d S X zx|jdd}|d k	r|  ~|  }|d k	r|j  ~qT|  }t	s|d ks|j	r|d k	rd|_	|
d  W d S ~qTW n$ t k
r   tjjddd Y nX d S )NzException in initializer:T)exc_info)blockzException in worker)r   r   ZLOGGERZcritical_initializer_failedgetr   _idle_semaphorereleaser   r   )Zexecutor_referenceZ
work_queueinitializerinitargsZexecutor	work_itemr   r   r   _workerB   s8    

r(   c                   @   s   e Zd ZdZdS )BrokenThreadPoolzR
    Raised when a worker thread in a ThreadPoolExecutor failed initializing.
    N)r   r   r   __doc__r   r   r   r   r)   m   s   r)   c                   @   sf   e Zd Ze jZdddZdd Ze	j
jje_e	j
jje_dd	 Zd
d ZdddZe	j
jje_dS )ThreadPoolExecutorN r   c                 C   s   |dkrt dt pdd }|dkr.td|dk	rFt|sFtd|| _t | _	t
d| _t | _d| _d| _t
 | _|pd	|   | _|| _|| _dS )
a  Initializes a new ThreadPoolExecutor instance.

        Args:
            max_workers: The maximum number of threads that can be used to
                execute the given calls.
            thread_name_prefix: An optional name prefix to give our threads.
            initializer: A callable used to initialize worker threads.
            initargs: A tuple of arguments to pass to the initializer.
        N          r   z"max_workers must be greater than 0zinitializer must be a callableFzThreadPoolExecutor-%d)minos	cpu_count
ValueErrorcallable	TypeError_max_workersqueueZSimpleQueue_work_queue	threadingZ	Semaphorer#   set_threads_brokenr   ZLock_shutdown_lock_counter_thread_name_prefix_initializer	_initargs)r   Zmax_workersZthread_name_prefixr%   r&   r   r   r   r   x   s$    


zThreadPoolExecutor.__init__c               
   O   s   t | dkr| ^}}} nV| s&tdnHd|krZ|d}| ^}} dd l}|jdtdd ntdt | d  |jf |jrt|j|j	rt
d	t	rt
d
t }t||| |}|j| |  |W  5 Q R  S Q R X d S )N   zDdescriptor 'submit' of 'ThreadPoolExecutor' object needs an argumentr   r   z.Passing 'fn' as keyword argument is deprecated)
stacklevelz6submit expected at least 1 positional argument, got %dr.   z*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdown)lenr5   popwarningswarnDeprecationWarningr=   r<   r)   r   RuntimeErrorr   ZFuturer   r8   r   _adjust_thread_count)r   r   r   r   rF   fwr   r   r   submit   s6    

 

zThreadPoolExecutor.submitc                 C   s   | j jddrd S | jfdd}t| j}|| jk rd| jp>| |f }tj|t	t
| || j| j| jfd}d|_|  | j| | jt|< d S )Nr   )Ztimeoutc                 S   s   | d  d S r   )r   )_r   r   r   r   
weakref_cb   s    z;ThreadPoolExecutor._adjust_thread_count.<locals>.weakref_cbz%s_%d)nametargetr   T)r#   acquirer8   rD   r;   r6   r?   r9   ZThreadr(   weakrefrefr@   rA   Zdaemonstartaddr   )r   rO   Znum_threadsZthread_namer
   r   r   r   rJ      s&    



z'ThreadPoolExecutor._adjust_thread_countc              	   C   sb   | j R d| _z| j }W n tjk
r6   Y qTY nX |d k	r|jt| j qW 5 Q R X d S )NzBA thread initializer failed, the thread pool is not usable anymore)	r=   r<   r8   Z
get_nowaitr7   ZEmptyr   r   r)   )r   r'   r   r   r   r!      s    
z&ThreadPoolExecutor._initializer_failedTc              	   C   s@   | j  d| _| jd  W 5 Q R X |r<| jD ]}|  q.d S r   )r=   r   r8   r   r;   r	   )r   waitr
   r   r   r   shutdown   s    
zThreadPoolExecutor.shutdown)Nr,   Nr   )T)r   r   r   	itertoolscount__next__r>   r   rM   r   Executor__text_signature__r*   rJ   r!   rX   r   r   r   r   r+   s   s   
    
& 
r+   )r*   
__author__atexitZconcurrent.futuresr   rY   r7   r9   rS   r1   WeakKeyDictionaryr   r   r   registerobjectr   r(   ZBrokenExecutorr)   r\   r+   r   r   r   r   <module>   s    	
+                                                                                                                                                                                                                                                                                                                                    thread.cpython-38.opt-2.pyc                                                                         0000644                 00000012232 15175327576 0011425 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d@"                     @   s   d Z ddlZddlmZ ddlZddlZddlZddlZddlZe	 Z
dadd Zee G dd deZd	d
 ZG dd dejZG dd dejZdS )z"Brian Quinlan (brian@sweetapp.com)    N)_baseFc                  C   sB   da tt } | D ]\}}|d  q| D ]\}}|  q,d S NT)	_shutdownlist_threads_queuesitemsputjoin)r   tq r   1/usr/lib64/python3.8/concurrent/futures/thread.py_python_exit!   s    r   c                   @   s   e Zd Zdd Zdd ZdS )	_WorkItemc                 C   s   || _ || _|| _|| _d S N)futurefnargskwargs)selfr   r   r   r   r   r   r   __init__.   s    z_WorkItem.__init__c              
   C   sf   | j  sd S z| j| j| j}W n2 tk
rT } z| j | d } W 5 d }~X Y nX | j | d S r   )r   Zset_running_or_notify_cancelr   r   r   BaseExceptionset_exceptionZ
set_result)r   resultexcr   r   r   run4   s    
z_WorkItem.runN)__name__
__module____qualname__r   r   r   r   r   r   r   -   s   r   c                 C   s   |d k	rRz||  W n< t k
rP   tjjddd |  }|d k	rJ|  Y d S X zx|jdd}|d k	r|  ~|  }|d k	r|j  ~qT|  }t	s|d ks|j	r|d k	rd|_	|
d  W d S ~qTW n$ t k
r   tjjddd Y nX d S )NzException in initializer:T)exc_info)blockzException in worker)r   r   ZLOGGERZcritical_initializer_failedgetr   _idle_semaphorereleaser   r   )Zexecutor_referenceZ
work_queueinitializerinitargsZexecutor	work_itemr   r   r   _workerB   s8    

r(   c                   @   s   e Zd ZdS )BrokenThreadPoolN)r   r   r   r   r   r   r   r)   m   s   r)   c                   @   sf   e Zd Ze jZdddZdd Ze	j
jje_e	j
jje_dd	 Zd
d ZdddZe	j
jje_dS )ThreadPoolExecutorN r   c                 C   s   |d krt dt pdd }|dkr.td|d k	rFt|sFtd|| _t | _	t
d| _t | _d| _d| _t
 | _|pd|   | _|| _|| _d S )	N          r   z"max_workers must be greater than 0zinitializer must be a callableFzThreadPoolExecutor-%d)minos	cpu_count
ValueErrorcallable	TypeError_max_workersqueueZSimpleQueue_work_queue	threadingZ	Semaphorer#   set_threads_brokenr   ZLock_shutdown_lock_counter_thread_name_prefix_initializer	_initargs)r   Zmax_workersZthread_name_prefixr%   r&   r   r   r   r   x   s$    


zThreadPoolExecutor.__init__c               
   O   s   t | dkr| ^}}} nV| s&tdnHd|krZ|d}| ^}} dd l}|jdtdd ntdt | d  |jf |jrt|j|j	rt
d	t	rt
d
t }t||| |}|j| |  |W  5 Q R  S Q R X d S )N   zDdescriptor 'submit' of 'ThreadPoolExecutor' object needs an argumentr   r   z.Passing 'fn' as keyword argument is deprecated)
stacklevelz6submit expected at least 1 positional argument, got %dr-   z*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdown)lenr4   popwarningswarnDeprecationWarningr<   r;   r)   r   RuntimeErrorr   ZFuturer   r7   r   _adjust_thread_count)r   r   r   r   rE   fwr   r   r   submit   s6    

 

zThreadPoolExecutor.submitc                 C   s   | j jddrd S | jfdd}t| j}|| jk rd| jp>| |f }tj|t	t
| || j| j| jfd}d|_|  | j| | jt|< d S )Nr   )Ztimeoutc                 S   s   | d  d S r   )r   )_r   r   r   r   
weakref_cb   s    z;ThreadPoolExecutor._adjust_thread_count.<locals>.weakref_cbz%s_%d)nametargetr   T)r#   acquirer7   rC   r:   r5   r>   r8   ZThreadr(   weakrefrefr?   r@   Zdaemonstartaddr   )r   rN   Znum_threadsZthread_namer
   r   r   r   rI      s&    



z'ThreadPoolExecutor._adjust_thread_countc              	   C   sb   | j R d| _z| j }W n tjk
r6   Y qTY nX |d k	r|jt| j qW 5 Q R X d S )NzBA thread initializer failed, the thread pool is not usable anymore)	r<   r;   r7   Z
get_nowaitr6   ZEmptyr   r   r)   )r   r'   r   r   r   r!      s    
z&ThreadPoolExecutor._initializer_failedTc              	   C   s@   | j  d| _| jd  W 5 Q R X |r<| jD ]}|  q.d S r   )r<   r   r7   r   r:   r	   )r   waitr
   r   r   r   shutdown   s    
zThreadPoolExecutor.shutdown)Nr+   Nr   )T)r   r   r   	itertoolscount__next__r=   r   rL   r   Executor__text_signature____doc__rI   r!   rW   r   r   r   r   r*   s   s   
    
& 
r*   )
__author__atexitZconcurrent.futuresr   rX   r6   r8   rR   r0   WeakKeyDictionaryr   r   r   registerobjectr   r(   ZBrokenExecutorr)   r[   r*   r   r   r   r   <module>   s   	
+                                                                                                                                                                                                                                                                                                                                                                      _base.cpython-38.opt-1.pyc                                                                          0000644                 00000052666 15175327576 0011245 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dY                  
   @   sp  d Z ddlZddlZddlZddlZdZdZdZdZdZ	dZ
d	Zd
ZdZe	e
eeegZe	de
dededediZe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G dd de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d%d& Zd3d'd(Ze d)d*Z!defd+d,Z"G d-d. d.eZ#G d/d0 d0eZ$G d1d2 d2e%Z&dS )4z"Brian Quinlan (brian@sweetapp.com)    NFIRST_COMPLETEDFIRST_EXCEPTIONALL_COMPLETED_AS_COMPLETEDPENDINGRUNNING	CANCELLEDCANCELLED_AND_NOTIFIEDFINISHEDpendingrunning	cancelledfinishedzconcurrent.futuresc                   @   s   e Zd ZdZdS )Errorz-Base class for all future-related exceptions.N__name__
__module____qualname____doc__ r   r   0/usr/lib64/python3.8/concurrent/futures/_base.pyr   ,   s   r   c                   @   s   e Zd ZdZdS )CancelledErrorzThe Future was cancelled.Nr   r   r   r   r   r   0   s   r   c                   @   s   e Zd ZdZdS )TimeoutErrorz*The operation exceeded the given deadline.Nr   r   r   r   r   r   4   s   r   c                   @   s   e Zd ZdZdS )InvalidStateErrorz+The operation is not allowed in this state.Nr   r   r   r   r   r   8   s   r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )_Waiterz;Provides the event that wait() and as_completed() block on.c                 C   s   t  | _g | _d S N)	threadingZEventeventfinished_futuresselfr   r   r   __init__>   s    
z_Waiter.__init__c                 C   s   | j | d S r   r   appendr    futurer   r   r   
add_resultB   s    z_Waiter.add_resultc                 C   s   | j | d S r   r"   r$   r   r   r   add_exceptionE   s    z_Waiter.add_exceptionc                 C   s   | j | d S r   r"   r$   r   r   r   add_cancelledH   s    z_Waiter.add_cancelledN)r   r   r   r   r!   r&   r'   r(   r   r   r   r   r   <   s
   r   c                       sD   e Zd ZdZ fddZ fddZ fddZ fdd	Z  ZS )
_AsCompletedWaiterzUsed by as_completed().c                    s   t t|   t | _d S r   )superr)   r!   r   Locklockr   	__class__r   r   r!   N   s    z_AsCompletedWaiter.__init__c              	      s0   | j   tt| | | j  W 5 Q R X d S r   )r,   r*   r)   r&   r   setr$   r-   r   r   r&   R   s    z_AsCompletedWaiter.add_resultc              	      s0   | j   tt| | | j  W 5 Q R X d S r   )r,   r*   r)   r'   r   r/   r$   r-   r   r   r'   W   s    z _AsCompletedWaiter.add_exceptionc              	      s0   | j   tt| | | j  W 5 Q R X d S r   )r,   r*   r)   r(   r   r/   r$   r-   r   r   r(   \   s    z _AsCompletedWaiter.add_cancelled)	r   r   r   r   r!   r&   r'   r(   __classcell__r   r   r-   r   r)   K   s
   r)   c                       s8   e Zd ZdZ fddZ fddZ fddZ  ZS )_FirstCompletedWaiterz*Used by wait(return_when=FIRST_COMPLETED).c                    s   t  | | j  d S r   )r*   r&   r   r/   r$   r-   r   r   r&   d   s    z _FirstCompletedWaiter.add_resultc                    s   t  | | j  d S r   )r*   r'   r   r/   r$   r-   r   r   r'   h   s    z#_FirstCompletedWaiter.add_exceptionc                    s   t  | | j  d S r   )r*   r(   r   r/   r$   r-   r   r   r(   l   s    z#_FirstCompletedWaiter.add_cancelled)r   r   r   r   r&   r'   r(   r0   r   r   r-   r   r1   a   s   r1   c                       sL   e Zd ZdZ fddZdd Z fddZ fdd	Z fd
dZ  Z	S )_AllCompletedWaiterz<Used by wait(return_when=FIRST_EXCEPTION and ALL_COMPLETED).c                    s$   || _ || _t | _t   d S r   )num_pending_callsstop_on_exceptionr   r+   r,   r*   r!   )r    r3   r4   r-   r   r   r!   s   s    
z_AllCompletedWaiter.__init__c              	   C   s4   | j $ |  jd8  _| js&| j  W 5 Q R X d S )N   )r,   r3   r   r/   r   r   r   r   _decrement_pending_callsy   s    z,_AllCompletedWaiter._decrement_pending_callsc                    s   t  | |   d S r   )r*   r&   r6   r$   r-   r   r   r&      s    z_AllCompletedWaiter.add_resultc                    s*   t  | | jr| j  n|   d S r   )r*   r'   r4   r   r/   r6   r$   r-   r   r   r'      s    z!_AllCompletedWaiter.add_exceptionc                    s   t  | |   d S r   )r*   r(   r6   r$   r-   r   r   r(      s    z!_AllCompletedWaiter.add_cancelled)
r   r   r   r   r!   r6   r&   r'   r(   r0   r   r   r-   r   r2   p   s   r2   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_AcquireFutureszDA context manager that does an ordered acquire of Future conditions.c                 C   s   t |td| _d S )N)key)sortedidfutures)r    r;   r   r   r   r!      s    z_AcquireFutures.__init__c                 C   s   | j D ]}|j  qd S r   )r;   
_conditionacquirer$   r   r   r   	__enter__   s    
z_AcquireFutures.__enter__c                 G   s   | j D ]}|j  qd S r   )r;   r<   release)r    argsr%   r   r   r   __exit__   s    
z_AcquireFutures.__exit__N)r   r   r   r   r!   r>   rA   r   r   r   r   r7      s   r7   c                 C   s   |t krt }nZ|tkr t }nJtdd | D }|tkrHt|dd}n"|tkr^t|dd}ntd| | D ]}|j	
| qn|S )Nc                 s   s   | ]}|j ttfkV  qd S r   _stater	   r
   .0fr   r   r   	<genexpr>   s    z._create_and_install_waiters.<locals>.<genexpr>T)r4   FzInvalid return condition: %r)r   r)   r   r1   sumr   r2   r   
ValueError_waitersr#   )fsreturn_whenwaiterZpending_countrF   r   r   r   _create_and_install_waiters   s    rN   c              	   c   sP   | rL| d }|D ]}| | q|j |j | W 5 Q R X ~|  V  q dS )a~  
    Iterate on the list *fs*, yielding finished futures one by one in
    reverse order.
    Before yielding a future, *waiter* is removed from its waiters
    and the future is removed from each set in the collection of sets
    *ref_collect*.

    The aim of this function is to avoid keeping stale references after
    the future is yielded and before the iterator resumes.
    N)remover<   rJ   pop)rK   rM   ref_collectrF   Zfutures_setr   r   r   _yield_finished_futures   s    rS   c           	      c   sB  |dk	r|t   }t| } t| }t| * tdd | D }| | }t| t}W 5 Q R X t|}zt||| fdE dH  |r|dkrd}n(|t   }|dk rtdt||f |j| |j |j}g |_|j  W 5 Q R X |  t||| |fdE dH  q|W 5 | D ]$}|j |j	
| W 5 Q R X qX dS )an  An iterator over the given futures that yields each as it completes.

    Args:
        fs: The sequence of Futures (possibly created by different Executors) to
            iterate over.
        timeout: The maximum number of seconds to wait. If None, then there
            is no limit on the wait time.

    Returns:
        An iterator that yields the given Futures as they complete (finished or
        cancelled). If any given Futures are duplicated, they will be returned
        once.

    Raises:
        TimeoutError: If the entire result iterator could not be generated
            before the given timeout.
    Nc                 s   s    | ]}|j ttfkr|V  qd S r   rB   rD   r   r   r   rG      s   zas_completed.<locals>.<genexpr>)rR   r   z%d (of %d) futures unfinished)time	monotonicr/   lenr7   rN   r   listr<   rJ   rP   rS   r   r   waitr,   r   clearreverse)	rK   timeoutend_timeZtotal_futuresr   r   rM   rF   Zwait_timeoutr   r   r   as_completed   sL    
 r]   DoneAndNotDoneFutureszdone not_donec              
   C   s
  t |  tdd | D }t| | }|tkrJ|rJt||W  5 Q R  S |tkr~|r~tdd |D r~t||W  5 Q R  S t|t| krt||W  5 Q R  S t| |}W 5 Q R X |j	| | D ]"}|j
 |j| W 5 Q R X q||j t|t| | S )a  Wait for the futures in the given sequence to complete.

    Args:
        fs: The sequence of Futures (possibly created by different Executors) to
            wait upon.
        timeout: The maximum number of seconds to wait. If None, then there
            is no limit on the wait time.
        return_when: Indicates when this function should return. The options
            are:

            FIRST_COMPLETED - Return when any future finishes or is
                              cancelled.
            FIRST_EXCEPTION - Return when any future finishes by raising an
                              exception. If no future raises an exception
                              then it is equivalent to ALL_COMPLETED.
            ALL_COMPLETED -   Return when all futures finish or are cancelled.

    Returns:
        A named 2-tuple of sets. The first set, named 'done', contains the
        futures that completed (is finished or cancelled) before the wait
        completed. The second set, named 'not_done', contains uncompleted
        futures.
    c                 s   s    | ]}|j ttfkr|V  qd S r   rB   rD   r   r   r   rG   !  s    zwait.<locals>.<genexpr>c                 s   s&   | ]}|  s| d k	r|V  qd S r   )r   	exceptionrD   r   r   r   rG   (  s     )r7   r/   r   r^   r   anyrV   rN   r   rX   r<   rJ   rP   updater   )rK   r[   rL   doneZnot_donerM   rF   r   r   r   rX     s"    
rX   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dZd ddZdd Zdd Zdd ZdS )!Futurez5Represents the result of an asynchronous computation.c                 C   s,   t  | _t| _d| _d| _g | _g | _dS )z8Initializes the future. Should not be called by clients.N)	r   Z	Conditionr<   r   rC   _result
_exceptionrJ   _done_callbacksr   r   r   r   r!   <  s    
zFuture.__init__c              	   C   s>   | j D ]2}z||  W q tk
r6   td|  Y qX qd S )N!exception calling callback for %r)rf   	ExceptionLOGGERr_   )r    callbackr   r   r   _invoke_callbacksE  s
    
zFuture._invoke_callbacksc              
   C   s   | j  | jtkrx| jrHd| jjt| t| j | jjjf W  5 Q R  S d| jjt| t| j | jjjf W  5 Q R  S d| jjt| t| j f W  5 Q R  S Q R X d S )Nz<%s at %#x state=%s raised %s>z <%s at %#x state=%s returned %s>z<%s at %#x state=%s>)	r<   rC   r
   re   r.   r   r:   _STATE_TO_DESCRIPTION_MAPrd   r   r   r   r   __repr__L  s(    
zFuture.__repr__c              	   C   sf   | j N | jttfkr$W 5 Q R  dS | jttfkr@W 5 Q R  dS t| _| j   W 5 Q R X |   dS )zCancel the future if possible.

        Returns True if the future was cancelled, False otherwise. A future
        cannot be cancelled if it is running or has already completed.
        FT)r<   rC   r   r
   r   r	   
notify_allrk   r   r   r   r   cancel`  s    zFuture.cancelc              
   C   s,   | j  | jttfkW  5 Q R  S Q R X dS )z(Return True if the future was cancelled.N)r<   rC   r   r	   r   r   r   r   r   s  s    zFuture.cancelledc              
   C   s(   | j  | jtkW  5 Q R  S Q R X dS )z1Return True if the future is currently executing.N)r<   rC   r   r   r   r   r   r   x  s    zFuture.runningc              
   C   s.   | j  | jtttfkW  5 Q R  S Q R X dS )z>Return True of the future was cancelled or finished executing.N)r<   rC   r   r	   r
   r   r   r   r   rb   }  s    zFuture.donec                 C   s$   | j rz
| j W 5 d } X n| jS d S r   )re   rd   r   r   r   r   Z__get_result  s
    
zFuture.__get_resultc              	   C   sn   | j 0 | jtttfkr2| j| W 5 Q R  dS W 5 Q R X z||  W n  tk
rh   t	d|  Y nX dS )a%  Attaches a callable that will be called when the future finishes.

        Args:
            fn: A callable that will be called with this future as its only
                argument when the future completes or is cancelled. The callable
                will always be called by a thread in the same process in which
                it was added. If the future has already completed or been
                cancelled then the callable will be called immediately. These
                callables are called in the order that they were added.
        Nrg   )
r<   rC   r   r	   r
   rf   r#   rh   ri   r_   )r    fnr   r   r   add_done_callback  s    zFuture.add_done_callbackNc              
   C   s   z| j  | jttfkr t n"| jtkrB|  W  5 Q R  W ZS | j | | jttfkrdt n(| jtkr|  W  5 Q R  W S t W 5 Q R X W 5 d} X dS )aB  Return the result of the call that the future represents.

        Args:
            timeout: The number of seconds to wait for the result if the future
                isn't done. If None, then there is no limit on the wait time.

        Returns:
            The result of the call that the future represents.

        Raises:
            CancelledError: If the future was cancelled.
            TimeoutError: If the future didn't finish executing before the given
                timeout.
            Exception: If the call raised then that exception will be raised.
        N)	r<   rC   r   r	   r   r
   _Future__get_resultrX   r   r    r[   r   r   r   result  s    

zFuture.resultc              
   C   s   | j | | jttfkrt n| jtkr:| jW  5 Q R  S | j | | jttfkr\t n"| jtkrx| jW  5 Q R  S t W 5 Q R X dS )aU  Return the exception raised by the call that the future represents.

        Args:
            timeout: The number of seconds to wait for the exception if the
                future isn't done. If None, then there is no limit on the wait
                time.

        Returns:
            The exception raised by the call that the future represents or None
            if the call completed without raising.

        Raises:
            CancelledError: If the future was cancelled.
            TimeoutError: If the future didn't finish executing before the given
                timeout.
        N)	r<   rC   r   r	   r   r
   re   rX   r   rs   r   r   r   r_     s    

zFuture.exceptionc              	   C   s   | j t | jtkr<t| _| jD ]}||  qW 5 Q R  dS | jtkrZt| _W 5 Q R  dS t	dt
| | j tdW 5 Q R X dS )a  Mark the future as running or process any cancel notifications.

        Should only be used by Executor implementations and unit tests.

        If the future has been cancelled (cancel() was called and returned
        True) then any threads waiting on the future completing (though calls
        to as_completed() or wait()) are notified and False is returned.

        If the future was not cancelled then it is put in the running state
        (future calls to running() will return True) and True is returned.

        This method should be called by Executor implementations before
        executing the work associated with this future. If this method returns
        False then the work should not be executed.

        Returns:
            False if the Future was cancelled, True otherwise.

        Raises:
            RuntimeError: if this method was already called or if set_result()
                or set_exception() was called.
        FTz!Future %s in unexpected state: %szFuture in unexpected stateN)r<   rC   r   r	   rJ   r(   r   r   ri   Zcriticalr:   RuntimeError)r    rM   r   r   r   set_running_or_notify_cancel  s    


z#Future.set_running_or_notify_cancelc              	   C   sl   | j T | jttthkr*td| j| || _t| _| jD ]}|	|  q<| j 
  W 5 Q R X |   dS )zSets the return value of work associated with the future.

        Should only be used by Executor implementations and unit tests.
        {}: {!r}N)r<   rC   r   r	   r
   r   formatrd   rJ   r&   rn   rk   )r    rt   rM   r   r   r   
set_result  s    
zFuture.set_resultc              	   C   sl   | j T | jttthkr*td| j| || _t| _| jD ]}|	|  q<| j 
  W 5 Q R X |   dS )zSets the result of the future as being the given exception.

        Should only be used by Executor implementations and unit tests.
        rw   N)r<   rC   r   r	   r
   r   rx   re   rJ   r'   rn   rk   )r    r_   rM   r   r   r   set_exception  s    
zFuture.set_exception)N)N)r   r   r   r   r!   rk   rm   ro   r   r   rb   rr   rq   rt   r_   rv   ry   rz   r   r   r   r   rc   9  s   	

#
"(rc   c                   @   sH   e Zd ZdZdd Zde_ddddd	ZdddZdd Zdd Z	dS )ExecutorzCThis is an abstract base class for concrete asynchronous executors.c                  O   s\   t | dkrnD| stdn6d|kr>ddl}|jdtdd ntdt | d	  t dS )
a   Submits a callable to be executed with the given arguments.

        Schedules the callable to be executed as fn(*args, **kwargs) and returns
        a Future instance representing the execution of the callable.

        Returns:
            A Future representing the given call.
           z:descriptor 'submit' of 'Executor' object needs an argumentrp   r   Nz.Passing 'fn' as keyword argument is deprecated)
stacklevelz6submit expected at least 1 positional argument, got %dr5   )rV   	TypeErrorwarningswarnDeprecationWarningNotImplementedError)r@   kwargsr   r   r   r   submit.  s    	
 
zExecutor.submitz($self, fn, /, *args, **kwargs)Nr5   )r[   	chunksizec                   sB   dk	rt    fddt| D  fdd}| S )a}  Returns an iterator equivalent to map(fn, iter).

        Args:
            fn: A callable that will take as many arguments as there are
                passed iterables.
            timeout: The maximum number of seconds to wait. If None, then there
                is no limit on the wait time.
            chunksize: The size of the chunks the iterable will be broken into
                before being passed to a child process. This argument is only
                used by ProcessPoolExecutor; it is ignored by
                ThreadPoolExecutor.

        Returns:
            An iterator equivalent to: map(func, *iterables) but the calls may
            be evaluated out-of-order.

        Raises:
            TimeoutError: If the entire result iterator could not be generated
                before the given timeout.
            Exception: If fn(*args) raises for any values.
        Nc                    s   g | ]}j  f| qS r   )r   )rE   r@   )rp   r    r   r   
<listcomp>`  s     z Executor.map.<locals>.<listcomp>c               	   3   s\   zB  r@d kr&  V  q
  t  V  q
W 5 D ]} |    qHX d S r   )ro   rZ   rQ   rt   rT   rU   )r%   )r\   rK   r[   r   r   result_iteratord  s    z%Executor.map.<locals>.result_iterator)rT   rU   zip)r    rp   r[   r   	iterablesr   r   )r\   rp   rK   r    r[   r   mapG  s
    zExecutor.mapTc                 C   s   dS )a  Clean-up the resources associated with the Executor.

        It is safe to call this method several times. Otherwise, no other
        methods can be called after this one.

        Args:
            wait: If True then shutdown will not return until all running
                futures have finished executing and the resources used by the
                executor have been reclaimed.
        Nr   )r    rX   r   r   r   shutdowns  s    zExecutor.shutdownc                 C   s   | S r   r   r   r   r   r   r>     s    zExecutor.__enter__c                 C   s   | j dd dS )NT)rX   F)r   )r    exc_typeZexc_valZexc_tbr   r   r   rA     s    zExecutor.__exit__)T)
r   r   r   r   r   __text_signature__r   r   r>   rA   r   r   r   r   r{   +  s   ,
r{   c                   @   s   e Zd ZdZdS )BrokenExecutorzR
    Raised when a executor has become non-functional after a severe failure.
    Nr   r   r   r   r   r     s   r   )N)'
__author__collectionsZloggingr   rT   r   r   r   r   r   r   r   r	   r
   Z_FUTURE_STATESrl   Z	getLoggerri   rh   r   r   r   r   objectr   r)   r1   r2   r7   rN   rS   r]   
namedtupler^   rX   rc   r{   ru   r   r   r   r   r   <module>   sh   	     	

> 1 s]                                                                          process.cpython-38.opt-1.pyc                                                                        0000644                 00000047460 15175327576 0011646 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dzn                     @   s  d Z dZddlZddlZddlmZ ddlZddlmZ ddlZ	ddl
ZddlmZ ddlZddlZddlmZ ddlZddlZddlZe ZdaG d	d
 d
Zdd ZdZdZG dd deZG dd dZ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Z#dd Z$dd  Z%d1d!d"Z&d#d$ Z'd%d& Z(d'd( Z)da*da+d)d* Z,d+d, Z-G d-d. d.ej.Z/G d/d0 d0ej0Z1e2e dS )2a-	  Implements ProcessPoolExecutor.

The following diagram and text describe the data-flow through the system:

|======================= In-process =====================|== Out-of-process ==|

+----------+     +----------+       +--------+     +-----------+    +---------+
|          |  => | Work Ids |       |        |     | Call Q    |    | Process |
|          |     +----------+       |        |     +-----------+    |  Pool   |
|          |     | ...      |       |        |     | ...       |    +---------+
|          |     | 6        |    => |        |  => | 5, call() | => |         |
|          |     | 7        |       |        |     | ...       |    |         |
| Process  |     | ...      |       | Local  |     +-----------+    | Process |
|  Pool    |     +----------+       | Worker |                      |  #1..n  |
| Executor |                        | Thread |                      |         |
|          |     +----------- +     |        |     +-----------+    |         |
|          | <=> | Work Items | <=> |        | <=  | Result Q  | <= |         |
|          |     +------------+     |        |     +-----------+    |         |
|          |     | 6: call()  |     |        |     | ...       |    |         |
|          |     |    future  |     |        |     | 4, result |    |         |
|          |     | ...        |     |        |     | 3, except |    |         |
+----------+     +------------+     +--------+     +-----------+    +---------+

Executor.submit() called:
- creates a uniquely numbered _WorkItem and adds it to the "Work Items" dict
- adds the id of the _WorkItem to the "Work Ids" queue

Local worker thread:
- reads work ids from the "Work Ids" queue and looks up the corresponding
  WorkItem from the "Work Items" dict: if the work item has been cancelled then
  it is simply removed from the dict, otherwise it is repackaged as a
  _CallItem and put in the "Call Q". New _CallItems are put in the "Call Q"
  until "Call Q" is full. NOTE: the size of the "Call Q" is kept small because
  calls placed in the "Call Q" can no longer be cancelled with Future.cancel().
- reads _ResultItems from "Result Q", updates the future stored in the
  "Work Items" dict and deletes the dict entry

Process #1..n:
- reads _CallItems from "Call Q", executes the calls, and puts the resulting
  _ResultItems in "Result Q"
z"Brian Quinlan (brian@sweetapp.com)    N)_base)Full)Queue)partialFc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
_ThreadWakeupc                 C   s   t jdd\| _| _d S )NF)Zduplex)mpZPipe_reader_writerself r   2/usr/lib64/python3.8/concurrent/futures/process.py__init__R   s    z_ThreadWakeup.__init__c                 C   s   | j   | j  d S N)r	   closer   r
   r   r   r   r   U   s    
z_ThreadWakeup.closec                 C   s   | j d d S )N    )r	   Z
send_bytesr
   r   r   r   wakeupY   s    z_ThreadWakeup.wakeupc                 C   s   | j  r| j   q d S r   )r   ZpollZ
recv_bytesr
   r   r   r   clear\   s    
z_ThreadWakeup.clearN)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   Q   s   r   c                  C   s@   da tt } | D ]\}}|  q| D ]\}}|  q*d S NT)_global_shutdownlist_threads_wakeupsitemsr   join)r   _thread_wakeuptr   r   r   _python_exita   s    
r       =   c                   @   s   e Zd Zdd Zdd ZdS )_RemoteTracebackc                 C   s
   || _ d S r   tb)r   r%   r   r   r   r   z   s    z_RemoteTraceback.__init__c                 C   s   | j S r   r$   r
   r   r   r   __str__|   s    z_RemoteTraceback.__str__N)r   r   r   r   r&   r   r   r   r   r#   y   s   r#   c                   @   s   e Zd Zdd Zdd ZdS )_ExceptionWithTracebackc                 C   s0   t t|||}d|}|| _d| | _d S )N z

"""
%s""")	tracebackformat_exceptiontyper   excr%   )r   r,   r%   r   r   r   r      s    
z _ExceptionWithTraceback.__init__c                 C   s   t | j| jffS r   )_rebuild_excr,   r%   r
   r   r   r   
__reduce__   s    z"_ExceptionWithTraceback.__reduce__N)r   r   r   r   r.   r   r   r   r   r'      s   r'   c                 C   s   t || _| S r   )r#   	__cause__)r,   r%   r   r   r   r-      s    
r-   c                   @   s   e Zd Zdd ZdS )	_WorkItemc                 C   s   || _ || _|| _|| _d S r   )futurefnargskwargs)r   r1   r2   r3   r4   r   r   r   r      s    z_WorkItem.__init__Nr   r   r   r   r   r   r   r   r0      s   r0   c                   @   s   e Zd ZdddZdS )_ResultItemNc                 C   s   || _ || _|| _d S r   )work_id	exceptionresult)r   r7   r8   r9   r   r   r   r      s    z_ResultItem.__init__)NNr5   r   r   r   r   r6      s   r6   c                   @   s   e Zd Zdd ZdS )	_CallItemc                 C   s   || _ || _|| _|| _d S r   )r7   r2   r3   r4   )r   r7   r2   r3   r4   r   r   r   r      s    z_CallItem.__init__Nr5   r   r   r   r   r:      s   r:   c                       s.   e Zd ZdZd fdd	Z fddZ  ZS )
_SafeQueuez=Safe Queue set exception to the future object linked to a jobr   c                   s   || _ t j||d d S )N)ctx)pending_work_itemssuperr   )r   max_sizer<   r=   	__class__r   r   r      s    z_SafeQueue.__init__c                    sl   t |trZtt|||j}tdd||_	| j
|jd }|d k	rh|j| nt || d S )Nz

"""
{}"""r(   )
isinstancer:   r)   r*   r+   __traceback__r#   formatr   r/   r=   popr7   r1   set_exceptionr>   _on_queue_feeder_error)r   eobjr%   	work_itemr@   r   r   rG      s    
z!_SafeQueue._on_queue_feeder_error)r   )r   r   r   __doc__r   rG   __classcell__r   r   r@   r   r;      s   r;   c                 g   s,   t | }tt|| }|s dS |V  qdS )z, Iterates over zip()ed iterables in chunks. N)ziptuple	itertoolsislice)	chunksize	iterablesitchunkr   r   r   _get_chunks   s
    rU   c                    s    fdd|D S )z Processes a chunk of an iterable passed to map.

    Runs the function passed to map() on a chunk of the
    iterable passed to map.

    This function is run in a separate process.

    c                    s   g | ]} | qS r   r   ).0r3   r2   r   r   
<listcomp>   s     z"_process_chunk.<locals>.<listcomp>r   )r2   rT   r   rW   r   _process_chunk   s    	rY   c              
   C   s^   z|  t|||d W n@ tk
rX } z"t||j}|  t||d W 5 d}~X Y nX dS )z.Safely send back the given result or exception)r9   r8   r8   N)putr6   BaseExceptionr'   rC   )result_queuer7   r9   r8   rH   r,   r   r   r   _sendback_result   s    
r^   c              
   C   s   |dk	r<z||  W n& t k
r:   tjjddd Y dS X | jdd}|dkrb|t  dS z|j|j	|j
}W n> t k
r } z t||j}t||j|d W 5 d}~X Y nX t||j|d ~~q<dS )a  Evaluates calls from call_queue and places the results in result_queue.

    This worker is run in a separate process.

    Args:
        call_queue: A ctx.Queue of _CallItems that will be read and
            evaluated by the worker.
        result_queue: A ctx.Queue of _ResultItems that will written
            to by the worker.
        initializer: A callable initializer, or None
        initargs: A tuple of args for the initializer
    NzException in initializer:T)exc_infoblockrZ   )r9   )r\   r   ZLOGGERZcriticalgetr[   osgetpidr2   r3   r4   r'   rC   r^   r7   )
call_queuer]   initializerinitargsZ	call_itemrrH   r,   r   r   r   _process_worker   s$    "ri   c                 C   sv   |  rdS z|jdd}W n tjk
r4   Y dS X | | }|j rh|jt||j|j	|j
dd q | |= q q dS )aM  Fills call_queue with _WorkItems from pending_work_items.

    This function never blocks.

    Args:
        pending_work_items: A dict mapping work ids to _WorkItems e.g.
            {5: <_WorkItem...>, 6: <_WorkItem...>, ...}
        work_ids: A queue.Queue of work ids e.g. Queue([5, 6, ...]). Work ids
            are consumed and the corresponding _WorkItems from
            pending_work_items are transformed into _CallItems and put in
            call_queue.
        call_queue: A multiprocessing.Queue that will be filled with _CallItems
            derived from _WorkItems.
    NFr`   T)Zfullrb   queueZEmptyr1   Zset_running_or_notify_cancelr[   r:   r2   r3   r4   )r=   Zwork_idsre   r7   rJ   r   r   r   _add_call_item_to_queue   s"    
rk   c              
      s>  dfdd} fdd}|j }	|j }
|	|
g}t||  dd  D }tj|| }d}d}|	|krz|	 }d	}W q tk
r } zt	t
|||j}W 5 d}~X Y qX n|
|krd	}d}|  |rl|  dk	rd
_d_dtd}|dk	r tdd| d|_| D ]\}}|j| ~q(|   D ]}|  qR|  dS t|tr|}|  s|  dS nL|dk	r||jd}|dk	r|jr|j|j n|j|j ~~|  | r4z&dk	rd_|s|  W dS W n tk
r2   Y nX dq2dS )a,  Manages the communication between this process and the worker processes.

    This function is run in a local thread.

    Args:
        executor_reference: A weakref.ref to the ProcessPoolExecutor that owns
            this thread. Used to determine if the ProcessPoolExecutor has been
            garbage collected and that this function can exit.
        process: A list of the ctx.Process instances used as
            workers.
        pending_work_items: A dict mapping work ids to _WorkItems e.g.
            {5: <_WorkItem...>, 6: <_WorkItem...>, ...}
        work_ids_queue: A queue.Queue of work ids e.g. Queue([5, 6, ...]).
        call_queue: A ctx.Queue that will be filled with _CallItems
            derived from _WorkItems for processing by the process workers.
        result_queue: A ctx.SimpleQueue of _ResultItems generated by the
            process workers.
        thread_wakeup: A _ThreadWakeup to allow waking up the
            queue_manager_thread from the main Thread and avoid deadlocks
            caused by permanently locked queues.
    Nc                      s   t p d kp jS r   )r   _shutdown_threadr   )executorr   r   shutting_down@  s    z/_queue_management_worker.<locals>.shutting_downc               	      s   t dd  D } | }d}||k r| dkrt|| D ]6}z d  |d7 }W q: tk
rn   Y  qrY q:X q:t dd  D } q    D ]}|  qd S )Nc                 s   s   | ]}|  V  qd S r   Zis_aliverV   pr   r   r   	<genexpr>F  s     zD_queue_management_worker.<locals>.shutdown_worker.<locals>.<genexpr>r   r!   c                 s   s   | ]}|  V  qd S r   ro   rp   r   r   r   rr   R  s     )sumvaluesrangeZ
put_nowaitr   r   r   )Zn_children_aliveZn_children_to_stopZn_sentinels_sentirq   )re   	processesr   r   shutdown_workerD  s    
z1_queue_management_worker.<locals>.shutdown_workerc                 S   s   g | ]
}|j qS r   )sentinelrp   r   r   r   rX   i  s     z,_queue_management_worker.<locals>.<listcomp>TFzKA child process terminated abruptly, the process pool is not usable anymorez^A process in the process pool was terminated abruptly while the future was running or pending.z
'''
r(   z''')r   rk   rt   r   Z
connectionwaitZrecvr\   r)   r*   r+   rC   r   _brokenrl   BrokenProcessPoolr#   r   r/   r   r1   rF   Z	terminaterB   intrE   r7   r8   Z
set_resultr9   r   )Zexecutor_referencerw   r=   Zwork_ids_queuere   r]   r   rn   rx   Zresult_readerZwakeup_readerZreadersZworker_sentinelsZreadycauseZ	is_brokenZresult_itemrH   Zbper7   rJ   rq   r   )re   rm   rw   r   _queue_management_worker"  s    	(





r   c               	   C   sj   t rtrttda ztd} W n ttfk
r<   Y d S X | dkrJd S | dkrVd S d|  attd S )NTSC_SEM_NSEMS_MAX   z@system provides too few semaphores (%d available, 256 necessary))_system_limits_checked_system_limitedNotImplementedErrorrc   sysconfAttributeError
ValueError)Z	nsems_maxr   r   r   _check_system_limits  s     r   c                 c   s&   | D ]}|   |r| V  qqdS )z
    Specialized implementation of itertools.chain.from_iterable.
    Each item in *iterable* should be a list.  This function is
    careful not to keep references to yielded objects.
    N)reverserE   )iterableZelementr   r   r   _chain_from_iterable_of_lists  s    r   c                   @   s   e Zd ZdZdS )r|   zy
    Raised when a process in a ProcessPoolExecutor terminated abruptly
    while a future was in the running state.
    N)r   r   r   rK   r   r   r   r   r|     s   r|   c                       st   e Zd ZdddZdd Zdd Zd	d
 Zejjj	e_	ejjj
e_
ddd fdd
ZdddZejjj
e_
  ZS )ProcessPoolExecutorNr   c                 C   s  t   |dkr6t pd| _tjdkrntt| j| _n8|dkrHtdn tjdkrh|tkrhtdt || _|dkr~t	
 }|| _|dk	rt|std|| _|| _d| _i | _d| _t | _d| _d| _i | _| jt }t|| j| jd	| _d
| j_| | _t  | _!t" | _#dS )aS  Initializes a new ProcessPoolExecutor instance.

        Args:
            max_workers: The maximum number of processes that can be used to
                execute the given calls. If None or not given then as many
                worker processes will be created as the machine has processors.
            mp_context: A multiprocessing context to launch the workers. This
                object should provide SimpleQueue, Queue and Process.
            initializer: A callable used to initialize worker processes.
            initargs: A tuple of arguments to pass to the initializer.
        Nr!   Zwin32r   z"max_workers must be greater than 0zmax_workers must be <= zinitializer must be a callableF)r?   r<   r=   T)$r   rc   	cpu_count_max_workerssysplatformmin_MAX_WINDOWS_WORKERSr   r   Zget_context_mp_contextcallable	TypeError_initializer	_initargs_queue_management_thread
_processesrl   	threadingZLock_shutdown_lockr{   _queue_count_pending_work_itemsEXTRA_QUEUED_CALLSr;   _call_queueZ_ignore_epipeZSimpleQueue_result_queuerj   r   	_work_idsr   _queue_management_thread_wakeup)r   Zmax_workersZ
mp_contextrf   rg   Z
queue_sizer   r   r   r     sP    




 

zProcessPoolExecutor.__init__c              	   C   sv   | j d krr| jfdd}|   tjtt| || j| j	| j
| j| j| jfdd| _ d| j _| j   | jt| j < d S )Nc                 S   s   t jd |  d S )Nz?Executor collected: triggering callback for QueueManager wakeup)r   utildebugr   )r   r   r   r   r   
weakref_cbB  s    zFProcessPoolExecutor._start_queue_management_thread.<locals>.weakref_cbZQueueManagerThread)targetr3   nameT)r   r   _adjust_process_countr   ZThreadr   weakrefrefr   r   r   r   r   Zdaemonstartr   )r   r   r   r   r   _start_queue_management_thread=  s(    




z2ProcessPoolExecutor._start_queue_management_threadc                 C   sP   t t| j| jD ]8}| jjt| j| j| j	| j
fd}|  || j|j< qd S )N)r   r3   )ru   lenr   r   r   ZProcessri   r   r   r   r   r   pid)r   r   rq   r   r   r   r   X  s    z)ProcessPoolExecutor._adjust_process_countc               
   O   s
  t | dkr| ^}}} nV| s&tdnHd|krZ|d}| ^}} dd l}|jdtdd ntdt | d  |j |jrt|j|j	rt
d	trt
d
t }t||| |}||j|j< |j|j | jd7  _|j  |  |W  5 Q R  S Q R X d S )N   zEdescriptor 'submit' of 'ProcessPoolExecutor' object needs an argumentr2   r   z.Passing 'fn' as keyword argument is deprecated)
stacklevelz6submit expected at least 1 positional argument, got %dr!   z*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdown)r   r   rE   warningswarnDeprecationWarningr   r{   r|   rl   RuntimeErrorr   r   ZFuturer0   r   r   r   r[   r   r   r   )r3   r4   r   r2   r   fwr   r   r   submitc  s<    

 


zProcessPoolExecutor.submitr!   )timeoutrQ   c                   s:   |dk rt dt jtt|t|d|i|d}t|S )aj  Returns an iterator equivalent to map(fn, iter).

        Args:
            fn: A callable that will take as many arguments as there are
                passed iterables.
            timeout: The maximum number of seconds to wait. If None, then there
                is no limit on the wait time.
            chunksize: If greater than one, the iterables will be chopped into
                chunks of size chunksize and submitted to the process pool.
                If set to one, the items in the list will be sent one at a time.

        Returns:
            An iterator equivalent to: map(func, *iterables) but the calls may
            be evaluated out-of-order.

        Raises:
            TimeoutError: If the entire result iterator could not be generated
                before the given timeout.
            Exception: If fn(*args) raises for any values.
        r!   zchunksize must be >= 1.rQ   )r   )r   r>   mapr   rY   rU   r   )r   r2   r   rQ   rR   Zresultsr@   r   r   r     s    zProcessPoolExecutor.mapTc              	   C   s   | j  d| _W 5 Q R X | jr6| j  |r6| j  d | _| jd k	rd| j  |r^| j  d | _d | _	d | _
| jr| j  d | _d S r   )r   rl   r   r   r   r   r   r   Zjoin_threadr   r   )r   rz   r   r   r   shutdown  s"    





zProcessPoolExecutor.shutdown)NNNr   )T)r   r   r   r   r   r   r   r   Executor__text_signature__rK   r   r   rL   r   r   r@   r   r     s       
K$
r   )NN)3rK   
__author__atexitrc   Zconcurrent.futuresr   rj   r   Zmultiprocessingr   Zmultiprocessing.connectionZmultiprocessing.queuesr   r   r   	functoolsr   rO   r   r)   WeakKeyDictionaryr   r   r   r    r   r   	Exceptionr#   r'   r-   objectr0   r6   r:   r;   rU   rY   r^   ri   rk   r   r   r   r   r   ZBrokenExecutorr|   r   r   registerr   r   r   r   <module>   sV   *		

)& ! P                                                                                                                                                                                                                _base.cpython-38.pyc                                                                                0000644                 00000052666 15175327576 0010306 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dY                  
   @   sp  d Z ddlZddlZddlZddlZdZdZdZdZdZ	dZ
d	Zd
ZdZe	e
eeegZe	de
dededediZe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G dd de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d%d& Zd3d'd(Ze d)d*Z!defd+d,Z"G d-d. d.eZ#G d/d0 d0eZ$G d1d2 d2e%Z&dS )4z"Brian Quinlan (brian@sweetapp.com)    NFIRST_COMPLETEDFIRST_EXCEPTIONALL_COMPLETED_AS_COMPLETEDPENDINGRUNNING	CANCELLEDCANCELLED_AND_NOTIFIEDFINISHEDpendingrunning	cancelledfinishedzconcurrent.futuresc                   @   s   e Zd ZdZdS )Errorz-Base class for all future-related exceptions.N__name__
__module____qualname____doc__ r   r   0/usr/lib64/python3.8/concurrent/futures/_base.pyr   ,   s   r   c                   @   s   e Zd ZdZdS )CancelledErrorzThe Future was cancelled.Nr   r   r   r   r   r   0   s   r   c                   @   s   e Zd ZdZdS )TimeoutErrorz*The operation exceeded the given deadline.Nr   r   r   r   r   r   4   s   r   c                   @   s   e Zd ZdZdS )InvalidStateErrorz+The operation is not allowed in this state.Nr   r   r   r   r   r   8   s   r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )_Waiterz;Provides the event that wait() and as_completed() block on.c                 C   s   t  | _g | _d S N)	threadingZEventeventfinished_futuresselfr   r   r   __init__>   s    
z_Waiter.__init__c                 C   s   | j | d S r   r   appendr    futurer   r   r   
add_resultB   s    z_Waiter.add_resultc                 C   s   | j | d S r   r"   r$   r   r   r   add_exceptionE   s    z_Waiter.add_exceptionc                 C   s   | j | d S r   r"   r$   r   r   r   add_cancelledH   s    z_Waiter.add_cancelledN)r   r   r   r   r!   r&   r'   r(   r   r   r   r   r   <   s
   r   c                       sD   e Zd ZdZ fddZ fddZ fddZ fdd	Z  ZS )
_AsCompletedWaiterzUsed by as_completed().c                    s   t t|   t | _d S r   )superr)   r!   r   Locklockr   	__class__r   r   r!   N   s    z_AsCompletedWaiter.__init__c              	      s0   | j   tt| | | j  W 5 Q R X d S r   )r,   r*   r)   r&   r   setr$   r-   r   r   r&   R   s    z_AsCompletedWaiter.add_resultc              	      s0   | j   tt| | | j  W 5 Q R X d S r   )r,   r*   r)   r'   r   r/   r$   r-   r   r   r'   W   s    z _AsCompletedWaiter.add_exceptionc              	      s0   | j   tt| | | j  W 5 Q R X d S r   )r,   r*   r)   r(   r   r/   r$   r-   r   r   r(   \   s    z _AsCompletedWaiter.add_cancelled)	r   r   r   r   r!   r&   r'   r(   __classcell__r   r   r-   r   r)   K   s
   r)   c                       s8   e Zd ZdZ fddZ fddZ fddZ  ZS )_FirstCompletedWaiterz*Used by wait(return_when=FIRST_COMPLETED).c                    s   t  | | j  d S r   )r*   r&   r   r/   r$   r-   r   r   r&   d   s    z _FirstCompletedWaiter.add_resultc                    s   t  | | j  d S r   )r*   r'   r   r/   r$   r-   r   r   r'   h   s    z#_FirstCompletedWaiter.add_exceptionc                    s   t  | | j  d S r   )r*   r(   r   r/   r$   r-   r   r   r(   l   s    z#_FirstCompletedWaiter.add_cancelled)r   r   r   r   r&   r'   r(   r0   r   r   r-   r   r1   a   s   r1   c                       sL   e Zd ZdZ fddZdd Z fddZ fdd	Z fd
dZ  Z	S )_AllCompletedWaiterz<Used by wait(return_when=FIRST_EXCEPTION and ALL_COMPLETED).c                    s$   || _ || _t | _t   d S r   )num_pending_callsstop_on_exceptionr   r+   r,   r*   r!   )r    r3   r4   r-   r   r   r!   s   s    
z_AllCompletedWaiter.__init__c              	   C   s4   | j $ |  jd8  _| js&| j  W 5 Q R X d S )N   )r,   r3   r   r/   r   r   r   r   _decrement_pending_callsy   s    z,_AllCompletedWaiter._decrement_pending_callsc                    s   t  | |   d S r   )r*   r&   r6   r$   r-   r   r   r&      s    z_AllCompletedWaiter.add_resultc                    s*   t  | | jr| j  n|   d S r   )r*   r'   r4   r   r/   r6   r$   r-   r   r   r'      s    z!_AllCompletedWaiter.add_exceptionc                    s   t  | |   d S r   )r*   r(   r6   r$   r-   r   r   r(      s    z!_AllCompletedWaiter.add_cancelled)
r   r   r   r   r!   r6   r&   r'   r(   r0   r   r   r-   r   r2   p   s   r2   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_AcquireFutureszDA context manager that does an ordered acquire of Future conditions.c                 C   s   t |td| _d S )N)key)sortedidfutures)r    r;   r   r   r   r!      s    z_AcquireFutures.__init__c                 C   s   | j D ]}|j  qd S r   )r;   
_conditionacquirer$   r   r   r   	__enter__   s    
z_AcquireFutures.__enter__c                 G   s   | j D ]}|j  qd S r   )r;   r<   release)r    argsr%   r   r   r   __exit__   s    
z_AcquireFutures.__exit__N)r   r   r   r   r!   r>   rA   r   r   r   r   r7      s   r7   c                 C   s   |t krt }nZ|tkr t }nJtdd | D }|tkrHt|dd}n"|tkr^t|dd}ntd| | D ]}|j	
| qn|S )Nc                 s   s   | ]}|j ttfkV  qd S r   _stater	   r
   .0fr   r   r   	<genexpr>   s    z._create_and_install_waiters.<locals>.<genexpr>T)r4   FzInvalid return condition: %r)r   r)   r   r1   sumr   r2   r   
ValueError_waitersr#   )fsreturn_whenwaiterZpending_countrF   r   r   r   _create_and_install_waiters   s    rN   c              	   c   sP   | rL| d }|D ]}| | q|j |j | W 5 Q R X ~|  V  q dS )a~  
    Iterate on the list *fs*, yielding finished futures one by one in
    reverse order.
    Before yielding a future, *waiter* is removed from its waiters
    and the future is removed from each set in the collection of sets
    *ref_collect*.

    The aim of this function is to avoid keeping stale references after
    the future is yielded and before the iterator resumes.
    N)remover<   rJ   pop)rK   rM   ref_collectrF   Zfutures_setr   r   r   _yield_finished_futures   s    rS   c           	      c   sB  |dk	r|t   }t| } t| }t| * tdd | D }| | }t| t}W 5 Q R X t|}zt||| fdE dH  |r|dkrd}n(|t   }|dk rtdt||f |j| |j |j}g |_|j  W 5 Q R X |  t||| |fdE dH  q|W 5 | D ]$}|j |j	
| W 5 Q R X qX dS )an  An iterator over the given futures that yields each as it completes.

    Args:
        fs: The sequence of Futures (possibly created by different Executors) to
            iterate over.
        timeout: The maximum number of seconds to wait. If None, then there
            is no limit on the wait time.

    Returns:
        An iterator that yields the given Futures as they complete (finished or
        cancelled). If any given Futures are duplicated, they will be returned
        once.

    Raises:
        TimeoutError: If the entire result iterator could not be generated
            before the given timeout.
    Nc                 s   s    | ]}|j ttfkr|V  qd S r   rB   rD   r   r   r   rG      s   zas_completed.<locals>.<genexpr>)rR   r   z%d (of %d) futures unfinished)time	monotonicr/   lenr7   rN   r   listr<   rJ   rP   rS   r   r   waitr,   r   clearreverse)	rK   timeoutend_timeZtotal_futuresr   r   rM   rF   Zwait_timeoutr   r   r   as_completed   sL    
 r]   DoneAndNotDoneFutureszdone not_donec              
   C   s
  t |  tdd | D }t| | }|tkrJ|rJt||W  5 Q R  S |tkr~|r~tdd |D r~t||W  5 Q R  S t|t| krt||W  5 Q R  S t| |}W 5 Q R X |j	| | D ]"}|j
 |j| W 5 Q R X q||j t|t| | S )a  Wait for the futures in the given sequence to complete.

    Args:
        fs: The sequence of Futures (possibly created by different Executors) to
            wait upon.
        timeout: The maximum number of seconds to wait. If None, then there
            is no limit on the wait time.
        return_when: Indicates when this function should return. The options
            are:

            FIRST_COMPLETED - Return when any future finishes or is
                              cancelled.
            FIRST_EXCEPTION - Return when any future finishes by raising an
                              exception. If no future raises an exception
                              then it is equivalent to ALL_COMPLETED.
            ALL_COMPLETED -   Return when all futures finish or are cancelled.

    Returns:
        A named 2-tuple of sets. The first set, named 'done', contains the
        futures that completed (is finished or cancelled) before the wait
        completed. The second set, named 'not_done', contains uncompleted
        futures.
    c                 s   s    | ]}|j ttfkr|V  qd S r   rB   rD   r   r   r   rG   !  s    zwait.<locals>.<genexpr>c                 s   s&   | ]}|  s| d k	r|V  qd S r   )r   	exceptionrD   r   r   r   rG   (  s     )r7   r/   r   r^   r   anyrV   rN   r   rX   r<   rJ   rP   updater   )rK   r[   rL   doneZnot_donerM   rF   r   r   r   rX     s"    
rX   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dZd ddZdd Zdd Zdd ZdS )!Futurez5Represents the result of an asynchronous computation.c                 C   s,   t  | _t| _d| _d| _g | _g | _dS )z8Initializes the future. Should not be called by clients.N)	r   Z	Conditionr<   r   rC   _result
_exceptionrJ   _done_callbacksr   r   r   r   r!   <  s    
zFuture.__init__c              	   C   s>   | j D ]2}z||  W q tk
r6   td|  Y qX qd S )N!exception calling callback for %r)rf   	ExceptionLOGGERr_   )r    callbackr   r   r   _invoke_callbacksE  s
    
zFuture._invoke_callbacksc              
   C   s   | j  | jtkrx| jrHd| jjt| t| j | jjjf W  5 Q R  S d| jjt| t| j | jjjf W  5 Q R  S d| jjt| t| j f W  5 Q R  S Q R X d S )Nz<%s at %#x state=%s raised %s>z <%s at %#x state=%s returned %s>z<%s at %#x state=%s>)	r<   rC   r
   re   r.   r   r:   _STATE_TO_DESCRIPTION_MAPrd   r   r   r   r   __repr__L  s(    
zFuture.__repr__c              	   C   sf   | j N | jttfkr$W 5 Q R  dS | jttfkr@W 5 Q R  dS t| _| j   W 5 Q R X |   dS )zCancel the future if possible.

        Returns True if the future was cancelled, False otherwise. A future
        cannot be cancelled if it is running or has already completed.
        FT)r<   rC   r   r
   r   r	   
notify_allrk   r   r   r   r   cancel`  s    zFuture.cancelc              
   C   s,   | j  | jttfkW  5 Q R  S Q R X dS )z(Return True if the future was cancelled.N)r<   rC   r   r	   r   r   r   r   r   s  s    zFuture.cancelledc              
   C   s(   | j  | jtkW  5 Q R  S Q R X dS )z1Return True if the future is currently executing.N)r<   rC   r   r   r   r   r   r   x  s    zFuture.runningc              
   C   s.   | j  | jtttfkW  5 Q R  S Q R X dS )z>Return True of the future was cancelled or finished executing.N)r<   rC   r   r	   r
   r   r   r   r   rb   }  s    zFuture.donec                 C   s$   | j rz
| j W 5 d } X n| jS d S r   )re   rd   r   r   r   r   Z__get_result  s
    
zFuture.__get_resultc              	   C   sn   | j 0 | jtttfkr2| j| W 5 Q R  dS W 5 Q R X z||  W n  tk
rh   t	d|  Y nX dS )a%  Attaches a callable that will be called when the future finishes.

        Args:
            fn: A callable that will be called with this future as its only
                argument when the future completes or is cancelled. The callable
                will always be called by a thread in the same process in which
                it was added. If the future has already completed or been
                cancelled then the callable will be called immediately. These
                callables are called in the order that they were added.
        Nrg   )
r<   rC   r   r	   r
   rf   r#   rh   ri   r_   )r    fnr   r   r   add_done_callback  s    zFuture.add_done_callbackNc              
   C   s   z| j  | jttfkr t n"| jtkrB|  W  5 Q R  W ZS | j | | jttfkrdt n(| jtkr|  W  5 Q R  W S t W 5 Q R X W 5 d} X dS )aB  Return the result of the call that the future represents.

        Args:
            timeout: The number of seconds to wait for the result if the future
                isn't done. If None, then there is no limit on the wait time.

        Returns:
            The result of the call that the future represents.

        Raises:
            CancelledError: If the future was cancelled.
            TimeoutError: If the future didn't finish executing before the given
                timeout.
            Exception: If the call raised then that exception will be raised.
        N)	r<   rC   r   r	   r   r
   _Future__get_resultrX   r   r    r[   r   r   r   result  s    

zFuture.resultc              
   C   s   | j | | jttfkrt n| jtkr:| jW  5 Q R  S | j | | jttfkr\t n"| jtkrx| jW  5 Q R  S t W 5 Q R X dS )aU  Return the exception raised by the call that the future represents.

        Args:
            timeout: The number of seconds to wait for the exception if the
                future isn't done. If None, then there is no limit on the wait
                time.

        Returns:
            The exception raised by the call that the future represents or None
            if the call completed without raising.

        Raises:
            CancelledError: If the future was cancelled.
            TimeoutError: If the future didn't finish executing before the given
                timeout.
        N)	r<   rC   r   r	   r   r
   re   rX   r   rs   r   r   r   r_     s    

zFuture.exceptionc              	   C   s   | j t | jtkr<t| _| jD ]}||  qW 5 Q R  dS | jtkrZt| _W 5 Q R  dS t	dt
| | j tdW 5 Q R X dS )a  Mark the future as running or process any cancel notifications.

        Should only be used by Executor implementations and unit tests.

        If the future has been cancelled (cancel() was called and returned
        True) then any threads waiting on the future completing (though calls
        to as_completed() or wait()) are notified and False is returned.

        If the future was not cancelled then it is put in the running state
        (future calls to running() will return True) and True is returned.

        This method should be called by Executor implementations before
        executing the work associated with this future. If this method returns
        False then the work should not be executed.

        Returns:
            False if the Future was cancelled, True otherwise.

        Raises:
            RuntimeError: if this method was already called or if set_result()
                or set_exception() was called.
        FTz!Future %s in unexpected state: %szFuture in unexpected stateN)r<   rC   r   r	   rJ   r(   r   r   ri   Zcriticalr:   RuntimeError)r    rM   r   r   r   set_running_or_notify_cancel  s    


z#Future.set_running_or_notify_cancelc              	   C   sl   | j T | jttthkr*td| j| || _t| _| jD ]}|	|  q<| j 
  W 5 Q R X |   dS )zSets the return value of work associated with the future.

        Should only be used by Executor implementations and unit tests.
        {}: {!r}N)r<   rC   r   r	   r
   r   formatrd   rJ   r&   rn   rk   )r    rt   rM   r   r   r   
set_result  s    
zFuture.set_resultc              	   C   sl   | j T | jttthkr*td| j| || _t| _| jD ]}|	|  q<| j 
  W 5 Q R X |   dS )zSets the result of the future as being the given exception.

        Should only be used by Executor implementations and unit tests.
        rw   N)r<   rC   r   r	   r
   r   rx   re   rJ   r'   rn   rk   )r    r_   rM   r   r   r   set_exception  s    
zFuture.set_exception)N)N)r   r   r   r   r!   rk   rm   ro   r   r   rb   rr   rq   rt   r_   rv   ry   rz   r   r   r   r   rc   9  s   	

#
"(rc   c                   @   sH   e Zd ZdZdd Zde_ddddd	ZdddZdd Zdd Z	dS )ExecutorzCThis is an abstract base class for concrete asynchronous executors.c                  O   s\   t | dkrnD| stdn6d|kr>ddl}|jdtdd ntdt | d	  t dS )
a   Submits a callable to be executed with the given arguments.

        Schedules the callable to be executed as fn(*args, **kwargs) and returns
        a Future instance representing the execution of the callable.

        Returns:
            A Future representing the given call.
           z:descriptor 'submit' of 'Executor' object needs an argumentrp   r   Nz.Passing 'fn' as keyword argument is deprecated)
stacklevelz6submit expected at least 1 positional argument, got %dr5   )rV   	TypeErrorwarningswarnDeprecationWarningNotImplementedError)r@   kwargsr   r   r   r   submit.  s    	
 
zExecutor.submitz($self, fn, /, *args, **kwargs)Nr5   )r[   	chunksizec                   sB   dk	rt    fddt| D  fdd}| S )a}  Returns an iterator equivalent to map(fn, iter).

        Args:
            fn: A callable that will take as many arguments as there are
                passed iterables.
            timeout: The maximum number of seconds to wait. If None, then there
                is no limit on the wait time.
            chunksize: The size of the chunks the iterable will be broken into
                before being passed to a child process. This argument is only
                used by ProcessPoolExecutor; it is ignored by
                ThreadPoolExecutor.

        Returns:
            An iterator equivalent to: map(func, *iterables) but the calls may
            be evaluated out-of-order.

        Raises:
            TimeoutError: If the entire result iterator could not be generated
                before the given timeout.
            Exception: If fn(*args) raises for any values.
        Nc                    s   g | ]}j  f| qS r   )r   )rE   r@   )rp   r    r   r   
<listcomp>`  s     z Executor.map.<locals>.<listcomp>c               	   3   s\   zB  r@d kr&  V  q
  t  V  q
W 5 D ]} |    qHX d S r   )ro   rZ   rQ   rt   rT   rU   )r%   )r\   rK   r[   r   r   result_iteratord  s    z%Executor.map.<locals>.result_iterator)rT   rU   zip)r    rp   r[   r   	iterablesr   r   )r\   rp   rK   r    r[   r   mapG  s
    zExecutor.mapTc                 C   s   dS )a  Clean-up the resources associated with the Executor.

        It is safe to call this method several times. Otherwise, no other
        methods can be called after this one.

        Args:
            wait: If True then shutdown will not return until all running
                futures have finished executing and the resources used by the
                executor have been reclaimed.
        Nr   )r    rX   r   r   r   shutdowns  s    zExecutor.shutdownc                 C   s   | S r   r   r   r   r   r   r>     s    zExecutor.__enter__c                 C   s   | j dd dS )NT)rX   F)r   )r    exc_typeZexc_valZexc_tbr   r   r   rA     s    zExecutor.__exit__)T)
r   r   r   r   r   __text_signature__r   r   r>   rA   r   r   r   r   r{   +  s   ,
r{   c                   @   s   e Zd ZdZdS )BrokenExecutorzR
    Raised when a executor has become non-functional after a severe failure.
    Nr   r   r   r   r   r     s   r   )N)'
__author__collectionsZloggingr   rT   r   r   r   r   r   r   r   r	   r
   Z_FUTURE_STATESrl   Z	getLoggerri   rh   r   r   r   r   objectr   r)   r1   r2   r7   rN   rS   r]   
namedtupler^   rX   rc   r{   ru   r   r   r   r   r   <module>   sh   	     	

> 1 s]                                                                          process.cpython-38.pyc                                                                              0000644                 00000047516 15175327576 0010711 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dzn                     @   s  d Z dZddlZddlZddlmZ ddlZddlmZ ddlZ	ddl
ZddlmZ ddlZddlZddlmZ ddlZddlZddlZe ZdaG d	d
 d
Zdd ZdZdZG dd deZG dd dZ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Z#dd Z$dd  Z%d1d!d"Z&d#d$ Z'd%d& Z(d'd( Z)da*da+d)d* Z,d+d, Z-G d-d. d.ej.Z/G d/d0 d0ej0Z1e2e dS )2a-	  Implements ProcessPoolExecutor.

The following diagram and text describe the data-flow through the system:

|======================= In-process =====================|== Out-of-process ==|

+----------+     +----------+       +--------+     +-----------+    +---------+
|          |  => | Work Ids |       |        |     | Call Q    |    | Process |
|          |     +----------+       |        |     +-----------+    |  Pool   |
|          |     | ...      |       |        |     | ...       |    +---------+
|          |     | 6        |    => |        |  => | 5, call() | => |         |
|          |     | 7        |       |        |     | ...       |    |         |
| Process  |     | ...      |       | Local  |     +-----------+    | Process |
|  Pool    |     +----------+       | Worker |                      |  #1..n  |
| Executor |                        | Thread |                      |         |
|          |     +----------- +     |        |     +-----------+    |         |
|          | <=> | Work Items | <=> |        | <=  | Result Q  | <= |         |
|          |     +------------+     |        |     +-----------+    |         |
|          |     | 6: call()  |     |        |     | ...       |    |         |
|          |     |    future  |     |        |     | 4, result |    |         |
|          |     | ...        |     |        |     | 3, except |    |         |
+----------+     +------------+     +--------+     +-----------+    +---------+

Executor.submit() called:
- creates a uniquely numbered _WorkItem and adds it to the "Work Items" dict
- adds the id of the _WorkItem to the "Work Ids" queue

Local worker thread:
- reads work ids from the "Work Ids" queue and looks up the corresponding
  WorkItem from the "Work Items" dict: if the work item has been cancelled then
  it is simply removed from the dict, otherwise it is repackaged as a
  _CallItem and put in the "Call Q". New _CallItems are put in the "Call Q"
  until "Call Q" is full. NOTE: the size of the "Call Q" is kept small because
  calls placed in the "Call Q" can no longer be cancelled with Future.cancel().
- reads _ResultItems from "Result Q", updates the future stored in the
  "Work Items" dict and deletes the dict entry

Process #1..n:
- reads _CallItems from "Call Q", executes the calls, and puts the resulting
  _ResultItems in "Result Q"
z"Brian Quinlan (brian@sweetapp.com)    N)_base)Full)Queue)partialFc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
_ThreadWakeupc                 C   s   t jdd\| _| _d S )NF)Zduplex)mpZPipe_reader_writerself r   2/usr/lib64/python3.8/concurrent/futures/process.py__init__R   s    z_ThreadWakeup.__init__c                 C   s   | j   | j  d S N)r	   closer   r
   r   r   r   r   U   s    
z_ThreadWakeup.closec                 C   s   | j d d S )N    )r	   Z
send_bytesr
   r   r   r   wakeupY   s    z_ThreadWakeup.wakeupc                 C   s   | j  r| j   q d S r   )r   ZpollZ
recv_bytesr
   r   r   r   clear\   s    
z_ThreadWakeup.clearN)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   Q   s   r   c                  C   s@   da tt } | D ]\}}|  q| D ]\}}|  q*d S NT)_global_shutdownlist_threads_wakeupsitemsr   join)r   _thread_wakeuptr   r   r   _python_exita   s    
r       =   c                   @   s   e Zd Zdd Zdd ZdS )_RemoteTracebackc                 C   s
   || _ d S r   tb)r   r%   r   r   r   r   z   s    z_RemoteTraceback.__init__c                 C   s   | j S r   r$   r
   r   r   r   __str__|   s    z_RemoteTraceback.__str__N)r   r   r   r   r&   r   r   r   r   r#   y   s   r#   c                   @   s   e Zd Zdd Zdd ZdS )_ExceptionWithTracebackc                 C   s0   t t|||}d|}|| _d| | _d S )N z

"""
%s""")	tracebackformat_exceptiontyper   excr%   )r   r,   r%   r   r   r   r      s    
z _ExceptionWithTraceback.__init__c                 C   s   t | j| jffS r   )_rebuild_excr,   r%   r
   r   r   r   
__reduce__   s    z"_ExceptionWithTraceback.__reduce__N)r   r   r   r   r.   r   r   r   r   r'      s   r'   c                 C   s   t || _| S r   )r#   	__cause__)r,   r%   r   r   r   r-      s    
r-   c                   @   s   e Zd Zdd ZdS )	_WorkItemc                 C   s   || _ || _|| _|| _d S r   )futurefnargskwargs)r   r1   r2   r3   r4   r   r   r   r      s    z_WorkItem.__init__Nr   r   r   r   r   r   r   r   r0      s   r0   c                   @   s   e Zd ZdddZdS )_ResultItemNc                 C   s   || _ || _|| _d S r   )work_id	exceptionresult)r   r7   r8   r9   r   r   r   r      s    z_ResultItem.__init__)NNr5   r   r   r   r   r6      s   r6   c                   @   s   e Zd Zdd ZdS )	_CallItemc                 C   s   || _ || _|| _|| _d S r   )r7   r2   r3   r4   )r   r7   r2   r3   r4   r   r   r   r      s    z_CallItem.__init__Nr5   r   r   r   r   r:      s   r:   c                       s.   e Zd ZdZd fdd	Z fddZ  ZS )
_SafeQueuez=Safe Queue set exception to the future object linked to a jobr   c                   s   || _ t j||d d S )N)ctx)pending_work_itemssuperr   )r   max_sizer<   r=   	__class__r   r   r      s    z_SafeQueue.__init__c                    sl   t |trZtt|||j}tdd||_	| j
|jd }|d k	rh|j| nt || d S )Nz

"""
{}"""r(   )
isinstancer:   r)   r*   r+   __traceback__r#   formatr   r/   r=   popr7   r1   set_exceptionr>   _on_queue_feeder_error)r   eobjr%   	work_itemr@   r   r   rG      s    
z!_SafeQueue._on_queue_feeder_error)r   )r   r   r   __doc__r   rG   __classcell__r   r   r@   r   r;      s   r;   c                 g   s,   t | }tt|| }|s dS |V  qdS )z, Iterates over zip()ed iterables in chunks. N)ziptuple	itertoolsislice)	chunksize	iterablesitchunkr   r   r   _get_chunks   s
    rU   c                    s    fdd|D S )z Processes a chunk of an iterable passed to map.

    Runs the function passed to map() on a chunk of the
    iterable passed to map.

    This function is run in a separate process.

    c                    s   g | ]} | qS r   r   ).0r3   r2   r   r   
<listcomp>   s     z"_process_chunk.<locals>.<listcomp>r   )r2   rT   r   rW   r   _process_chunk   s    	rY   c              
   C   s^   z|  t|||d W n@ tk
rX } z"t||j}|  t||d W 5 d}~X Y nX dS )z.Safely send back the given result or exception)r9   r8   r8   N)putr6   BaseExceptionr'   rC   )result_queuer7   r9   r8   rH   r,   r   r   r   _sendback_result   s    
r^   c              
   C   s   |dk	r<z||  W n& t k
r:   tjjddd Y dS X | jdd}|dkrb|t  dS z|j|j	|j
}W n> t k
r } z t||j}t||j|d W 5 d}~X Y nX t||j|d ~~q<dS )a  Evaluates calls from call_queue and places the results in result_queue.

    This worker is run in a separate process.

    Args:
        call_queue: A ctx.Queue of _CallItems that will be read and
            evaluated by the worker.
        result_queue: A ctx.Queue of _ResultItems that will written
            to by the worker.
        initializer: A callable initializer, or None
        initargs: A tuple of args for the initializer
    NzException in initializer:T)exc_infoblockrZ   )r9   )r\   r   ZLOGGERZcriticalgetr[   osgetpidr2   r3   r4   r'   rC   r^   r7   )
call_queuer]   initializerinitargsZ	call_itemrrH   r,   r   r   r   _process_worker   s$    "ri   c                 C   sv   |  rdS z|jdd}W n tjk
r4   Y dS X | | }|j rh|jt||j|j	|j
dd q | |= q q dS )aM  Fills call_queue with _WorkItems from pending_work_items.

    This function never blocks.

    Args:
        pending_work_items: A dict mapping work ids to _WorkItems e.g.
            {5: <_WorkItem...>, 6: <_WorkItem...>, ...}
        work_ids: A queue.Queue of work ids e.g. Queue([5, 6, ...]). Work ids
            are consumed and the corresponding _WorkItems from
            pending_work_items are transformed into _CallItems and put in
            call_queue.
        call_queue: A multiprocessing.Queue that will be filled with _CallItems
            derived from _WorkItems.
    NFr`   T)Zfullrb   queueZEmptyr1   Zset_running_or_notify_cancelr[   r:   r2   r3   r4   )r=   Zwork_idsre   r7   rJ   r   r   r   _add_call_item_to_queue   s"    
rk   c              
      sJ  dfdd} fdd}|j }	|j }
|	|
g}t||  dd  D }tj|| }d}d}|	|krz|	 }d	}W q tk
r } zt	t
|||j}W 5 d}~X Y qX n|
|krd	}d}|  |rl|  dk	rd
_d_dtd}|dk	r tdd| d|_| D ]\}}|j| ~q(|   D ]}|  qR|  dS t|tr| st|}|  s|  dS nL|dk	r||jd}|dk	r|jr|j|j n|j|j ~~|  | r@z&dk	rd_|s&|  W dS W n tk
r>   Y nX dq2dS )a,  Manages the communication between this process and the worker processes.

    This function is run in a local thread.

    Args:
        executor_reference: A weakref.ref to the ProcessPoolExecutor that owns
            this thread. Used to determine if the ProcessPoolExecutor has been
            garbage collected and that this function can exit.
        process: A list of the ctx.Process instances used as
            workers.
        pending_work_items: A dict mapping work ids to _WorkItems e.g.
            {5: <_WorkItem...>, 6: <_WorkItem...>, ...}
        work_ids_queue: A queue.Queue of work ids e.g. Queue([5, 6, ...]).
        call_queue: A ctx.Queue that will be filled with _CallItems
            derived from _WorkItems for processing by the process workers.
        result_queue: A ctx.SimpleQueue of _ResultItems generated by the
            process workers.
        thread_wakeup: A _ThreadWakeup to allow waking up the
            queue_manager_thread from the main Thread and avoid deadlocks
            caused by permanently locked queues.
    Nc                      s   t p d kp jS r   )r   _shutdown_threadr   )executorr   r   shutting_down@  s    z/_queue_management_worker.<locals>.shutting_downc               	      s   t dd  D } | }d}||k r| dkrt|| D ]6}z d  |d7 }W q: tk
rn   Y  qrY q:X q:t dd  D } q    D ]}|  qd S )Nc                 s   s   | ]}|  V  qd S r   Zis_aliverV   pr   r   r   	<genexpr>F  s     zD_queue_management_worker.<locals>.shutdown_worker.<locals>.<genexpr>r   r!   c                 s   s   | ]}|  V  qd S r   ro   rp   r   r   r   rr   R  s     )sumvaluesrangeZ
put_nowaitr   r   r   )Zn_children_aliveZn_children_to_stopZn_sentinels_sentirq   )re   	processesr   r   shutdown_workerD  s    
z1_queue_management_worker.<locals>.shutdown_workerc                 S   s   g | ]
}|j qS r   )sentinelrp   r   r   r   rX   i  s     z,_queue_management_worker.<locals>.<listcomp>TFzKA child process terminated abruptly, the process pool is not usable anymorez^A process in the process pool was terminated abruptly while the future was running or pending.z
'''
r(   z''') r   rk   rt   r   Z
connectionwaitZrecvr\   r)   r*   r+   rC   r   _brokenrl   BrokenProcessPoolr#   r   r/   r   r1   rF   Z	terminaterB   intAssertionErrorrE   r7   r8   Z
set_resultr9   r   )Zexecutor_referencerw   r=   Zwork_ids_queuere   r]   r   rn   rx   Zresult_readerZwakeup_readerZreadersZworker_sentinelsZreadycauseZ	is_brokenZresult_itemrH   Zbper7   rJ   rq   r   )re   rm   rw   r   _queue_management_worker"  s    	(





r   c               	   C   sj   t rtrttda ztd} W n ttfk
r<   Y d S X | dkrJd S | dkrVd S d|  attd S )NTSC_SEM_NSEMS_MAX   z@system provides too few semaphores (%d available, 256 necessary))_system_limits_checked_system_limitedNotImplementedErrorrc   sysconfAttributeError
ValueError)Z	nsems_maxr   r   r   _check_system_limits  s     r   c                 c   s&   | D ]}|   |r| V  qqdS )z
    Specialized implementation of itertools.chain.from_iterable.
    Each item in *iterable* should be a list.  This function is
    careful not to keep references to yielded objects.
    N)reverserE   )iterableZelementr   r   r   _chain_from_iterable_of_lists  s    r   c                   @   s   e Zd ZdZdS )r|   zy
    Raised when a process in a ProcessPoolExecutor terminated abruptly
    while a future was in the running state.
    N)r   r   r   rK   r   r   r   r   r|     s   r|   c                       st   e Zd ZdddZdd Zdd Zd	d
 Zejjj	e_	ejjj
e_
ddd fdd
ZdddZejjj
e_
  ZS )ProcessPoolExecutorNr   c                 C   s  t   |dkr6t pd| _tjdkrntt| j| _n8|dkrHtdn tjdkrh|tkrhtdt || _|dkr~t	
 }|| _|dk	rt|std|| _|| _d| _i | _d| _t | _d| _d| _i | _| jt }t|| j| jd	| _d
| j_| | _t  | _!t" | _#dS )aS  Initializes a new ProcessPoolExecutor instance.

        Args:
            max_workers: The maximum number of processes that can be used to
                execute the given calls. If None or not given then as many
                worker processes will be created as the machine has processors.
            mp_context: A multiprocessing context to launch the workers. This
                object should provide SimpleQueue, Queue and Process.
            initializer: A callable used to initialize worker processes.
            initargs: A tuple of arguments to pass to the initializer.
        Nr!   Zwin32r   z"max_workers must be greater than 0zmax_workers must be <= zinitializer must be a callableF)r?   r<   r=   T)$r   rc   	cpu_count_max_workerssysplatformmin_MAX_WINDOWS_WORKERSr   r   Zget_context_mp_contextcallable	TypeError_initializer	_initargs_queue_management_thread
_processesrl   	threadingZLock_shutdown_lockr{   _queue_count_pending_work_itemsEXTRA_QUEUED_CALLSr;   _call_queueZ_ignore_epipeZSimpleQueue_result_queuerj   r   	_work_idsr   _queue_management_thread_wakeup)r   Zmax_workersZ
mp_contextrf   rg   Z
queue_sizer   r   r   r     sP    




 

zProcessPoolExecutor.__init__c              	   C   sv   | j d krr| jfdd}|   tjtt| || j| j	| j
| j| j| jfdd| _ d| j _| j   | jt| j < d S )Nc                 S   s   t jd |  d S )Nz?Executor collected: triggering callback for QueueManager wakeup)r   utildebugr   )r   r   r   r   r   
weakref_cbB  s    zFProcessPoolExecutor._start_queue_management_thread.<locals>.weakref_cbZQueueManagerThread)targetr3   nameT)r   r   _adjust_process_countr   ZThreadr   weakrefrefr   r   r   r   r   Zdaemonstartr   )r   r   r   r   r   _start_queue_management_thread=  s(    




z2ProcessPoolExecutor._start_queue_management_threadc                 C   sP   t t| j| jD ]8}| jjt| j| j| j	| j
fd}|  || j|j< qd S )N)r   r3   )ru   lenr   r   r   ZProcessri   r   r   r   r   r   pid)r   r   rq   r   r   r   r   X  s    z)ProcessPoolExecutor._adjust_process_countc               
   O   s
  t | dkr| ^}}} nV| s&tdnHd|krZ|d}| ^}} dd l}|jdtdd ntdt | d  |j |jrt|j|j	rt
d	trt
d
t }t||| |}||j|j< |j|j | jd7  _|j  |  |W  5 Q R  S Q R X d S )N   zEdescriptor 'submit' of 'ProcessPoolExecutor' object needs an argumentr2   r   z.Passing 'fn' as keyword argument is deprecated)
stacklevelz6submit expected at least 1 positional argument, got %dr!   z*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdown)r   r   rE   warningswarnDeprecationWarningr   r{   r|   rl   RuntimeErrorr   r   ZFuturer0   r   r   r   r[   r   r   r   )r3   r4   r   r2   r   fwr   r   r   submitc  s<    

 


zProcessPoolExecutor.submitr!   )timeoutrQ   c                   s:   |dk rt dt jtt|t|d|i|d}t|S )aj  Returns an iterator equivalent to map(fn, iter).

        Args:
            fn: A callable that will take as many arguments as there are
                passed iterables.
            timeout: The maximum number of seconds to wait. If None, then there
                is no limit on the wait time.
            chunksize: If greater than one, the iterables will be chopped into
                chunks of size chunksize and submitted to the process pool.
                If set to one, the items in the list will be sent one at a time.

        Returns:
            An iterator equivalent to: map(func, *iterables) but the calls may
            be evaluated out-of-order.

        Raises:
            TimeoutError: If the entire result iterator could not be generated
                before the given timeout.
            Exception: If fn(*args) raises for any values.
        r!   zchunksize must be >= 1.rQ   )r   )r   r>   mapr   rY   rU   r   )r   r2   r   rQ   rR   Zresultsr@   r   r   r     s    zProcessPoolExecutor.mapTc              	   C   s   | j  d| _W 5 Q R X | jr6| j  |r6| j  d | _| jd k	rd| j  |r^| j  d | _d | _	d | _
| jr| j  d | _d S r   )r   rl   r   r   r   r   r   r   Zjoin_threadr   r   )r   rz   r   r   r   shutdown  s"    





zProcessPoolExecutor.shutdown)NNNr   )T)r   r   r   r   r   r   r   r   Executor__text_signature__rK   r   r   rL   r   r   r@   r   r     s       
K$
r   )NN)3rK   
__author__atexitrc   Zconcurrent.futuresr   rj   r   Zmultiprocessingr   Zmultiprocessing.connectionZmultiprocessing.queuesr   r   r   	functoolsr   rO   r   r)   WeakKeyDictionaryr   r   r   r    r   r   	Exceptionr#   r'   r-   objectr0   r6   r:   r;   rU   rY   r^   ri   rk   r   r   r   r   r   ZBrokenExecutorr|   r   r   registerr   r   r   r   <module>   sV   *		

)& ! P                                                                                                                                                                                  thread.cpython-38.pyc                                                                               0000644                 00000013274 15175327576 0010474 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d@"                     @   s   d Z dZddlZddlmZ ddlZddlZddlZddlZddl	Z	e
 Zdadd Zee G dd	 d	eZd
d ZG dd dejZG dd dejZdS )zImplements ThreadPoolExecutor.z"Brian Quinlan (brian@sweetapp.com)    N)_baseFc                  C   sB   da tt } | D ]\}}|d  q| D ]\}}|  q,d S NT)	_shutdownlist_threads_queuesitemsputjoin)r   tq r   1/usr/lib64/python3.8/concurrent/futures/thread.py_python_exit!   s    r   c                   @   s   e Zd Zdd Zdd ZdS )	_WorkItemc                 C   s   || _ || _|| _|| _d S N)futurefnargskwargs)selfr   r   r   r   r   r   r   __init__.   s    z_WorkItem.__init__c              
   C   sf   | j  sd S z| j| j| j}W n2 tk
rT } z| j | d } W 5 d }~X Y nX | j | d S r   )r   Zset_running_or_notify_cancelr   r   r   BaseExceptionset_exceptionZ
set_result)r   resultexcr   r   r   run4   s    
z_WorkItem.runN)__name__
__module____qualname__r   r   r   r   r   r   r   -   s   r   c                 C   s   |d k	rRz||  W n< t k
rP   tjjddd |  }|d k	rJ|  Y d S X zx|jdd}|d k	r|  ~|  }|d k	r|j  ~qT|  }t	s|d ks|j	r|d k	rd|_	|
d  W d S ~qTW n$ t k
r   tjjddd Y nX d S )NzException in initializer:T)exc_info)blockzException in worker)r   r   ZLOGGERZcritical_initializer_failedgetr   _idle_semaphorereleaser   r   )Zexecutor_referenceZ
work_queueinitializerinitargsZexecutor	work_itemr   r   r   _workerB   s8    

r(   c                   @   s   e Zd ZdZdS )BrokenThreadPoolzR
    Raised when a worker thread in a ThreadPoolExecutor failed initializing.
    N)r   r   r   __doc__r   r   r   r   r)   m   s   r)   c                   @   sf   e Zd Ze jZdddZdd Ze	j
jje_e	j
jje_dd	 Zd
d ZdddZe	j
jje_dS )ThreadPoolExecutorN r   c                 C   s   |dkrt dt pdd }|dkr.td|dk	rFt|sFtd|| _t | _	t
d| _t | _d| _d| _t
 | _|pd	|   | _|| _|| _dS )
a  Initializes a new ThreadPoolExecutor instance.

        Args:
            max_workers: The maximum number of threads that can be used to
                execute the given calls.
            thread_name_prefix: An optional name prefix to give our threads.
            initializer: A callable used to initialize worker threads.
            initargs: A tuple of arguments to pass to the initializer.
        N          r   z"max_workers must be greater than 0zinitializer must be a callableFzThreadPoolExecutor-%d)minos	cpu_count
ValueErrorcallable	TypeError_max_workersqueueZSimpleQueue_work_queue	threadingZ	Semaphorer#   set_threads_brokenr   ZLock_shutdown_lock_counter_thread_name_prefix_initializer	_initargs)r   Zmax_workersZthread_name_prefixr%   r&   r   r   r   r   x   s$    


zThreadPoolExecutor.__init__c               
   O   s   t | dkr| ^}}} nV| s&tdnHd|krZ|d}| ^}} dd l}|jdtdd ntdt | d  |jf |jrt|j|j	rt
d	t	rt
d
t }t||| |}|j| |  |W  5 Q R  S Q R X d S )N   zDdescriptor 'submit' of 'ThreadPoolExecutor' object needs an argumentr   r   z.Passing 'fn' as keyword argument is deprecated)
stacklevelz6submit expected at least 1 positional argument, got %dr.   z*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdown)lenr5   popwarningswarnDeprecationWarningr=   r<   r)   r   RuntimeErrorr   ZFuturer   r8   r   _adjust_thread_count)r   r   r   r   rF   fwr   r   r   submit   s6    

 

zThreadPoolExecutor.submitc                 C   s   | j jddrd S | jfdd}t| j}|| jk rd| jp>| |f }tj|t	t
| || j| j| jfd}d|_|  | j| | jt|< d S )Nr   )Ztimeoutc                 S   s   | d  d S r   )r   )_r   r   r   r   
weakref_cb   s    z;ThreadPoolExecutor._adjust_thread_count.<locals>.weakref_cbz%s_%d)nametargetr   T)r#   acquirer8   rD   r;   r6   r?   r9   ZThreadr(   weakrefrefr@   rA   Zdaemonstartaddr   )r   rO   Znum_threadsZthread_namer
   r   r   r   rJ      s&    



z'ThreadPoolExecutor._adjust_thread_countc              	   C   sb   | j R d| _z| j }W n tjk
r6   Y qTY nX |d k	r|jt| j qW 5 Q R X d S )NzBA thread initializer failed, the thread pool is not usable anymore)	r=   r<   r8   Z
get_nowaitr7   ZEmptyr   r   r)   )r   r'   r   r   r   r!      s    
z&ThreadPoolExecutor._initializer_failedTc              	   C   s@   | j  d| _| jd  W 5 Q R X |r<| jD ]}|  q.d S r   )r=   r   r8   r   r;   r	   )r   waitr
   r   r   r   shutdown   s    
zThreadPoolExecutor.shutdown)Nr,   Nr   )T)r   r   r   	itertoolscount__next__r>   r   rM   r   Executor__text_signature__r*   rJ   r!   rX   r   r   r   r   r+   s   s   
    
& 
r+   )r*   
__author__atexitZconcurrent.futuresr   rY   r7   r9   rS   r1   WeakKeyDictionaryr   r   r   registerobjectr   r(   ZBrokenExecutorr)   r\   r+   r   r   r   r   <module>   s    	
+                                                                                                                                                                                                                                                                                                                                    process.cpython-38.opt-2.pyc                                                                        0000644                 00000032505 15175327576 0011641 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dzn                     @   s  d Z ddlZddlZddlmZ ddlZddlmZ ddlZddl	Zddl
mZ ddlZddlZddlmZ ddlZddlZddlZe ZdaG dd	 d	Zd
d ZdZdZG dd deZG dd dZ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Z"dd Z#dd Z$d0d d!Z%d"d# Z&d$d% Z'd&d' Z(da)da*d(d) Z+d*d+ Z,G d,d- d-ej-Z.G d.d/ d/ej/Z0e1e dS )1z"Brian Quinlan (brian@sweetapp.com)    N)_base)Full)Queue)partialFc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
_ThreadWakeupc                 C   s   t jdd\| _| _d S )NF)Zduplex)mpZPipe_reader_writerself r   2/usr/lib64/python3.8/concurrent/futures/process.py__init__R   s    z_ThreadWakeup.__init__c                 C   s   | j   | j  d S N)r	   closer   r
   r   r   r   r   U   s    
z_ThreadWakeup.closec                 C   s   | j d d S )N    )r	   Z
send_bytesr
   r   r   r   wakeupY   s    z_ThreadWakeup.wakeupc                 C   s   | j  r| j   q d S r   )r   ZpollZ
recv_bytesr
   r   r   r   clear\   s    
z_ThreadWakeup.clearN)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   Q   s   r   c                  C   s@   da tt } | D ]\}}|  q| D ]\}}|  q*d S NT)_global_shutdownlist_threads_wakeupsitemsr   join)r   _thread_wakeuptr   r   r   _python_exita   s    
r       =   c                   @   s   e Zd Zdd Zdd ZdS )_RemoteTracebackc                 C   s
   || _ d S r   tb)r   r%   r   r   r   r   z   s    z_RemoteTraceback.__init__c                 C   s   | j S r   r$   r
   r   r   r   __str__|   s    z_RemoteTraceback.__str__N)r   r   r   r   r&   r   r   r   r   r#   y   s   r#   c                   @   s   e Zd Zdd Zdd ZdS )_ExceptionWithTracebackc                 C   s0   t t|||}d|}|| _d| | _d S )N z

"""
%s""")	tracebackformat_exceptiontyper   excr%   )r   r,   r%   r   r   r   r      s    
z _ExceptionWithTraceback.__init__c                 C   s   t | j| jffS r   )_rebuild_excr,   r%   r
   r   r   r   
__reduce__   s    z"_ExceptionWithTraceback.__reduce__N)r   r   r   r   r.   r   r   r   r   r'      s   r'   c                 C   s   t || _| S r   )r#   	__cause__)r,   r%   r   r   r   r-      s    
r-   c                   @   s   e Zd Zdd ZdS )	_WorkItemc                 C   s   || _ || _|| _|| _d S r   )futurefnargskwargs)r   r1   r2   r3   r4   r   r   r   r      s    z_WorkItem.__init__Nr   r   r   r   r   r   r   r   r0      s   r0   c                   @   s   e Zd ZdddZdS )_ResultItemNc                 C   s   || _ || _|| _d S r   )work_id	exceptionresult)r   r7   r8   r9   r   r   r   r      s    z_ResultItem.__init__)NNr5   r   r   r   r   r6      s   r6   c                   @   s   e Zd Zdd ZdS )	_CallItemc                 C   s   || _ || _|| _|| _d S r   )r7   r2   r3   r4   )r   r7   r2   r3   r4   r   r   r   r      s    z_CallItem.__init__Nr5   r   r   r   r   r:      s   r:   c                       s*   e Zd Zd fdd	Z fddZ  ZS )
_SafeQueuer   c                   s   || _ t j||d d S )N)ctx)pending_work_itemssuperr   )r   max_sizer<   r=   	__class__r   r   r      s    z_SafeQueue.__init__c                    sl   t |trZtt|||j}tdd||_	| j
|jd }|d k	rh|j| nt || d S )Nz

"""
{}"""r(   )
isinstancer:   r)   r*   r+   __traceback__r#   formatr   r/   r=   popr7   r1   set_exceptionr>   _on_queue_feeder_error)r   eobjr%   	work_itemr@   r   r   rG      s    
z!_SafeQueue._on_queue_feeder_error)r   )r   r   r   r   rG   __classcell__r   r   r@   r   r;      s   r;   c                 g   s,   t | }tt|| }|s d S |V  qd S r   )ziptuple	itertoolsislice)	chunksize	iterablesitchunkr   r   r   _get_chunks   s
    rT   c                    s    fdd|D S )Nc                    s   g | ]} | qS r   r   ).0r3   r2   r   r   
<listcomp>   s     z"_process_chunk.<locals>.<listcomp>r   )r2   rS   r   rV   r   _process_chunk   s    	rX   c              
   C   s^   z|  t|||d W n@ tk
rX } z"t||j}|  t||d W 5 d }~X Y nX d S )N)r9   r8   r8   )putr6   BaseExceptionr'   rC   )result_queuer7   r9   r8   rH   r,   r   r   r   _sendback_result   s    
r]   c              
   C   s   |d k	r<z||  W n& t k
r:   tjjddd Y d S X | jdd}|d krb|t  d S z|j|j	|j
}W n> t k
r } z t||j}t||j|d W 5 d }~X Y nX t||j|d ~~q<d S )NzException in initializer:T)exc_infoblockrY   )r9   )r[   r   ZLOGGERZcriticalgetrZ   osgetpidr2   r3   r4   r'   rC   r]   r7   )
call_queuer\   initializerinitargsZ	call_itemrrH   r,   r   r   r   _process_worker   s$    "rh   c                 C   sv   |  rd S z|jdd}W n tjk
r4   Y d S X | | }|j rh|jt||j|j	|j
dd q | |= q q d S )NFr_   T)Zfullra   queueZEmptyr1   Zset_running_or_notify_cancelrZ   r:   r2   r3   r4   )r=   Zwork_idsrd   r7   rJ   r   r   r   _add_call_item_to_queue   s"    
rj   c              
      s>  d fdd} fdd}|j }	|j }
|	|
g}t||  dd  D }tj|| }d }d}|	|krz|	 }d}W q tk
r } zt	t
|||j}W 5 d }~X Y qX n|
|krd}d }|  |rl|  d k	rd	_d_d td
}|d k	r tdd| d|_| D ]\}}|j| ~q(|   D ]}|  qR|  d S t|tr|}|  s|  d S nL|d k	r||jd }|d k	r|jr|j|j n|j|j ~~|  | r4z&d k	rd_|s|  W d S W n tk
r2   Y nX d q2d S )Nc                      s   t p d kp jS r   )r   _shutdown_threadr   )executorr   r   shutting_down@  s    z/_queue_management_worker.<locals>.shutting_downc               	      s   t dd  D } | }d}||k r| dkrt|| D ]6}z d  |d7 }W q: tk
rn   Y  qrY q:X q:t dd  D } q    D ]}|  qd S )Nc                 s   s   | ]}|  V  qd S r   Zis_aliverU   pr   r   r   	<genexpr>F  s     zD_queue_management_worker.<locals>.shutdown_worker.<locals>.<genexpr>r   r!   c                 s   s   | ]}|  V  qd S r   rn   ro   r   r   r   rq   R  s     )sumvaluesrangeZ
put_nowaitr   r   r   )Zn_children_aliveZn_children_to_stopZn_sentinels_sentirp   )rd   	processesr   r   shutdown_workerD  s    
z1_queue_management_worker.<locals>.shutdown_workerc                 S   s   g | ]
}|j qS r   )sentinelro   r   r   r   rW   i  s     z,_queue_management_worker.<locals>.<listcomp>TFzKA child process terminated abruptly, the process pool is not usable anymorez^A process in the process pool was terminated abruptly while the future was running or pending.z
'''
r(   z''')r   rj   rs   r   Z
connectionwaitZrecvr[   r)   r*   r+   rC   r   _brokenrk   BrokenProcessPoolr#   r   r/   r   r1   rF   Z	terminaterB   intrE   r7   r8   Z
set_resultr9   r   )Zexecutor_referencerv   r=   Zwork_ids_queuerd   r\   r   rm   rw   Zresult_readerZwakeup_readerZreadersZworker_sentinelsZreadycauseZ	is_brokenZresult_itemrH   Zbper7   rJ   rp   r   )rd   rl   rv   r   _queue_management_worker"  s    	(





r~   c               	   C   sj   t rtrttda ztd} W n ttfk
r<   Y d S X | dkrJd S | dkrVd S d|  attd S )NTSC_SEM_NSEMS_MAX   z@system provides too few semaphores (%d available, 256 necessary))_system_limits_checked_system_limitedNotImplementedErrorrb   sysconfAttributeError
ValueError)Z	nsems_maxr   r   r   _check_system_limits  s     r   c                 c   s&   | D ]}|   |r| V  qqd S r   )reverserE   )iterableZelementr   r   r   _chain_from_iterable_of_lists  s    r   c                   @   s   e Zd ZdS )r{   N)r   r   r   r   r   r   r   r{     s   r{   c                       st   e Zd ZdddZdd Zdd Zd	d
 Zejjj	e_	ejjj
e_
ddd fdd
ZdddZejjj
e_
  ZS )ProcessPoolExecutorNr   c                 C   s  t   |d kr6t pd| _tjdkrntt| j| _n8|dkrHtdn tjdkrh|tkrhtdt || _|d kr~t	
 }|| _|d k	rt|std|| _|| _d | _i | _d| _t | _d| _d| _i | _| jt }t|| j| jd| _d	| j_| | _t  | _!t" | _#d S )
Nr!   Zwin32r   z"max_workers must be greater than 0zmax_workers must be <= zinitializer must be a callableF)r?   r<   r=   T)$r   rb   	cpu_count_max_workerssysplatformmin_MAX_WINDOWS_WORKERSr   r   Zget_context_mp_contextcallable	TypeError_initializer	_initargs_queue_management_thread
_processesrk   	threadingZLock_shutdown_lockrz   _queue_count_pending_work_itemsEXTRA_QUEUED_CALLSr;   _call_queueZ_ignore_epipeZSimpleQueue_result_queueri   r   	_work_idsr   _queue_management_thread_wakeup)r   Zmax_workersZ
mp_contextre   rf   Z
queue_sizer   r   r   r     sP    




 

zProcessPoolExecutor.__init__c              	   C   sv   | j d krr| jfdd}|   tjtt| || j| j	| j
| j| j| jfdd| _ d| j _| j   | jt| j < d S )Nc                 S   s   t jd |  d S )Nz?Executor collected: triggering callback for QueueManager wakeup)r   utildebugr   )r   r   r   r   r   
weakref_cbB  s    zFProcessPoolExecutor._start_queue_management_thread.<locals>.weakref_cbZQueueManagerThread)targetr3   nameT)r   r   _adjust_process_countr   ZThreadr~   weakrefrefr   r   r   r   r   Zdaemonstartr   )r   r   r   r   r   _start_queue_management_thread=  s(    




z2ProcessPoolExecutor._start_queue_management_threadc                 C   sP   t t| j| jD ]8}| jjt| j| j| j	| j
fd}|  || j|j< qd S )N)r   r3   )rt   lenr   r   r   ZProcessrh   r   r   r   r   r   pid)r   r   rp   r   r   r   r   X  s    z)ProcessPoolExecutor._adjust_process_countc               
   O   s
  t | dkr| ^}}} nV| s&tdnHd|krZ|d}| ^}} dd l}|jdtdd ntdt | d  |j |jrt|j|j	rt
d	trt
d
t }t||| |}||j|j< |j|j | jd7  _|j  |  |W  5 Q R  S Q R X d S )N   zEdescriptor 'submit' of 'ProcessPoolExecutor' object needs an argumentr2   r   z.Passing 'fn' as keyword argument is deprecated)
stacklevelz6submit expected at least 1 positional argument, got %dr!   z*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdown)r   r   rE   warningswarnDeprecationWarningr   rz   r{   rk   RuntimeErrorr   r   ZFuturer0   r   r   r   rZ   r   r   r   )r3   r4   r   r2   r   fwr   r   r   submitc  s<    

 


zProcessPoolExecutor.submitr!   )timeoutrP   c                   s:   |dk rt dt jtt|t|d|i|d}t|S )Nr!   zchunksize must be >= 1.rP   )r   )r   r>   mapr   rX   rT   r   )r   r2   r   rP   rQ   Zresultsr@   r   r   r     s    zProcessPoolExecutor.mapTc              	   C   s   | j  d| _W 5 Q R X | jr6| j  |r6| j  d | _| jd k	rd| j  |r^| j  d | _d | _	d | _
| jr| j  d | _d S r   )r   rk   r   r   r   r   r   r   Zjoin_threadr   r   )r   ry   r   r   r   shutdown  s"    





zProcessPoolExecutor.shutdown)NNNr   )T)r   r   r   r   r   r   r   r   Executor__text_signature____doc__r   r   rK   r   r   r@   r   r     s       
K$
r   )NN)2
__author__atexitrb   Zconcurrent.futuresr   ri   r   Zmultiprocessingr   Zmultiprocessing.connectionZmultiprocessing.queuesr   r   r   	functoolsr   rN   r   r)   WeakKeyDictionaryr   r   r   r    r   r   	Exceptionr#   r'   r-   objectr0   r6   r:   r;   rT   rX   r]   rh   rj   r~   r   r   r   r   ZBrokenExecutorr{   r   r   registerr   r   r   r   <module>.   sT   		

)& ! P                                                                                                                                                                                           __init__.cpython-38.opt-1.pyc                                                                       0000644                 00000006070 15175327576 0011717 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   s   d Z ddddddddd	d
ddddddddddgZedddg dZddlmZ ddlmZ ddlm	Z	m
Z
mZmZmZmZmZmZ ddlmZmZ ddlmZmZmZmZmZ ddlmZmZ dd lmZmZ dd!lm Z m!Z!m"Z"m#Z# eZ$d"d# Z%d$S )%a  
Python unit testing framework, based on Erich Gamma's JUnit and Kent Beck's
Smalltalk testing framework (used with permission).

This module contains the core framework classes that form the basis of
specific test cases and suites (TestCase, TestSuite etc.), and also a
text-based utility class for running the tests and reporting the results
 (TextTestRunner).

Simple usage:

    import unittest

    class IntegerArithmeticTestCase(unittest.TestCase):
        def testAdd(self):  # test method names begin with 'test'
            self.assertEqual((1 + 2), 3)
            self.assertEqual(0 + 1, 1)
        def testMultiply(self):
            self.assertEqual((0 * 10), 0)
            self.assertEqual((5 * 8), 40)

    if __name__ == '__main__':
        unittest.main()

Further information is available in the bundled documentation, and from

  http://docs.python.org/library/unittest.html

Copyright (c) 1999-2003 Steve Purcell
Copyright (c) 2003-2010 Python Software Foundation
This module is free software, and you may redistribute it and/or modify
it under the same terms as Python itself, so long as this copyright message
and disclaimer are retained in their original form.

IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

TestResultTestCaseIsolatedAsyncioTestCase	TestSuiteTextTestRunner
TestLoaderFunctionTestCasemaindefaultTestLoaderSkipTestskipskipIf
skipUnlessexpectedFailureTextTestResultinstallHandlerregisterResultremoveResultremoveHandleraddModuleCleanupgetTestCaseNames	makeSuitefindTestCasesT   )r   )r   )r   r   r   r
   r   r   r   r   )BaseTestSuiter   )r   r	   r   r   r   )TestProgramr   )r   r   )r   r   r   r   c                 C   s"   dd l }|jt}| j||dS )N    )Z	start_dirpattern)Zos.pathpathdirname__file__Zdiscover)loaderZtestsr   osZthis_dir r"   )/usr/lib64/python3.8/unittest/__init__.py
load_testsL   s    r$   N)&__doc____all__extendZ
__unittestresultr   Z
async_caser   Zcaser   r   r   r
   r   r   r   r   Zsuiter   r   r    r   r	   r   r   r   r   r   Zrunnerr   r   Zsignalsr   r   r   r   Z_TextTestResultr$   r"   r"   r"   r#   <module>   s<   .           (                                                                                                                                                                                                                                                                                                                                                                                                                                                                        signals.cpython-38.pyc                                                                              0000644                 00000004256 15175327600 0010651 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dc	                     @   sb   d dl Z d dlZd dlmZ dZG dd deZe Zdd Z	dd	 Z
dad
d ZdddZdS )    N)wrapsTc                   @   s   e Zd Zdd Zdd ZdS )_InterruptHandlerc                 C   sN   d| _ || _t|trD|tjkr(tj}n|tjkr<dd }ntd|| _	d S )NFc                 S   s   d S N )Zunused_signumZunused_framer   r   (/usr/lib64/python3.8/unittest/signals.pydefault_handler   s    z3_InterruptHandler.__init__.<locals>.default_handlerzYexpected SIGINT signal handler to be signal.SIG_IGN, signal.SIG_DFL, or a callable object)
calledoriginal_handler
isinstanceintsignalSIG_DFLdefault_int_handlerSIG_IGN	TypeErrorr   )selfr   r   r   r   __init__
   s    



z_InterruptHandler.__init__c                 C   sR   t t j}|| k	r | || | jr2| || d| _t D ]}|  q@d S )NT)r   	getsignalSIGINTr   r   _resultskeysstop)r   ZsignumframeZinstalled_handlerresultr   r   r   __call__   s    z_InterruptHandler.__call__N)__name__
__module____qualname__r   r   r   r   r   r   r   	   s   r   c                 C   s   dt | < d S )N   )r   r   r   r   r   registerResult*   s    r    c                 C   s   t t| d S r   )boolr   popr   r   r   r   removeResult-   s    r#   c                  C   s.   t d kr*ttj} t| a ttjt  d S r   )_interrupt_handlerr   r   r   r   )r   r   r   r   installHandler1   s    r%   c                    s<    d k	r t   fdd}|S td k	r8ttjtj d S )Nc               
      s6   t t j}t  z | |W S t  t j| X d S r   )r   r   r   removeHandler)argskwargsinitialmethodr   r   inner;   s
    zremoveHandler.<locals>.inner)r   r$   r   r   r	   )r+   r,   r   r*   r   r&   9   s    r&   )N)r   weakref	functoolsr   Z
__unittestobjectr   WeakKeyDictionaryr   r    r#   r$   r%   r&   r   r   r   r   <module>   s                                                                                                                                                                                                                                                                                                                                                      main.cpython-38.opt-2.pyc                                                                           0000644                 00000016276 15175327600 0011102 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d+                     @   sp   d dl Z d dlZd dlZddlmZmZ ddlmZ dZdZ	dZ
dd	 Zd
d Zdd ZG dd deZeZdS )    N   )loaderrunner)installHandlerTa  Examples:
  %(prog)s test_module               - run tests from test_module
  %(prog)s module.TestClass          - run tests from module.TestClass
  %(prog)s module.Class.test_method  - run specified test method
  %(prog)s path/to/test_file.py      - run tests from test_file.py
aF  Examples:
  %(prog)s                           - run default set of tests
  %(prog)s MyTestSuite               - run suite 'MyTestSuite'
  %(prog)s MyTestCase.testSomething  - run MyTestCase.testSomething
  %(prog)s MyTestCase                - run all 'test*' test methods
                                       in MyTestCase
c                 C   sx   t j| rt|  drtt j| rXt j| t  }t j|sP|t j	rT| S |} | d d 
dd
ddS | S )Nz.py\./)ospathisfilelowerendswithisabsrelpathgetcwd
startswithpardirreplace)nameZrel_path r   %/usr/lib64/python3.8/unittest/main.py_convert_name   s    r   c                 C   s   dd | D S )Nc                 S   s   g | ]}t |qS r   )r   ).0r   r   r   r   
<listcomp>.   s     z"_convert_names.<locals>.<listcomp>r   )namesr   r   r   _convert_names-   s    r   c                 C   s   d| krd|  } | S )N*z*%s*r   )patternr   r   r   _convert_select_pattern1   s    r   c                   @   s   e Zd ZdZdZd Z Z Z Z Z	Z
dZddddejddddddfddddZdd	d
Zdd Zdd ZdddZdd Zdd Zdd Zdd ZdddZdd ZdS ) TestProgramNr   __main__TF)	tb_localsc                C   s   t |tr<t|| _|ddd  D ]}t| j|| _q&n|| _|d krPtj}|| _|| _	|	| _
|| _|
| _|| _|d krtjsd| _n|| _|| _|| _|| _tj|d | _| | |   d S )Nr   r   defaultr   )
isinstancestr
__import__modulesplitgetattrsysargvexitfailfast
catchbreak	verbositybufferr"   warnoptionswarningsdefaultTest
testRunner
testLoaderr
   r   basenameprogName	parseArgsrunTests)selfr'   r3   r+   r4   r5   r,   r/   r-   r.   r0   r2   r"   partr   r   r   __init__A   s,    


zTestProgram.__init__c                 C   s4   |rt | | jd kr|   |   td d S )N   )print_discovery_parser_initArgParsers_print_helpr*   r,   )r:   msgr   r   r   	usageExitg   s    
zTestProgram.usageExitc                 O   sZ   | j d kr6t| j  ttd| ji  | j  n t| j  ttd| ji  d S )Nprog)	r'   r>   _main_parserZformat_helpMAIN_EXAMPLESr7   r?   
print_helpMODULE_EXAMPLES)r:   argskwargsr   r   r   rA   o   s    
zTestProgram._print_helpc                 C   s   |    | jd krpt|dkrD|d  dkrD| |dd   d S | j|dd  |  | js| g  d S n| j|dd  |  | jrt| j| _	t
dkrd | _n6| jd krd | _	n$t| jtr| jf| _	nt| j| _	|   d S )Nr   discoverr=   r!   )r@   r'   lenr   _do_discoveryrE   
parse_argstestsr   	testNames__name__r3   r$   r%   listcreateTests)r:   r+   r   r   r   r8   x   s(    


zTestProgram.parseArgsc                 C   st   | j r| j | j_ |r@|d kr"| jn| }|| j| j| j| _n0| jd kr\| j| j	| _n| j
| j| j	| _d S N)testNamePatternsr5   rK   startr   toptestrP   ZloadTestsFromModuler'   ZloadTestsFromNames)r:   from_discoveryLoaderr   r   r   r   rS      s    


zTestProgram.createTestsc                 C   s$   |   }| || _| || _d S rT   )_getParentArgParser_getMainArgParserrE   _getDiscoveryArgParserr?   )r:   Zparent_parserr   r   r   r@      s    zTestProgram._initArgParsersc                 C   s   t jdd}|jddddddd	 |jd
dddddd	 |jddddd | jd krn|jdddddd d| _| jd kr|jdddddd d| _| jd kr|jdddddd d| _| jd kr|jdd d!td"d# g | _|S )$NF)Zadd_helpz-vz	--verboser/   Zstore_constr=   zVerbose output)destactionZconsthelpz-qz--quietr   zQuiet outputz--localsr"   
store_truez"Show local variables in tracebacks)r^   r_   r`   z-fz
--failfastr-   zStop on first fail or errorz-cz--catchr.   z'Catch Ctrl-C and display results so farz-bz--bufferr0   z%Buffer stdout and stderr during testsz-krU   appendz.Only run tests which match the given substring)r^   r_   typer`   )argparseArgumentParseradd_argumentr-   r.   r0   rU   r   )r:   parserr   r   r   r[      sR    
 
 






 zTestProgram._getParentArgParserc                 C   s2   t j|gd}| j|_| j|_|jdddd |S )NparentsrO   r   z?a list of any number of test modules, classes and test methods.)nargsr`   )rd   re   r7   rD   rA   rG   rf   )r:   parentrg   r   r   r   r\      s    zTestProgram._getMainArgParserc                 C   sz   t j|gd}d| j |_d|_|jddddd |jd	d
ddd |jddddd dD ]}|j|dt jt jd qZ|S )Nrh   z%s discoverzcFor test discovery all test modules must be importable from the top level directory of the project.z-sz--start-directoryrV   z*Directory to start discovery ('.' default))r^   r`   z-pz	--patternr   z+Pattern to match tests ('test*.py' default)z-tz--top-level-directoryrW   z<Top level directory of project (defaults to start directory))rV   r   rW   ?)rj   r#   r`   )rd   re   r7   rD   Zepilogrf   ZSUPPRESS)r:   rk   rg   argr   r   r   r]      s$    


z"TestProgram._getDiscoveryArgParserc                 C   sL   d| _ d| _d | _|d k	r:| jd kr,|   | j||  | jd|d d S )Nr   ztest*.pyT)rY   rZ   )rV   r   rW   r?   r@   rN   rS   )r:   r+   rZ   r   r   r   rM      s    
zTestProgram._do_discoveryc              	   C   s   | j rt  | jd krtj| _t| jtrzVz"| j| j| j| j	| j
| jd}W n. tk
r|   | j| j| j| j	| j
d}Y nX W q tk
r   |  }Y qX n| j}|| j| _| jrt| j   d S )N)r/   r-   r0   r2   r"   )r/   r-   r0   r2   )r.   r   r4   r   ZTextTestRunnerr$   rc   r/   r-   r0   r2   r"   	TypeErrorrunrX   resultr,   r*   ZwasSuccessful)r:   r4   r   r   r   r9      s2    

zTestProgram.runTests)N)FN)N)rQ   
__module____qualname__r'   r/   r-   r.   r0   r7   r2   rU   r?   r   ZdefaultTestLoaderr<   rC   rA   r8   rS   r@   r[   r\   r]   rM   r9   r   r   r   r   r    7   s4        &
	
#
r    )r*   rd   r
    r   r   Zsignalsr   Z
__unittestrF   rH   r   r   r   objectr    mainr   r   r   r   <module>   s   	 ]                                                                                                                                                                                                                                                                                                                                  __main__.cpython-38.pyc                                                                             0000644                 00000000621 15175327600 0010721 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   s`   d Z ddlZejd drBddlZejejZed ejd< [dZ	ddl
m
Z
 e
dd dS )	zMain entry point    Nz__main__.pyz -m unittestT   )main)module)__doc__sysargvendswithZos.pathospathbasename
executableZ
__unittestr    r   r   )/usr/lib64/python3.8/unittest/__main__.py<module>   s                                                                                                                  loader.cpython-38.opt-2.pyc                                                                         0000644                 00000026742 15175327600 0011423 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dX                     @   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mZmZ ddl	m
Z
mZmZ dZedejZG dd de
jZd	d
 Zdd Zdd Zdd Zdd ZG dd deZe ZdddZejdfddZdejejfddZdejejfddZ dS )    N)fnmatchfnmatchcase   )casesuiteutilTz[_a-z]\w*\.py$c                       s,   e Zd ZdZ fddZ fddZ  ZS )_FailedTestNc                    s   || _ tt| | d S N)
_exceptionsuperr   __init__)selfZmethod_name	exception	__class__ '/usr/lib64/python3.8/unittest/loader.pyr      s    z_FailedTest.__init__c                    s*   | j krtt |S  fdd}|S )Nc                      s
    j d S r	   )r
   r   r   r   r   testFailure!   s    z,_FailedTest.__getattr__.<locals>.testFailure)_testMethodNamer   r   __getattr__)r   namer   r   r   r   r      s    
z_FailedTest.__getattr__)__name__
__module____qualname__r   r   r   __classcell__r   r   r   r   r      s   r   c                 C   s"   d| t  f }t| t|||S )Nz#Failed to import test module: %s
%s)	traceback
format_exc_make_failed_testImportError)r   
suiteClassmessager   r   r   _make_failed_import_test&   s
     r"   c                 C   s   dt  f }t| |||S )NzFailed to call load_tests:
%s)r   r   r   )r   r   r    r!   r   r   r   _make_failed_load_tests+   s       r#   c                 C   s   t | |}||f|fS r	   )r   )
methodnamer   r    r!   testr   r   r   r   0   s    
r   c                 C   s<   t t|dd }| |i}tdt jf|}||| fS )Nc                 S   s   d S r	   r   r   r   r   r   testSkipped5   s    z'_make_skipped_test.<locals>.testSkippedZModuleSkipped)r   skipstrtypeTestCase)r$   r   r    r&   attrsZ	TestClassr   r   r   _make_skipped_test4   s
    
r,   c                 C   s*   |   dr| d d S tj| d S )Nz	$py.classir   )lowerendswithospathsplitext)r0   r   r   r   _jython_aware_splitext<   s    r2   c                       s   e Zd ZdZeejZdZe	j
ZdZ fddZdd Zdddd	Zd d
dZd!ddZdd Zd"ddZdd Zdd Zdd Zdd Zd#ddZd$ddZ  ZS )%
TestLoaderr%   Nc                    s    t t|   g | _t | _d S r	   )r   r3   r   errorsset_loading_packagesr   r   r   r   r   M   s    zTestLoader.__init__c                 C   sF   t |tjrtd| |}|s2t|dr2dg}| t||}|S )NzYTest cases should not be derived from TestSuite. Maybe you meant to derive from TestCase?ZrunTest)
issubclassr   	TestSuite	TypeErrorgetTestCaseNameshasattrr    map)r   testCaseClassZtestCaseNamesZloaded_suiter   r   r   loadTestsFromTestCaseT   s    
z TestLoader.loadTestsFromTestCasepatternc             
   O   s:  t |dksd|kr,tdt |dd  t |dkrRt |d }td|t |dkrxt|d }td|g }t|D ]4}t	||}t
|trt|tjr|| | qt	|dd }	| |}|	d k	r6z|	| ||W S  tk
r4 }
 z,t|j|
| j\}}| j| | W Y S d }
~
X Y nX |S )Nr   Zuse_load_testsz(use_load_tests is deprecated and ignoredr   zCloadTestsFromModule() takes 1 positional argument but {} were givenz=loadTestsFromModule() got an unexpected keyword argument '{}'
load_tests)lenwarningswarnDeprecationWarningpopr9   formatsorteddirgetattr
isinstancer)   r7   r   r*   appendr>   r    	Exceptionr#   r   r4   )r   moduler@   argsZkwsZ	complainttestsr   objrA   e
error_caseerror_messager   r   r   loadTestsFromModuleb   s<    


  zTestLoader.loadTestsFromModulec                 C   sX  | d}d\}}|d kr|d d  }|rzd|}t|}W qW q& tk
r   | }t|| j\}}|s| j| | Y S Y q&X q&|dd  }|}	|D ]}
z|	t	|	|
 }}	W q t
k
rN } zvt	|	dd d k	r|d k	r| j| | W Y D  S t|
|| jdt f \}}| j| | W Y 
  S W 5 d }~X Y qX qt|	tjrj| |	S t|	trt|	tjr| |	S t|	tjrt|trt|tjr|d }||}tt	||tjs| |gS nt|	tjr|	S t|	rH|	 }t|tjr|S t|tjr6| |gS td|	|f ntd|	 d S )	N.)NNr   __path__zFailed to access attribute:
%sz"calling %s returned %s, not a testz$don't know how to make test from: %s)splitjoin
__import__r   rF   r"   r    r4   rL   rJ   AttributeErrorr   r   r   rK   types
ModuleTyperU   r)   r7   r   r*   r>   FunctionTyper   r8   callabler9   )r   r   rN   partsrS   rT   Z
parts_copymodule_nameZnext_attributerQ   partparentrR   instr%   r   r   r   loadTestsFromName   s    	

   $



zTestLoader.loadTestsFromNamec                    s    fdd|D } |S )Nc                    s   g | ]} | qS r   )rf   ).0r   rN   r   r   r   
<listcomp>   s     z1TestLoader.loadTestsFromNames.<locals>.<listcomp>)r    )r   namesrN   Zsuitesr   rh   r   loadTestsFromNames   s    zTestLoader.loadTestsFromNamesc                    s>    fdd}t t|t} jr:|jt jd |S )Nc                    sZ   |  jsdS t| }t|s&dS djj| f  jd kpXt fddjD S )NFz%s.%s.%sc                 3   s   | ]}t  |V  qd S r	   )r   )rg   r@   ZfullNamer   r   	<genexpr>   s     zKTestLoader.getTestCaseNames.<locals>.shouldIncludeMethod.<locals>.<genexpr>)
startswithtestMethodPrefixrJ   r`   r   r   testNamePatternsany)attrnameZtestFuncr   r=   rl   r   shouldIncludeMethod   s    
  
z8TestLoader.getTestCaseNames.<locals>.shouldIncludeMethod)key)listfilterrI   sortTestMethodsUsingsort	functools
cmp_to_key)r   r=   rt   ZtestFnNamesr   rs   r   r:      s
    zTestLoader.getTestCaseNamestest*.pyc                 C   sJ  d}|d kr| j d k	r| j }n|d kr.d}|}tj|}|tjkrRtjd| || _ d}d}g }tjtj|rtj|}||krtjtj|d }npzt	| W n t
k
r   d}Y nJX tj| }|dd }	ztjtj|j}W n tk
r   z
|j}
W n tk
r8   d }
Y nX |
r|
jd kr|
jd k	rd}|jD ]P}|s|||s|qb||jdtjjd | _ || j||dd qbn*|jtjkrtdd ntd|d Y nX |r|s| |	| _ tj| ntj| |r*t
d	| |s@t| ||}|  |S )
NFTr   __init__.pyrV   )	namespacez2Can not use builtin modules as dotted module namesz$don't know how to discover from {!r}z%Start directory is not importable: %r)!_top_level_dirr/   r0   abspathsysinsertisdirisfilerZ   r[   r   modulesrY   dirname__file__r\   __spec__loadersubmodule_search_locationsrW   rn   r   replacesepextend_find_testsbuiltin_module_namesr9   rG    _get_directory_containing_moduleremoverv   r    )r   	start_dirr@   Ztop_level_dirZset_implicit_topZis_not_importableis_namespacerP   Z
the_moduleZtop_partspecr0   r   r   r   discover   s    





 
zTestLoader.discoverc                 C   sR   t j| }tj|j}tj| drBtj	tj	|S tj	|S d S )Nr}   )
r   r   r/   r0   r   r   basenamer-   rn   r   )r   rb   rN   	full_pathr   r   r   r   `  s
    
z+TestLoader._get_directory_containing_modulec                 C   sB   || j krdS ttj|}tj|| j }|tjjd}|S NrV   )r   r2   r/   r0   normpathrelpathr   r   )r   r0   Z_relpathr   r   r   r   _get_name_from_pathl  s    
zTestLoader._get_name_from_pathc                 C   s   t | tj| S r	   )r[   r   r   )r   r   r   r   r   _get_module_from_namex  s    z TestLoader._get_module_from_namec                 C   s
   t ||S r	   )r   )r   r0   r   r@   r   r   r   _match_path|  s    zTestLoader._match_pathFc           
   
   c   s   |  |}|dkrD|| jkrD| |||\}}|d k	r<|V  |sDd S tt|}|D ]t}tj||}	| |	||\}}|d k	r|V  |rV|  |	}| j| z| 
|	||E d H  W 5 | j	| X qVd S r   )r   r6   _find_test_pathrH   r/   listdirr0   rZ   adddiscardr   )
r   r   r@   r~   r   rP   Zshould_recursepathsr0   r   r   r   r   r     s6    
    
zTestLoader._find_testsc              
   C   st  t j|}t j|rVt|s(dS | |||s:dS | |}z| |}W nh t	j
k
r } zt||| jdf W Y S d }~X Y n   t|| j\}}	| j|	 |df Y S X t jt|d|}
tt j|
}tt j|}| | kr@t j|}tt j|}t j|}d}t||||f | j||ddfS nt j|rl|st jt j|dsdS d }d }| |}z| |}W nj t	j
k
r } zt||| jdf W Y S d }~X Y n   t|| j\}}	| j|	 |df Y S X t|dd }| j| z0| j||d}|d k	rP|dfW S |dfW S | j| X ndS d S )	N)NFFr   zW%r module incorrectly imported from %r. Expected %r. Is this module globally installed?r?   r}   rA   T)r/   r0   r   r   VALID_MODULE_NAMEmatchr   r   r   r   ZSkipTestr,   r    r"   r4   rL   r   rJ   r2   realpathr-   r   r   rU   r   rZ   r6   r   r   )r   r   r@   r~   r   r   rN   rR   rS   rT   Zmod_filer   Zfullpath_noextZ
module_dirZmod_nameZexpected_dirmsgrA   rP   packager   r   r   r     s|    

&





&

zTestLoader._find_test_path)N)N)r|   N)F)F)r   r   r   ro   staticmethodr   three_way_cmprx   rp   r   r8   r    r   r   r>   rU   rf   rk   r:   r   r   r   r   r   r   r   r   r   r   r   r   r3   B   s$   
(
N

n
"r3   c                 C   s&   t  }||_| |_||_|r"||_|S r	   )r3   rx   ro   rp   r    )prefix	sortUsingr    rp   r   r   r   r   _makeLoader  s    r   c                 C   s   t |||d| S )N)rp   )r   r:   )r=   r   r   rp   r   r   r   r:     s    r:   r%   c                 C   s   t |||| S r	   )r   r>   )r=   r   r   r    r   r   r   	makeSuite  s    r   c                 C   s   t |||| S r	   )r   rU   )rN   r   r   r    r   r   r   findTestCases  s    r   )NN)!r/   rer   r   r]   rz   rC   r   r    r   r   r   Z
__unittestcompile
IGNORECASEr   r*   r   r"   r#   r   r,   r2   objectr3   ZdefaultTestLoaderr   r   r:   r8   r   r   r   r   r   r   <module>   s:      /
	
                              result.cpython-38.pyc                                                                               0000644                 00000016175 15175327600 0010532 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   s\   d Z ddlZddlZddlZddlmZ ddlmZ dZdd Z	d	Z
d
ZG dd deZdS )zTest result object    N   )utilwrapsTc                    s   t   fdd}|S )Nc                    s$   t | ddr|    | f||S )NfailfastF)getattrstop)selfargskwmethod '/usr/lib64/python3.8/unittest/result.pyinner   s    zfailfast.<locals>.innerr   )r   r   r   r   r   r      s    r   z
Stdout:
%sz
Stderr:
%sc                   @   s   e Zd ZdZdZdZdZd.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dd Zedd Zdd Zdd Zdd Z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S )/
TestResulta  Holder for test result information.

    Test results are automatically managed by the TestCase and TestSuite
    classes, and do not need to be explicitly manipulated by writers of tests.

    Each instance holds the total number of tests run, and collections of
    failures and errors that occurred among those test runs. The collections
    contain tuples of (testcase, exceptioninfo), where exceptioninfo is the
    formatted traceback of the error that occurred.
    NFc                 C   sb   d| _ g | _g | _d| _g | _g | _g | _d| _d| _d| _	d | _
d | _tj| _tj| _d| _d S )NFr   )r   failureserrorstestsRunskippedexpectedFailuresunexpectedSuccesses
shouldStopbuffer	tb_locals_stdout_buffer_stderr_buffersysstdout_original_stdoutstderr_original_stderr_mirrorOutput)r	   streamZdescriptions	verbosityr   r   r   __init__&   s    zTestResult.__init__c                 C   s   dS )z#Called by TestRunner after test runNr   r	   r   r   r   printErrors7   s    zTestResult.printErrorsc                 C   s    |  j d7  _ d| _|   dS )z-Called when the given test is about to be runr   FN)r   r"   _setupStdoutr	   testr   r   r   	startTest:   s    zTestResult.startTestc                 C   s8   | j r4| jd kr$t | _t | _| jt_| jt_d S )N)r   r   ioStringIOr   r   r   r    r&   r   r   r   r(   @   s    


zTestResult._setupStdoutc                 C   s   dS )zpCalled once before any tests are executed.

        See startTest for a method called before each test.
        Nr   r&   r   r   r   startTestRunH   s    zTestResult.startTestRunc                 C   s   |    d| _dS )z'Called when the given test has been runFN)_restoreStdoutr"   r)   r   r   r   stopTestN   s    zTestResult.stopTestc                 C   s   | j r| jrltj }tj }|rF|ds6|d7 }| jt	|  |rl|ds\|d7 }| j
t|  | jt_| j
t_| jd | j  | jd | j  d S )N
r   )r   r"   r   r   getvaluer    endswithr   writeSTDOUT_LINEr!   STDERR_LINEr   seektruncater   )r	   outputerrorr   r   r   r/   S   s$    




zTestResult._restoreStdoutc                 C   s   dS )zmCalled once after all tests are executed.

        See stopTest for a method called after each test.
        Nr   r&   r   r   r   stopTestRunh   s    zTestResult.stopTestRunc                 C   s"   | j || ||f d| _dS )zmCalled when an error has occurred. 'err' is a tuple of values as
        returned by sys.exc_info().
        TN)r   append_exc_info_to_stringr"   r	   r*   errr   r   r   addErrorn   s    zTestResult.addErrorc                 C   s"   | j || ||f d| _dS )zdCalled when an error has occurred. 'err' is a tuple of values as
        returned by sys.exc_info().TN)r   r<   r=   r"   r>   r   r   r   
addFailurev   s    zTestResult.addFailurec                 C   sZ   |dk	rVt | ddr|   t|d |jr4| j}n| j}||| ||f d| _dS )zCalled at the end of a subtest.
        'err' is None if the subtest ended successfully, otherwise it's a
        tuple of values as returned by sys.exc_info().
        Nr   Fr   T)	r   r   
issubclassfailureExceptionr   r   r<   r=   r"   )r	   r*   Zsubtestr?   r   r   r   r   
addSubTest}   s    zTestResult.addSubTestc                 C   s   dS )z-Called when a test has completed successfullyNr   r)   r   r   r   
addSuccess   s    zTestResult.addSuccessc                 C   s   | j ||f dS )zCalled when a test is skipped.N)r   r<   )r	   r*   reasonr   r   r   addSkip   s    zTestResult.addSkipc                 C   s   | j || ||f dS )z/Called when an expected failure/error occurred.N)r   r<   r=   r>   r   r   r   addExpectedFailure   s    zTestResult.addExpectedFailurec                 C   s   | j | dS )z5Called when a test was expected to fail, but succeed.N)r   r<   r)   r   r   r   addUnexpectedSuccess   s    zTestResult.addUnexpectedSuccessc                 C   s>   t | jt | j  kodkn  o<t| d p<t | jdkS )z/Tells whether or not this result was a success.r   r   )lenr   r   hasattrr   r&   r   r   r   wasSuccessful   s    $zTestResult.wasSuccessfulc                 C   s
   d| _ dS )z+Indicates that the tests should be aborted.TN)r   r&   r   r   r   r      s    zTestResult.stopc                 C   s   |\}}}|r |  |r |j}q
||jkr6| |}nd}tj||||| jd}t| }| j	rt
j }	t
j }
|	r|	ds|	d7 }	|t|	  |
r|
ds|
d7 }
|t|
  d|S )z>Converts a sys.exc_info()-style tuple of values into a string.N)limitcapture_localsr1    )_is_relevant_tb_leveltb_nextrC   _count_relevant_tb_levels	tracebackTracebackExceptionr   listformatr   r   r   r2   r    r3   r<   r5   r6   join)r	   r?   r*   exctypevaluetblengthZtb_eZmsgLinesr9   r:   r   r   r   r=      s4    

    



zTestResult._exc_info_to_stringc                 C   s   d|j jkS )N
__unittest)tb_frame	f_globals)r	   rZ   r   r   r   rP      s    z TestResult._is_relevant_tb_levelc                 C   s&   d}|r"|  |s"|d7 }|j}q|S )Nr   r   )rP   rQ   )r	   rZ   r[   r   r   r   rR      s
    z$TestResult._count_relevant_tb_levelsc                 C   s&   dt | j| jt| jt| jf S )Nz!<%s run=%i errors=%i failures=%i>)r   Zstrclass	__class__r   rJ   r   r   r&   r   r   r   __repr__   s
    zTestResult.__repr__)NNN)__name__
__module____qualname____doc__Z_previousTestClassZ_testRunEnteredZ_moduleSetUpFailedr%   r'   r+   r(   r.   r0   r/   r;   r   r@   rA   rD   rE   rG   rH   rI   rL   r   r=   rP   rR   r`   r   r   r   r   r      s8   




	r   )rd   r,   r   rS   rO   r   	functoolsr   r\   r   r5   r6   objectr   r   r   r   r   <module>   s                                                                                                                                                                                                                                                                                                                                                                                                      case.cpython-38.opt-1.pyc                                                                           0000644                 00000142400 15175327600 0011055 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   s  d 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
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)e*d(d)d*gZ+G d+d, d,ej,Z-G d-d. d.e&Z.G d/d0 d0ej/Z0G d1d2 d2eZ1G d3d4 d4e1Z2G d5d6 d6e1Z3dS )7zTest case implementation    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ZdS )SkipTestz
    Raise this exception in a test to skip it.

    Usually you can use TestCase.skipTest() or one of the skipping decorators
    instead of raising this directly.
    N__name__
__module____qualname____doc__ r   r   %/usr/lib64/python3.8/unittest/case.pyr	      s   r	   c                   @   s   e Zd ZdZdS )_ShouldStopz
    The test should stop.
    Nr
   r   r   r   r   r   "   s   r   c                   @   s   e Zd ZdZdS )_UnexpectedSuccessz7
    The test was supposed to fail, but it didn't!
    Nr
   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k
r.    Y n tk
rh } zd| _ | j|t|f W 5 d }~X Y nj tk
rz   Y nX   t }| j	r|| _
nd| _ | j||f d }Y nX | jr| j r| j|d f W 5 | j o|| _ X d S )NTF)r   KeyboardInterruptr	   r   appendstrr   sysexc_infor   r   r   r   )r   	test_caseisTestZold_successer"   r   r   r   testPartExecutor7   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   _idU   s    r+   c                O   s   t | ||f dS )znSame as addCleanup, except the cleanup items are called even if
    setUpModule fails (unlike tearDownModule).N)_module_cleanupsr   )functionargskwargsr   r   r   addModuleCleanupZ   s    r0   c               
   C   sd   g } t rTt  \}}}z||| W q tk
rP } z| | W 5 d}~X Y qX q| r`| d dS )zWExecute all module cleanup functions. Normally called for you after
    tearDownModule.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 )z&
    Unconditionally skip a test.
    c                    s4   t | ts$t|  fdd}|} d| _ | _| S )Nc                     s   t  d S r)   r	   r.   r/   reasonr   r   skip_wrapperv   s    z-skip.<locals>.decorator.<locals>.skip_wrapperT)
isinstancetype	functoolswraps__unittest_skip____unittest_skip_why__)	test_itemr:   r8   r   r   	decoratort   s    
zskip.<locals>.decorator )r;   typesFunctionType)r9   rB   rA   r   r8   r   skipp   s    
rF   c                 C   s   | rt |S tS )z/
    Skip a test if the condition is true.
    rF   r+   Z	conditionr9   r   r   r   skipIf   s    rI   c                 C   s   | st |S tS )z3
    Skip a test unless the condition is true.
    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>   s     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   standardMsgrW   r   r   r   _raiseFailure   s    z"_BaseTestCaseContext._raiseFailureN)r   r   r   r   rZ   r   r   r   r   rU      s   rU   c                   @   s   e Zd ZdddZdd ZdS )_AssertRaisesBaseContextNc                 C   s@   t | | || _|| _|d k	r*t|}|| _d | _d | _d S r)   )	rU   r   rT   r#   recompileexpected_regexobj_namerW   )r   rT   r#   r^   r   r   r   r      s    
z!_AssertRaisesBaseContext.__init__c              	   C   s   zt | j| js"td|| jf |sV|dd| _|rNtdtt|f | W TS |^}}z|j	| _
W n tk
r   t|| _
Y nX |  ||| W 5 Q R X W 5 d} X dS )z
        If args is empty, assertRaises/Warns is being used as a
        context manager, so check for a 'msg' kwarg and return self.
        If args is not empty, call a callable passing positional and keyword
        arguments.
        Nz%s() arg 1 must be %srW   z3%r is an invalid keyword argument for this function)rL   rT   
_base_type	TypeError_base_type_strr1   rW   nextiterr   r_   AttributeErrorr    )r   namer.   r/   Zcallable_objr   r   r   handle   s(    z_AssertRaisesBaseContext.handle)N)r   r   r   r   rg   r   r   r   r   r[      s   

r[   c                   @   s(   e Zd ZdZeZdZdd Zdd ZdS )_AssertRaisesContextzCA context manager used to implement TestCase.assertRaises* methods.z-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 krbz| j j}W n tk
r2   t| j }Y nX | jrP| d|| j ql| d| n
t| t	|| j s|dS |
d | _| jd krdS | j}|t|s| d|jt| dS )Nz{} not raised by {}z{} not raisedFT"{}" does not match "{}")rT   r   re   r    r_   rZ   format	tracebackclear_framesrS   with_tracebackZ	exceptionr^   searchpattern)r   exc_type	exc_valuetbexc_namer^   r   r   r   __exit__   s.    


 z_AssertRaisesContext.__exit__N)	r   r   r   r   BaseExceptionr`   rb   rj   rv   r   r   r   r   rh      s
   rh   c                   @   s(   e Zd ZdZeZdZdd Zdd ZdS )_AssertWarnsContextzBA context manager used to implement TestCase.assertWarns* methods.z(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getattrry   warningscatch_warningswarnings_managerrj   simplefilterrT   )r   vr   r   r   rj      s    z_AssertWarnsContext.__enter__c                 C   s   | j ||| |d k	rd S z| jj}W n tk
rF   t| j}Y nX d }| jD ]Z}|j}t|| jsjqR|d krv|}| j	d k	r| j	
t|sqR|| _|j| _|j| _ d S |d k	r| d| j	jt| | jr| d|| j n| d| d S )Nrk   z{} not triggered by {}z{} not triggered)r   rv   rT   r   re   r    r   messager;   r^   rp   ZwarningfilenamelinenorZ   rl   rq   r_   )r   rr   rs   rt   ru   Zfirst_matchingmwr   r   r   rv     s@    

 
z_AssertWarnsContext.__exit__N)	r   r   r   r   Warningr`   rb   rj   rv   r   r   r   r   rx      s
   rx   _LoggingWatcherrecordsoutputc                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_CapturingHandlerzM
    A logging handler capturing all (raw and formatted) logging output.
    c                 C   s   t j|  tg g | _d S r)   )loggingHandlerr   r   watcherri   r   r   r   r   3  s    z_CapturingHandler.__init__c                 C   s   d S r)   r   ri   r   r   r   flush7  s    z_CapturingHandler.flushc                 C   s*   | j j| | |}| j j| d S r)   )r   r   r   rl   r   )r   rz   rW   r   r   r   emit:  s    
z_CapturingHandler.emitN)r   r   r   r   r   r   r   r   r   r   r   r   .  s   r   c                   @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
_AssertLogsContextz:A context manager used to implement TestCase.assertLogs().z"%(levelname)s:%(name)s:%(message)sc                 C   s:   t | | || _|r(tj||| _ntj| _d | _d S r)   )	rU   r   logger_namer   Z_nameToLevelgetlevelINFOrW   )r   r#   r   r   r   r   r   r   F  s    z_AssertLogsContext.__init__c                 C   s   t | jtjr| j }| _nt| j }| _t| j}t }|	| |j
| _
|jd d  | _|j| _|j| _|g|_|| j d|_|j
S )NF)r;   r   r   ZLoggerloggerZ	getLoggerZ	FormatterLOGGING_FORMATr   ZsetFormatterr   handlersold_handlersr   	old_level	propagateold_propagatesetLevel)r   r   Z	formatterZhandlerr   r   r   rj   O  s    
z_AssertLogsContext.__enter__c                 C   s`   | j | j_| j| j_| j| j |d k	r.dS t| jj	dkr\| 
dt| j| jj d S )NFr   z-no logs of level {} or higher triggered on {})r   r   r   r   r   r   r   lenr   r   rZ   rl   r   ZgetLevelNamer   rf   )r   rr   rs   rt   r   r   r   rv   `  s    


 z_AssertLogsContext.__exit__N)r   r   r   r   r   r   rj   rv   r   r   r   r   r   A  s
   	r   c                   @   s   e Zd Zdd ZdS )_OrderedChainMapc                 c   s8   t  }| jD ]&}|D ]}||kr|| |V  qqd S r)   )setmapsadd)r   seenmappingkr   r   r   __iter__n  s    

z_OrderedChainMap.__iter__N)r   r   r   r   r   r   r   r   r   m  s   r   c                   @   s  e Zd ZdZeZdZdZdZdZ	g Z
dddZd	d
 Zdd Zde_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#d0d1 Z$d2d3 Z%d4d5 Z&d6d7 Z'd8d9 Z(dd;d<Z)d=d> Z*ed?d@ Z+dAdB Z,dCdD Z-dEdF Z.ddGdHZ/ddIdJZ0ddKdLZ1dMdN Z2dOdP Z3dQdR Z4ddSdTZ5dUdV Z6ddWdXZ7ddYdZZ8dd[d\Z9dd]d^Z:dd_d`Z;ddadbZ<dcdd Z=ddedfZ>ddgdhZ?ddidjZ@ddkdlZAddmdnZBddodpZCddqdrZDddsdtZEddudvZFddwdxZGddydzZHdd{d|ZIdd}d~ZJdddZKdddZLdddZMdddZNdddZOdddZPdd ZQdd ZRdddZSdddZTdd ZUeUe8 ZVZWeUe9 ZXZYeUe: ZZZ[eUe; Z\Z]eUe1 Z^Z_eUe3Z`eUe0ZaeUeQZbeUeSZceUeTZdd:S )TestCaseaW  A class whose instances are single test cases.

    By default, the test code itself should be placed in a method named
    'runTest'.

    If the fixture may be used for many test cases, create as
    many test methods as are needed. When instantiating such a TestCase
    subclass, specify in the constructor arguments the name of the test method
    that the instance is to execute.

    Test authors should subclass TestCase for their own tests. Construction
    and deconstruction of the test's environment ('fixture') can be
    implemented by overriding the 'setUp' and 'tearDown' methods respectively.

    If it is necessary to override the __init__ method, the base class
    __init__ method must always be called. It is important that subclasses
    should not change the signature of their __init__ method, since instances
    of the classes are instantiated automatically by parts of the framework
    in order to be run.

    When subclassing TestCase, you can set these attributes:
    * failureException: determines which exception will be raised when
        the instance's assertion methods fail; test methods raising this
        exception will be deemed to have 'failed' rather than 'errored'.
    * longMessage: determines whether long messages (including repr of
        objects used in assert methods) will be printed on failure in *addition*
        to any explicit message passed.
    * maxDiff: sets the maximum length of a diff in failure messages
        by assert methods using difflib. It is looked up as an instance
        attribute so can be configured by individual tests if required.
    Ti  i   FrunTestc                 C   s   || _ d| _d| _zt| |}W n. tk
rN   |dkrJtd| j|f Y n
X |j| _g | _d| _	i | _
| td | td | td | td | td | td	 dS )
zCreate an instance of the class that will use the named test
           method when executed. Raises a ValueError if the instance does
           not have a method with the specified name.
        NzNo testr   zno such test method in %s: %sassertDictEqualassertListEqualassertTupleEqualassertSetEqualassertMultiLineEqual)_testMethodName_outcome_testMethodDocr   re   
ValueError	__class__r   	_cleanups_subtest_type_equality_funcsaddTypeEqualityFuncdictr|   rQ   r   	frozensetr    )r   Z
methodName
testMethodr   r   r   r     s(    zTestCase.__init__c                 C   s   || j |< dS )a[  Add a type specific assertEqual style function to compare a type.

        This method is for use by TestCase subclasses that need to register
        their own type equality functions to provide nicer error messages.

        Args:
            typeobj: The data type to call this function on when both values
                    are of the same type in assertEqual().
            function: The callable taking two arguments and an optional
                    msg= argument that raises self.failureException with a
                    useful error message when the two arguments are not equal.
        N)r   )r   Ztypeobjr-   r   r   r   r     s    zTestCase.addTypeEqualityFuncc                  O   s   t | dkr| ^}}} nV| s&tdnHd|krZ|d}| ^}} ddl}|jdtdd ntdt | d	  t| } |j|| |f dS )
a  Add a function, with arguments, to be called when the test is
        completed. Functions added are called on a LIFO basis and are
        called after tearDown on test failure or success.

        Cleanup items are called even if setUp fails (unlike tearDown).   z>descriptor 'addCleanup' of 'TestCase' object needs an argumentr-   r   Nz4Passing 'function' as keyword argument is deprecated)
stacklevelz:addCleanup expected at least 1 positional argument, got %dr   )	r   ra   r1   r   warnDeprecationWarningrQ   r   r   )r.   r/   r   r-   r   r   r   r   
addCleanup  s"    

 
zTestCase.addCleanupz%($self, function, /, *args, **kwargs)c                O   s   | j |||f dS )zpSame as addCleanup, except the cleanup items are called even if
        setUpClass fails (unlike tearDownClass).N)_class_cleanupsr   )clsr-   r.   r/   r   r   r   addClassCleanup  s    zTestCase.addClassCleanupc                 C   s   dS )zAHook method for setting up the test fixture before exercising it.Nr   ri   r   r   r   setUp  s    zTestCase.setUpc                 C   s   dS )zAHook method for deconstructing the test fixture after testing it.Nr   ri   r   r   r   tearDown  s    zTestCase.tearDownc                 C   s   dS )zKHook method for setting up class fixture before running tests in the class.Nr   r   r   r   r   
setUpClass  s    zTestCase.setUpClassc                 C   s   dS )zVHook method for deconstructing the class fixture after running all tests in the class.Nr   r   r   r   r   tearDownClass  s    zTestCase.tearDownClassc                 C   s   dS )Nr   r   ri   r   r   r   countTestCases  s    zTestCase.countTestCasesc                 C   s   t  S r)   )r   Z
TestResultri   r   r   r   defaultTestResult	  s    zTestCase.defaultTestResultc                 C   s$   | j }|r | dd  S dS )zReturns a one-line description of the test, or None if no
        description has been provided.

        The default implementation of this method returns the first line of
        the specified test method's docstring.
        
r   N)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   ri   r   r   r   id  s    zTestCase.idc                 C   s    t | t |k	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   ri   r   r   r   __hash__   s    zTestCase.__hash__c                 C   s   d| j t| jf S Nz%s (%s))r   r   r   ri   r   r   r   __str__#  s    zTestCase.__str__c                 C   s   dt | j| jf S )Nz<%s testMethod=%s>r   ri   r   r   r   __repr__&  s    zTestCase.__repr__c                 C   s<   t |dd }|d k	r ||| ntdtd || d S )NaddSkipz4TestResult has no addSkip method, skips not reportedr   )r   r   r   RuntimeWarning
addSuccess)r   r   r#   r9   r   r   r   r   _addSkip*  s     zTestCase._addSkipc              	   k   s   | j dks| j jsdV  dS | j}|dkr4t|}n|j|}t| ||| _zX| j j| jdd dV  W 5 Q R X | j js| j j	}|dk	r|j
rtn| j jrtW 5 || _X dS )aP  Return a context manager that will return the enclosed block
        of code in a subtest identified by the optional message and
        keyword parameters.  A failure in the subtest marks the test
        case as failed but resumes execution at the end of the enclosed
        block, allowing further test code to be executed.
        NTr$   )r   r   r   r   params	new_child_SubTestr&   r   r   Zfailfastr   r   )r   rW   r   parentZ
params_mapr   r   r   r   subTest3  s$    
zTestCase.subTestc                 C   s`   |D ]V\}}t |tr(||j|| q|d k	rt|d | jrN||| q||| qd S )Nr   )r;   r   r   r#   rS   rX   
addFailureZaddError)r   r   r   testr"   r   r   r   _feedErrorsToResultR  s    
zTestCase._feedErrorsToResultc                 C   sD   z
|j }W n* tk
r4   tdt ||  Y nX || | d S )Nz@TestResult has no addExpectedFailure method, reporting as passes)addExpectedFailurere   r   r   r   r   )r   r   r"   r   r   r   r   _addExpectedFailure\  s    
zTestCase._addExpectedFailurec                 C   sh   z
|j }W nP tk
rZ   tdt z
td W n$ tk
rT   || t  Y nX Y n
X ||  d S )NzCTestResult has no addUnexpectedSuccess method, reporting as failure)	addUnexpectedSuccessre   r   r   r   r   r   r!   r"   )r   r   r   r   r   r   _addUnexpectedSuccessf  s    

zTestCase._addUnexpectedSuccessc                 C   s   |    d S r)   )r   ri   r   r   r   
_callSetUpu  s    zTestCase._callSetUpc                 C   s
   |  d S r)   r   )r   methodr   r   r   _callTestMethodx  s    zTestCase._callTestMethodc                 C   s   |    d S r)   )r   ri   r   r   r   _callTearDown{  s    zTestCase._callTearDownc                O   s   ||| d S r)   r   r   r-   r.   r/   r   r   r   _callCleanup~  s    zTestCase._callCleanupNc              
   C   s  |}|d kr.|   }t|dd }|d k	r.|  ||  t| | j}t| jdds^t|ddrz,t| jddpxt|dd}| || | W 5 ||  X d S t|dd}t| dd}|p|}t|}	z|	| _|	|  |   W 5 Q R X |	jr@||	_|	j| dd	 | | W 5 Q R X d|	_|	|  |   W 5 Q R X |   |	jD ]\}}| ||| qN| ||	j |	jr|r|	j
r| ||	j
 n
| | n
||  |W S ||  |d krt|dd }
|
d k	r|
  |	j	  d |	_
d | _X d S )
NstartTestRunr?   Fr@   rC   rK   stopTestRunTr   )r   r   Z	startTestr   r   ZstopTestr   r   r   clearr   r   r&   r   r   r   r   r   
doCleanupsr   r   r   r   r   )r   r   Zorig_resultr   r   Zskip_whyZexpecting_failure_methodZexpecting_failure_classr   outcomer   r   r9   r   r   r   run  st    


  




zTestCase.runc              	   C   sR   | j p
t }| jrL| j \}}}||  | j|f|| W 5 Q R X q|jS )zNExecute all cleanup functions. Normally called for you after
        tearDown.)r   r   r   r1   r&   r   r   )r   r   r-   r.   r/   r   r   r   r     s    zTestCase.doCleanupsc              
   C   sd   g | _ | jr`| j \}}}z||| W q tk
r\ } z| j t  W 5 d}~X Y qX qdS )zYExecute all class cleanup functions. Normally called for you after
        tearDownClass.N)ZtearDown_exceptionsr   r1   r2   r   r!   r"   )r   r-   r.   r/   r4   r   r   r   doClassCleanups  s    zTestCase.doClassCleanupsc                 O   s   | j ||S r)   )r   )r   r.   kwdsr   r   r   __call__  s    zTestCase.__call__c                 C   sF   |    t| | j  |   | jrB| jd\}}}||| qdS )z6Run the test without collecting errors in a TestResultN)r   r   r   r   r   r1   r   r   r   r   debug  s    zTestCase.debugc                 C   s   t |dS )zSkip this test.Nr6   )r   r9   r   r   r   skipTest  s    zTestCase.skipTestc                 C   s   |  |dS )z)Fail immediately, with the given message.N)rX   )r   rW   r   r   r   fail  s    zTestCase.failc                 C   s&   |r"|  |dt| }| |dS )z#Check that the expression is false.z%s is not falseNrV   r   rX   r   exprrW   r   r   r   assertFalse  s    zTestCase.assertFalsec                 C   s&   |s"|  |dt| }| |dS )z"Check that the expression is true.z%s is not trueNr  r  r   r   r   
assertTrue  s    zTestCase.assertTruec                 C   sV   | j s|p|S |dkr|S zd||f W S  tk
rP   dt|t|f  Y S X dS )a  Honour the longMessage attribute when generating failure messages.
        If longMessage is False this means:
        * Use only an explicit message if it is provided
        * Otherwise use the standard message for the assert

        If longMessage is True:
        * Use the standard message
        * If an explicit message is provided, plus ' : ' and the explicit message
        Nz%s : %s)longMessageUnicodeDecodeErrorr   )r   rW   rY   r   r   r   rV     s    
zTestCase._formatMessagec                 O   s(   t || }z|d||W S d}X dS )a=  Fail unless an exception of class expected_exception is raised
           by the callable when invoked with specified positional and
           keyword arguments. If a different type of exception is
           raised, it will not be caught, and the test case will be
           deemed to have suffered an error, exactly as for an
           unexpected exception.

           If called with the callable and arguments omitted, will return a
           context object used like this::

                with self.assertRaises(SomeException):
                    do_something()

           An optional keyword argument 'msg' can be provided when assertRaises
           is used as a context object.

           The context manager keeps a reference to the exception as
           the 'exception' attribute. This allows you to inspect the
           exception after the assertion::

               with self.assertRaises(SomeException) as cm:
                   do_something()
               the_exception = cm.exception
               self.assertEqual(the_exception.error_code, 3)
        NassertRaisesrh   rg   )r   expected_exceptionr.   r/   contextr   r   r   r    s    
zTestCase.assertRaisesc                 O   s   t || }|d||S )a  Fail unless a warning of class warnClass is triggered
           by the callable when invoked with specified positional and
           keyword arguments.  If a different type of warning is
           triggered, it will not be handled: depending on the other
           warning filtering rules in effect, it might be silenced, printed
           out, or raised as an exception.

           If called with the callable and arguments omitted, will return a
           context object used like this::

                with self.assertWarns(SomeWarning):
                    do_something()

           An optional keyword argument 'msg' can be provided when assertWarns
           is used as a context object.

           The context manager keeps a reference to the first matching
           warning as the 'warning' attribute; similarly, the 'filename'
           and 'lineno' attributes give you information about the line
           of Python code from which the warning was triggered.
           This allows you to inspect the warning after the assertion::

               with self.assertWarns(SomeWarning) as cm:
                   do_something()
               the_warning = cm.warning
               self.assertEqual(the_warning.some_attribute, 147)
        assertWarnsrx   rg   )r   expected_warningr.   r/   r  r   r   r   r  5  s    
zTestCase.assertWarnsc                 C   s   t | ||S )a  Fail unless a log message of level *level* or higher is emitted
        on *logger_name* or its children.  If omitted, *level* defaults to
        INFO and *logger* defaults to the root logger.

        This method must be used as a context manager, and will yield
        a recording object with two attributes: `output` and `records`.
        At the end of the context manager, the `output` attribute will
        be a list of the matching formatted log messages and the
        `records` attribute will be a list of the corresponding LogRecord
        objects.

        Example::

            with self.assertLogs('foo', level='INFO') as cm:
                logging.getLogger('foo').info('first message')
                logging.getLogger('foo.bar').error('second message')
            self.assertEqual(cm.output, ['INFO:foo:first message',
                                         'ERROR:foo.bar:second message'])
        )r   )r   r   r   r   r   r   
assertLogsT  s    zTestCase.assertLogsc                 C   sF   t |t |kr@| jt |}|dk	r@t|tr<t| |}|S | jS )a  Get a detailed comparison function for the types of the two args.

        Returns: A callable accepting (first, second, msg=None) that will
        raise a failure exception if first != second with a useful human
        readable error message for those types.
        N)r<   r   r   r;   r    r   _baseAssertEqual)r   firstsecondZasserterr   r   r   _getAssertEqualityFuncj  s    

zTestCase._getAssertEqualityFuncc                 C   s0   ||ks,dt || }| ||}| |dS )z:The default assertEqual implementation, not type specific.%s != %sN)r   rV   rX   )r   r  r  rW   rY   r   r   r   r    s    zTestCase._baseAssertEqualc                 C   s   |  ||}||||d dS )z[Fail if the two objects are unequal as determined by the '=='
           operator.
        )rW   N)r  )r   r  r  rW   Zassertion_funcr   r   r   assertEqual  s    zTestCase.assertEqualc                 C   s2   ||ks.|  |dt|t|f }| |dS )zYFail if the two objects are equal as determined by the '!='
           operator.
        z%s == %sNr  )r   r  r  rW   r   r   r   assertNotEqual  s
    zTestCase.assertNotEqualc                 C   s   ||krdS |dk	r$|dk	r$t dt|| }|dk	rf||krDdS dt|t|t|t|f }n:|dkrrd}t||dkrdS dt|t||t|f }| ||}| |dS )a'  Fail if the two objects are unequal as determined by their
           difference rounded to the given number of decimal places
           (default 7) and comparing to zero, or by comparing that the
           difference between the two objects is more than the given
           delta.

           Note that decimal places (from zero) are usually not the same
           as significant digits (measured from the most significant digit).

           If the two objects compare equal then they will automatically
           compare almost equal.
        N specify delta or places not bothz(%s != %s within %s delta (%s difference)   r   z)%s != %s within %r places (%s difference)ra   absr   roundrV   rX   r   r  r  ZplacesrW   ZdeltadiffrY   r   r   r   assertAlmostEqual  s4    zTestCase.assertAlmostEqualc                 C   s   |dk	r|dk	rt dt|| }|dk	rb||ks@||kr@dS dt|t|t|t|f }n<|dkrnd}||kst||dkrdS dt|t||f }| ||}| |dS )a  Fail if the two objects are equal as determined by their
           difference rounded to the given number of decimal places
           (default 7) and comparing to zero, or by comparing that the
           difference between the two objects is less than the given delta.

           Note that decimal places (from zero) are usually not the same
           as significant digits (measured from the most significant digit).

           Objects that are equal automatically fail.
        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k	rP|j }t||s.| d|t|f t||sT| d|t|f nd}d}zt|}W n  ttfk
r   d| }Y nX |dkrzt|}W n  ttfk
r   d| }Y nX |dkr||krdS d| ft||  }t	t
||D ]}	z||	 }
W n4 tttfk
r<   |d|	|f 7 }Y  qY nX z||	 }W n4 tttfk
r~   |d	|	|f 7 }Y  qY nX |
|kr|d
|	ft|
|  7 } qq||kr|dkrt|t|krdS ||kr<|d||| f 7 }z|d|t|| f 7 }W n, tttfk
r8   |d||f 7 }Y nX nh||k r|d||| f 7 }z|d|t|| f 7 }W n, tttfk
r   |d||f 7 }Y nX |}ddtt| t|  }| ||}| ||}| | dS )aA  An equality assertion for ordered sequences (like lists and tuples).

        For the purposes of this function, a valid ordered sequence type is one
        which can be indexed, has a length, and has an equality operator.

        Args:
            seq1: The first sequence to compare.
            seq2: The second sequence to compare.
            seq_type: The expected datatype of the sequences, or None if no
                    datatype should be enforced.
            msg: Optional message to use on failure instead of a list of
                    differences.
        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;   rX   r   r   ra   NotImplementedError
capitalizer   rangemin
IndexErrorr<   joindifflibndiffpprintpformat
splitlines_truncateMessagerV   r   )r   Zseq1Zseq2rW   seq_typeZseq_type_nameZ	differingZlen1Zlen2iZitem1Zitem2rY   diffMsgr   r   r   assertSequenceEqual  s    












zTestCase.assertSequenceEqualc                 C   s2   | j }|d kst||kr"|| S |tt|  S r)   )maxDiffr   DIFF_OMITTED)r   r   r  Zmax_diffr   r   r   r+  N  s    zTestCase._truncateMessagec                 C   s   | j |||td dS )a  A list-specific equality assertion.

        Args:
            list1: The first list to compare.
            list2: The second list to compare.
            msg: Optional message to use on failure instead of a list of
                    differences.

        r,  N)r/  r|   )r   Zlist1Zlist2rW   r   r   r   r   T  s    
zTestCase.assertListEqualc                 C   s   | j |||td dS )a  A tuple-specific equality assertion.

        Args:
            tuple1: The first tuple to compare.
            tuple2: The second tuple to compare.
            msg: Optional message to use on failure instead of a list of
                    differences.
        r2  N)r/  rQ   )r   Ztuple1Ztuple2rW   r   r   r   r   `  s    	zTestCase.assertTupleEqualc           
   
   C   s`  z| |}W n^ tk
r> } z| d|  W 5 d}~X Y n0 tk
rl } z| d|  W 5 d}~X Y nX z| |}W n^ tk
r } z| d|  W 5 d}~X Y n0 tk
r } z| d|  W 5 d}~X Y nX |s|sdS g }|r|d |D ]}|t| q |r@|d |D ]}|t| q*d|}	| | ||	 dS )a  A set-specific equality assertion.

        Args:
            set1: The first set to compare.
            set2: The second set to compare.
            msg: Optional message to use on failure instead of a list of
                    differences.

        assertSetEqual uses ducktyping to support different types of sets, and
        is optimized for sets specifically (parameters must support a
        difference method).
        z/invalid type when attempting set difference: %sNz2first 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   )
differencera   r   re   r   reprr%  rV   )
r   Zset1Zset2rW   Zdifference1r%   Zdifference2linesitemrY   r   r   r   r   k  s2      


zTestCase.assertSetEqualc                 C   s2   ||kr.dt |t |f }| | || dS )zDJust like self.assertTrue(a in b), but with a nicer default message.z%s not found in %sNr   r   rV   r   memberZ	containerrW   rY   r   r   r   assertIn  s
    zTestCase.assertInc                 C   s2   ||kr.dt |t |f }| | || dS )zHJust like self.assertTrue(a not in b), but with a nicer default message.z%s unexpectedly found in %sNr7  r8  r   r   r   assertNotIn  s
    zTestCase.assertNotInc                 C   s2   ||k	r.dt |t |f }| | || dS )zDJust like self.assertTrue(a is b), but with a nicer default message.z%s is not %sNr7  r   Zexpr1Zexpr2rW   rY   r   r   r   assertIs  s
    zTestCase.assertIsc                 C   s,   ||kr(dt |f }| | || dS )zHJust like self.assertTrue(a is not b), but with a nicer default message.zunexpectedly identical: %sNr7  r<  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   rV   )r   Zd1Zd2rW   rY   r  r   r   r   r     s    
zTestCase.assertDictEqualc           	   	   C   s   t dt g }g }| D ]L\}}||k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 )z2Checks whether dictionary is a superset of subset.z&assertDictContainsSubset is deprecatedz%s, expected: %s, actual: %sNrC   zMissing: %s,c                 s   s   | ]}t |V  qd S r)   )r   )rM   r   r   r   r   rP     s     z4TestCase.assertDictContainsSubset.<locals>.<genexpr>z; zMismatched values: %s)	r   r   r   itemsr   r   r%  r   rV   )	r   ZsubsetZ
dictionaryrW   ZmissingZ
mismatchedkeyvaluerY   r   r   r   assertDictContainsSubset  s4    

z!TestCase.assertDictContainsSubsetc           
      C   s   t |t | }}zt|}t|}W n tk
rH   t||}Y nX ||krVdS t||}|rd}dd |D }d|}	| ||	}| ||}| 	| dS )a[  Asserts that two iterables have the same elements, the same number of
        times, without regard to order.

            self.assertEqual(Counter(list(first)),
                             Counter(list(second)))

         Example:
            - [0, 1, 1] and [1, 0, 1] compare equal.
            - [0, 0, 1] and [0, 1] compare unequal.

        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>  s     z-TestCase.assertCountEqual.<locals>.<listcomp>r   )
r|   collectionsCounterra   r   r   r%  r+  rV   r   )
r   r  r  rW   Z	first_seqZ
second_seqZdifferencesrY   r5  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 )z-Assert that two multi-line strings are equal.zFirst argument is not a stringzSecond argument is not a stringT)keependsr   z
r   r  rC   N)r?  r    r   _diffThresholdr  r*  r   r   r%  r&  r'  r+  r   rV   )r   r  r  rW   Z
firstlinesZsecondlinesrY   r  r   r   r   r     s     

zTestCase.assertMultiLineEqualc                 C   s2   ||k s.dt |t |f }| | || dS )zCJust like self.assertTrue(a < b), but with a nicer default message.z%s not less than %sNr7  r   abrW   rY   r   r   r   
assertLess  s    zTestCase.assertLessc                 C   s2   ||ks.dt |t |f }| | || dS )zDJust like self.assertTrue(a <= b), but with a nicer default message.z%s not less than or equal to %sNr7  rK  r   r   r   assertLessEqual  s    zTestCase.assertLessEqualc                 C   s2   ||ks.dt |t |f }| | || dS )zCJust like self.assertTrue(a > b), but with a nicer default message.z%s not greater than %sNr7  rK  r   r   r   assertGreater  s    zTestCase.assertGreaterc                 C   s2   ||ks.dt |t |f }| | || dS )zDJust like self.assertTrue(a >= b), but with a nicer default message.z"%s not greater than or equal to %sNr7  rK  r   r   r   assertGreaterEqual   s    zTestCase.assertGreaterEqualc                 C   s,   |dk	r(dt |f }| | || dS )zCSame as self.assertTrue(obj is None), with a nicer default message.Nz%s is not Noner7  r   r*   rW   rY   r   r   r   assertIsNone&  s    zTestCase.assertIsNonec                 C   s"   |dkrd}|  | || dS )z(Included for symmetry with assertIsNone.Nzunexpectedly None)r   rV   rR  r   r   r   assertIsNotNone,  s    zTestCase.assertIsNotNonec                 C   s0   t ||s,dt||f }| | || dS )zTSame as self.assertTrue(isinstance(obj, cls)), with a nicer
        default message.z%s is not an instance of %rNr;   r   r   rV   r   r*   r   rW   rY   r   r   r   r?  2  s    
zTestCase.assertIsInstancec                 C   s0   t ||r,dt||f }| | || dS )z,Included for symmetry with assertIsInstance.z%s is an instance of %rNrU  rV  r   r   r   assertNotIsInstance9  s    
zTestCase.assertNotIsInstancec                 O   s   t || |}|d||S )a  Asserts that the message in a raised exception matches a regex.

        Args:
            expected_exception: Exception class expected to be raised.
            expected_regex: Regex (re.Pattern object or string) expected
                    to be found in error message.
            args: Function to be called and extra positional args.
            kwargs: Extra kwargs.
            msg: Optional message used in case of failure. Can only be used
                    when assertRaisesRegex is used as a context manager.
        assertRaisesRegexr	  )r   r
  r^   r.   r/   r  r   r   r   rX  ?  s    zTestCase.assertRaisesRegexc                 O   s   t || |}|d||S )a  Asserts that the message in a triggered warning matches a regexp.
        Basic functioning is similar to assertWarns() with the addition
        that only warnings whose messages also match the regular expression
        are considered successful matches.

        Args:
            expected_warning: Warning class expected to be triggered.
            expected_regex: Regex (re.Pattern object or string) expected
                    to be found in error message.
            args: Function to be called and extra positional args.
            kwargs: Extra kwargs.
            msg: Optional message used in case of failure. Can only be used
                    when assertWarnsRegex is used as a context manager.
        assertWarnsRegexr  )r   r  r^   r.   r/   r  r   r   r   rY  O  s    zTestCase.assertWarnsRegexc                 C   sJ   t |ttfrt|}||sFd|j|f }| ||}| |dS )z=Fail the test unless the text matches the regular expression.z&Regex didn't match: %r not found in %rN)	r;   r    bytesr\   r]   rp   rq   rV   rX   )r   textr^   rW   rY   r   r   r   assertRegexb  s    

 zTestCase.assertRegexc                 C   s`   t |ttfrt|}||}|r\d|| |  |j|f }| 	||}| 
|dS )z9Fail the test if the text matches the regular expression.z"Regex matched: %r matches %r in %rN)r;   r    rZ  r\   r]   rp   startendrq   rV   rX   )r   r[  Zunexpected_regexrW   matchrY   r   r   r   assertNotRegexn  s    

zTestCase.assertNotRegexc                    s    fdd}|S )Nc                     s    t d jtd  | |S )NzPlease use {0} instead.r   )r   r   rl   r   r   r7   original_funcr   r   deprecated_func~  s    
 z,TestCase._deprecate.<locals>.deprecated_funcr   )rb  rc  r   ra  r   
_deprecate}  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)er   r   r   r   AssertionErrorrX   r  r0  rJ  Z_classSetupFailedr   r   r   r   __text_signature__classmethodr   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  rV   r  r  r  r  r  r  r  r  r  r/  r+  r   r   r   r:  r;  r=  r>  r   rD  rH  r   rN  rO  rP  rQ  rS  rT  r?  rW  rX  rY  r\  r`  rd  ZfailUnlessEqualZassertEqualsZfailIfEqualZassertNotEqualsZfailUnlessAlmostEqualZassertAlmostEqualsZfailIfAlmostEqualZassertNotAlmostEqualsZ
failUnlessZassert_ZfailUnlessRaisesZfailIfZassertRaisesRegexpZassertRegexpMatchesZassertNotRegexpMatchesr   r   r   r   r   w  s    
 


	


E
	


!



	  
-  
#
c


+






 










	r   c                       sj   e Zd 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 )FunctionTestCaseaI  A test case that wraps a test function.

    This is useful for slipping pre-existing test functions into the
    unittest framework. Optionally, set-up and tidy-up functions can be
    supplied. As with TestCase, the tidy-up ('tearDown') function will
    always be called if the set-up ('setUp') function ran successfully.
    Nc                    s*   t t|   || _|| _|| _|| _d S r)   )superri  r   
_setUpFunc_tearDownFunc	_testFunc_description)r   ZtestFuncr   r   Zdescriptionr   r   r   r     s
    zFunctionTestCase.__init__c                 C   s   | j d k	r|    d S r)   )rk  ri   r   r   r   r     s    
zFunctionTestCase.setUpc                 C   s   | j d k	r|    d S r)   )rl  ri   r   r   r   r     s    
zFunctionTestCase.tearDownc                 C   s   |    d S r)   )rm  ri   r   r   r   r     s    zFunctionTestCase.runTestc                 C   s   | j jS r)   )rm  r   ri   r   r   r   r     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   rk  rl  rm  rn  r   r   r   r   r     s    


zFunctionTestCase.__eq__c                 C   s   t t| | j| j| j| jfS r)   )r   r<   rk  rl  rm  rn  ri   r   r   r   r     s     zFunctionTestCase.__hash__c                 C   s   dt | j| jjf S r   )r   r   rm  r   ri   r   r   r   r     s    
zFunctionTestCase.__str__c                 C   s   dt | j| jf S )Nz<%s tec=%s>)r   r   rm  ri   r   r   r   r     s    
zFunctionTestCase.__repr__c                 C   s2   | j d k	r| j S | jj}|r.|dd  p0d S )Nr   r   )rn  rm  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   r   __classcell__r   r   ro  r   ri    s   	ri  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)   )rj  r   _messager#   r   rX   )r   r#   r   r   ro  r   r   r     s
    
z_SubTest.__init__c                 C   s   t dd S )Nzsubtests cannot be run directly)r   ri   r   r   r   r     s    z_SubTest.runTestc                 C   s^   g }| j tk	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)rl   )rM   r   r   r   r   r   rP     s   z+_SubTest._subDescription.<locals>.<genexpr>z({}) z(<subtest>))rq  rh  r   rl   r   r%  rA  )r   partsZparams_descr   r   r   _subDescription  s    

z_SubTest._subDescriptionc                 C   s   d | j |  S Nz{} {})rl   r#   r   rt  ri   r   r   r   r     s    z_SubTest.idc                 C   s
   | j  S )zlReturns a one-line description of the subtest, or None if no
        description has been provided.
        )r#   r   ri   r   r   r   r     s    z_SubTest.shortDescriptionc                 C   s   d | j|  S ru  )rl   r#   rt  ri   r   r   r   r     s    z_SubTest.__str__)
r   r   r   r   r   rt  r   r   r   rp  r   r   ro  r   r     s   r   )4r   r!   r=   r&  r   r(  r\   r   rF  r'   rm   rD   rC   r   utilr   r   r   r   r   Z
__unittestobjectrh  r1  r2   r	   r   r   r   r+   r,   r0   r5   rF   rI   rJ   r   rL   rU   r[   rh   rx   
namedtupler   r   r   r   ChainMapr   r   ri  r   r   r   r   r   <module>   sd   (	*%5,
        $:                                                                                                                                                                                                                                                                loader.cpython-38.pyc                                                                               0000644                 00000034312 15175327600 0010453 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dX                     @   s  d 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m	Z	 ddl
mZmZmZ dZedejZG dd	 d	ejZd
d Zdd Zdd Zdd Zdd ZG dd deZe ZdddZejdfddZdejejfddZ dejejfddZ!dS ) zLoading unittests.    N)fnmatchfnmatchcase   )casesuiteutilTz[_a-z]\w*\.py$c                       s,   e Zd ZdZ fddZ fddZ  ZS )_FailedTestNc                    s   || _ tt| | d S N)
_exceptionsuperr   __init__)selfZmethod_name	exception	__class__ '/usr/lib64/python3.8/unittest/loader.pyr      s    z_FailedTest.__init__c                    s*   | j krtt |S  fdd}|S )Nc                      s
    j d S r	   )r
   r   r   r   r   testFailure!   s    z,_FailedTest.__getattr__.<locals>.testFailure)_testMethodNamer   r   __getattr__)r   namer   r   r   r   r      s    
z_FailedTest.__getattr__)__name__
__module____qualname__r   r   r   __classcell__r   r   r   r   r      s   r   c                 C   s"   d| t  f }t| t|||S )Nz#Failed to import test module: %s
%s)	traceback
format_exc_make_failed_testImportError)r   
suiteClassmessager   r   r   _make_failed_import_test&   s
     r"   c                 C   s   dt  f }t| |||S )NzFailed to call load_tests:
%s)r   r   r   )r   r   r    r!   r   r   r   _make_failed_load_tests+   s       r#   c                 C   s   t | |}||f|fS r	   )r   )
methodnamer   r    r!   testr   r   r   r   0   s    
r   c                 C   s<   t t|dd }| |i}tdt jf|}||| fS )Nc                 S   s   d S r	   r   r   r   r   r   testSkipped5   s    z'_make_skipped_test.<locals>.testSkippedZModuleSkipped)r   skipstrtypeTestCase)r$   r   r    r&   attrsZ	TestClassr   r   r   _make_skipped_test4   s
    
r,   c                 C   s*   |   dr| d d S tj| d S )Nz	$py.classir   )lowerendswithospathsplitext)r0   r   r   r   _jython_aware_splitext<   s    r2   c                       s   e Zd ZdZdZeejZdZ	e
jZdZ fddZdd Zddd	d
Zd!ddZd"ddZdd Zd#ddZdd Zdd Zdd Zdd Zd$ddZd%dd Z  ZS )&
TestLoaderz
    This class is responsible for loading tests according to various criteria
    and returning them wrapped in a TestSuite
    r%   Nc                    s    t t|   g | _t | _d S r	   )r   r3   r   errorsset_loading_packagesr   r   r   r   r   M   s    zTestLoader.__init__c                 C   sF   t |tjrtd| |}|s2t|dr2dg}| t||}|S )z;Return a suite of all test cases contained in testCaseClasszYTest cases should not be derived from TestSuite. Maybe you meant to derive from TestCase?ZrunTest)
issubclassr   	TestSuite	TypeErrorgetTestCaseNameshasattrr    map)r   testCaseClassZtestCaseNamesZloaded_suiter   r   r   loadTestsFromTestCaseT   s    
z TestLoader.loadTestsFromTestCasepatternc             
   O   s:  t |dksd|kr,tdt |dd t |dkrRt |d }td|t |dkrxt|d }td|g }t|D ]4}t	||}t
|trt|tjr|| | qt	|dd}	| |}|	dk	r6z|	| ||W S  tk
r4 }
 z,t|j|
| j\}}| j| | W Y S d}
~
X Y nX |S )	z>Return a suite of all test cases contained in the given moduler   Zuse_load_testsz(use_load_tests is deprecated and ignoredNr   zCloadTestsFromModule() takes 1 positional argument but {} were givenz=loadTestsFromModule() got an unexpected keyword argument '{}'
load_tests)lenwarningswarnDeprecationWarningpopr9   formatsorteddirgetattr
isinstancer)   r7   r   r*   appendr>   r    	Exceptionr#   r   r4   )r   moduler@   argsZkwsZ	complainttestsr   objrA   e
error_caseerror_messager   r   r   loadTestsFromModuleb   s<    


  zTestLoader.loadTestsFromModulec                 C   sX  | d}d\}}|dkr|dd }|rzd|}t|}W qW q& tk
r   | }t|| j\}}|s| j| | Y S Y q&X q&|dd }|}	|D ]}
z|	t	|	|
 }}	W q t
k
rN } zvt	|	dddk	r|dk	r| j| | W Y D  S t|
|| jdt f \}}| j| | W Y 
  S W 5 d}~X Y qX qt|	tjrj| |	S t|	trt|	tjr| |	S t|	tjrt|trt|tjr|d }||}tt	||tjs| |gS nt|	tjr|	S t|	rH|	 }t|tjr|S t|tjr6| |gS td|	|f ntd	|	 dS )
aS  Return a suite of all test cases given a string specifier.

        The name may resolve either to a module, a test case class, a
        test method within a test case class, or a callable object which
        returns a TestCase or TestSuite instance.

        The method optionally resolves the names relative to a given module.
        .)NNNr   __path__zFailed to access attribute:
%sz"calling %s returned %s, not a testz$don't know how to make test from: %s)splitjoin
__import__r   rF   r"   r    r4   rL   rJ   AttributeErrorr   r   r   rK   types
ModuleTyperU   r)   r7   r   r*   r>   FunctionTyper   r8   callabler9   )r   r   rN   partsrS   rT   Z
parts_copymodule_nameZnext_attributerQ   partparentrR   instr%   r   r   r   loadTestsFromName   s    	

   $



zTestLoader.loadTestsFromNamec                    s    fdd|D } |S )zReturn a suite of all test cases found using the given sequence
        of string specifiers. See 'loadTestsFromName()'.
        c                    s   g | ]} | qS r   )rf   ).0r   rN   r   r   r   
<listcomp>   s     z1TestLoader.loadTestsFromNames.<locals>.<listcomp>)r    )r   namesrN   Zsuitesr   rh   r   loadTestsFromNames   s    zTestLoader.loadTestsFromNamesc                    s>    fdd}t t|t} jr:|jt jd |S )zLReturn a sorted sequence of method names found within testCaseClass
        c                    sZ   |  jsdS t| }t|s&dS djj| f  jd kpXt fddjD S )NFz%s.%s.%sc                 3   s   | ]}t  |V  qd S r	   )r   )rg   r@   ZfullNamer   r   	<genexpr>   s     zKTestLoader.getTestCaseNames.<locals>.shouldIncludeMethod.<locals>.<genexpr>)
startswithtestMethodPrefixrJ   r`   r   r   testNamePatternsany)attrnameZtestFuncr   r=   rl   r   shouldIncludeMethod   s    
  
z8TestLoader.getTestCaseNames.<locals>.shouldIncludeMethod)key)listfilterrI   sortTestMethodsUsingsort	functools
cmp_to_key)r   r=   rt   ZtestFnNamesr   rs   r   r:      s
    zTestLoader.getTestCaseNamestest*.pyc                 C   sJ  d}|dkr| j dk	r| j }n|dkr.d}|}tj|}|tjkrRtjd| || _ d}d}g }tjtj|rtj|}||krtjtj|d }npzt	| W n t
k
r   d}Y nJX tj| }|dd }	ztjtj|j}W n tk
r   z
|j}
W n tk
r8   d}
Y nX |
r|
jdkr|
jdk	rd}|jD ]P}|s|||s|qb||jdtjjd | _ || j||dd qbn*|jtjkrtddntd	|dY nX |r|s| |	| _ tj| ntj| |r*t
d
| |s@t| ||}|  |S )a%  Find and return all test modules from the specified start
        directory, recursing into subdirectories to find them and return all
        tests found within them. Only test files that match the pattern will
        be loaded. (Using shell style pattern matching.)

        All test modules must be importable from the top level of the project.
        If the start directory is not the top level directory then the top
        level directory must be specified separately.

        If a test package name (directory with '__init__.py') matches the
        pattern then the package will be checked for a 'load_tests' function. If
        this exists then it will be called with (loader, tests, pattern) unless
        the package has already had load_tests called from the same discovery
        invocation, in which case the package module object is not scanned for
        tests - this ensures that when a package uses discover to further
        discover child tests that infinite recursion does not happen.

        If load_tests exists then discovery does *not* recurse into the package,
        load_tests is responsible for loading all tests in the package.

        The pattern is deliberately not stored as a loader attribute so that
        packages can continue discovery themselves. top_level_dir is stored so
        load_tests does not need to pass this argument in to loader.discover().

        Paths are sorted before being imported to ensure reproducible execution
        order even on filesystems with non-alphabetical ordering like ext3/4.
        FNTr   __init__.pyrV   )	namespacez2Can not use builtin modules as dotted module namesz$don't know how to discover from {!r}z%Start directory is not importable: %r)!_top_level_dirr/   r0   abspathsysinsertisdirisfilerZ   r[   r   modulesrY   dirname__file__r\   __spec__loadersubmodule_search_locationsrW   rn   r   replacesepextend_find_testsbuiltin_module_namesr9   rG    _get_directory_containing_moduleremoverv   r    )r   	start_dirr@   Ztop_level_dirZset_implicit_topZis_not_importableis_namespacerP   Z
the_moduleZtop_partspecr0   r   r   r   discover   s    





 
zTestLoader.discoverc                 C   sR   t j| }tj|j}tj| drBtj	tj	|S tj	|S d S )Nr}   )
r   r   r/   r0   r   r   basenamer-   rn   r   )r   rb   rN   	full_pathr   r   r   r   `  s
    
z+TestLoader._get_directory_containing_modulec                 C   sh   || j krdS ttj|}tj|| j }tj|rBtd|drTtd|	tjj
d}|S )NrV   zPath must be within the projectz..)r   r2   r/   r0   normpathrelpathisabsAssertionErrorrn   r   r   )r   r0   Z_relpathr   r   r   r   _get_name_from_pathl  s    
zTestLoader._get_name_from_pathc                 C   s   t | tj| S r	   )r[   r   r   )r   r   r   r   r   _get_module_from_namex  s    z TestLoader._get_module_from_namec                 C   s
   t ||S r	   )r   )r   r0   r   r@   r   r   r   _match_path|  s    zTestLoader._match_pathFc           
   
   c   s   |  |}|dkrD|| jkrD| |||\}}|dk	r<|V  |sDdS tt|}|D ]t}tj||}	| |	||\}}|dk	r|V  |rV|  |	}| j| z| 
|	||E dH  W 5 | j	| X qVdS )z/Used by discovery. Yields test suites it loads.rV   N)r   r6   _find_test_pathrH   r/   listdirr0   rZ   adddiscardr   )
r   r   r@   r~   r   rP   Zshould_recursepathsr0   r   r   r   r   r     s6    
    
zTestLoader._find_testsc              
   C   st  t j|}t j|rVt|s(dS | |||s:dS | |}z| |}W nh t	j
k
r } zt||| jdf W Y S d}~X Y n   t|| j\}}	| j|	 |df Y S X t jt|d|}
tt j|
}tt j|}| | kr@t j|}tt j|}t j|}d}t||||f | j||ddfS nt j|rl|st jt j|dsdS d}d}| |}z| |}W nj t	j
k
r } zt||| jdf W Y S d}~X Y n   t|| j\}}	| j|	 |df Y S X t|dd}| j| z0| j||d}|dk	rP|dfW S |d	fW S | j| X ndS dS )
zUsed by discovery.

        Loads tests from a single file, or a directories' __init__.py when
        passed the directory.

        Returns a tuple (None_or_tests_from_file, should_recurse).
        )NFFNr   zW%r module incorrectly imported from %r. Expected %r. Is this module globally installed?r?   r}   rA   T)r/   r0   r   r   VALID_MODULE_NAMEmatchr   r   r   r   ZSkipTestr,   r    r"   r4   rL   r   rJ   r2   realpathr-   r   r   rU   r   rZ   r6   r   r   )r   r   r@   r~   r   r   rN   rR   rS   rT   Zmod_filer   Zfullpath_noextZ
module_dirZmod_nameZexpected_dirmsgrA   rP   packager   r   r   r     s|    

&





&

zTestLoader._find_test_path)N)N)r|   N)F)F)r   r   r   __doc__ro   staticmethodr   three_way_cmprx   rp   r   r8   r    r   r   r>   rU   rf   rk   r:   r   r   r   r   r   r   r   r   r   r   r   r   r3   B   s&   
(
N

n
"r3   c                 C   s&   t  }||_| |_||_|r"||_|S r	   )r3   rx   ro   rp   r    )prefix	sortUsingr    rp   r   r   r   r   _makeLoader  s    r   c                 C   s   t |||d| S )N)rp   )r   r:   )r=   r   r   rp   r   r   r   r:     s    r:   r%   c                 C   s   t |||| S r	   )r   r>   )r=   r   r   r    r   r   r   	makeSuite  s    r   c                 C   s   t |||| S r	   )r   rU   )rN   r   r   r    r   r   r   findTestCases  s    r   )NN)"r   r/   rer   r   r]   rz   rC   r   r    r   r   r   Z
__unittestcompile
IGNORECASEr   r*   r   r"   r#   r   r,   r2   objectr3   ZdefaultTestLoaderr   r   r:   r8   r   r   r   r   r   r   <module>   s<      /
	
                                                                                                                                                                                                                                                                                                                      case.cpython-38.pyc                                                                                 0000644                 00000142466 15175327600 0010132 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   s  d 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
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)e*d(d)d*gZ+G d+d, d,ej,Z-G d-d. d.e&Z.G d/d0 d0ej/Z0G d1d2 d2eZ1G d3d4 d4e1Z2G d5d6 d6e1Z3dS )7zTest case implementation    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ZdS )SkipTestz
    Raise this exception in a test to skip it.

    Usually you can use TestCase.skipTest() or one of the skipping decorators
    instead of raising this directly.
    N__name__
__module____qualname____doc__ r   r   %/usr/lib64/python3.8/unittest/case.pyr	      s   r	   c                   @   s   e Zd ZdZdS )_ShouldStopz
    The test should stop.
    Nr
   r   r   r   r   r   "   s   r   c                   @   s   e Zd ZdZdS )_UnexpectedSuccessz7
    The test was supposed to fail, but it didn't!
    Nr
   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k
r.    Y n tk
rh } zd| _ | j|t|f W 5 d }~X Y nj tk
rz   Y nX   t }| j	r|| _
nd| _ | j||f d }Y nX | jr| j r| j|d f W 5 | j o|| _ X d S )NTF)r   KeyboardInterruptr	   r   appendstrr   sysexc_infor   r   r   r   )r   	test_caseisTestZold_successer"   r   r   r   testPartExecutor7   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   _idU   s    r+   c                O   s   t | ||f dS )znSame as addCleanup, except the cleanup items are called even if
    setUpModule fails (unlike tearDownModule).N)_module_cleanupsr   )functionargskwargsr   r   r   addModuleCleanupZ   s    r0   c               
   C   sd   g } t rTt  \}}}z||| W q tk
rP } z| | W 5 d}~X Y qX q| r`| d dS )zWExecute all module cleanup functions. Normally called for you after
    tearDownModule.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 )z&
    Unconditionally skip a test.
    c                    s4   t | ts$t|  fdd}|} d| _ | _| S )Nc                     s   t  d S r)   r	   r.   r/   reasonr   r   skip_wrapperv   s    z-skip.<locals>.decorator.<locals>.skip_wrapperT)
isinstancetype	functoolswraps__unittest_skip____unittest_skip_why__)	test_itemr:   r8   r   r   	decoratort   s    
zskip.<locals>.decorator )r;   typesFunctionType)r9   rB   rA   r   r8   r   skipp   s    
rF   c                 C   s   | rt |S tS )z/
    Skip a test if the condition is true.
    rF   r+   Z	conditionr9   r   r   r   skipIf   s    rI   c                 C   s   | st |S tS )z3
    Skip a test unless the condition is true.
    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>   s     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   standardMsgrW   r   r   r   _raiseFailure   s    z"_BaseTestCaseContext._raiseFailureN)r   r   r   r   rZ   r   r   r   r   rU      s   rU   c                   @   s   e Zd ZdddZdd ZdS )_AssertRaisesBaseContextNc                 C   s@   t | | || _|| _|d k	r*t|}|| _d | _d | _d S r)   )	rU   r   rT   r#   recompileexpected_regexobj_namerW   )r   rT   r#   r^   r   r   r   r      s    
z!_AssertRaisesBaseContext.__init__c              	   C   s   zt | j| js"td|| jf |sV|dd| _|rNtdtt|f | W TS |^}}z|j	| _
W n tk
r   t|| _
Y nX |  ||| W 5 Q R X W 5 d} X dS )z
        If args is empty, assertRaises/Warns is being used as a
        context manager, so check for a 'msg' kwarg and return self.
        If args is not empty, call a callable passing positional and keyword
        arguments.
        Nz%s() arg 1 must be %srW   z3%r is an invalid keyword argument for this function)rL   rT   
_base_type	TypeError_base_type_strr1   rW   nextiterr   r_   AttributeErrorr    )r   namer.   r/   Zcallable_objr   r   r   handle   s(    z_AssertRaisesBaseContext.handle)N)r   r   r   r   rg   r   r   r   r   r[      s   

r[   c                   @   s(   e Zd ZdZeZdZdd Zdd ZdS )_AssertRaisesContextzCA context manager used to implement TestCase.assertRaises* methods.z-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 krbz| j j}W n tk
r2   t| j }Y nX | jrP| d|| j ql| d| n
t| t	|| j s|dS |
d | _| jd krdS | j}|t|s| d|jt| dS )Nz{} not raised by {}z{} not raisedFT"{}" does not match "{}")rT   r   re   r    r_   rZ   format	tracebackclear_framesrS   with_tracebackZ	exceptionr^   searchpattern)r   exc_type	exc_valuetbexc_namer^   r   r   r   __exit__   s.    


 z_AssertRaisesContext.__exit__N)	r   r   r   r   BaseExceptionr`   rb   rj   rv   r   r   r   r   rh      s
   rh   c                   @   s(   e Zd ZdZeZdZdd Zdd ZdS )_AssertWarnsContextzBA context manager used to implement TestCase.assertWarns* methods.z(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getattrry   warningscatch_warningswarnings_managerrj   simplefilterrT   )r   vr   r   r   rj      s    z_AssertWarnsContext.__enter__c                 C   s   | j ||| |d k	rd S z| jj}W n tk
rF   t| j}Y nX d }| jD ]Z}|j}t|| jsjqR|d krv|}| j	d k	r| j	
t|sqR|| _|j| _|j| _ d S |d k	r| d| j	jt| | jr| d|| j n| d| d S )Nrk   z{} not triggered by {}z{} not triggered)r   rv   rT   r   re   r    r   messager;   r^   rp   ZwarningfilenamelinenorZ   rl   rq   r_   )r   rr   rs   rt   ru   Zfirst_matchingmwr   r   r   rv     s@    

 
z_AssertWarnsContext.__exit__N)	r   r   r   r   Warningr`   rb   rj   rv   r   r   r   r   rx      s
   rx   _LoggingWatcherrecordsoutputc                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_CapturingHandlerzM
    A logging handler capturing all (raw and formatted) logging output.
    c                 C   s   t j|  tg g | _d S r)   )loggingHandlerr   r   watcherri   r   r   r   r   3  s    z_CapturingHandler.__init__c                 C   s   d S r)   r   ri   r   r   r   flush7  s    z_CapturingHandler.flushc                 C   s*   | j j| | |}| j j| d S r)   )r   r   r   rl   r   )r   rz   rW   r   r   r   emit:  s    
z_CapturingHandler.emitN)r   r   r   r   r   r   r   r   r   r   r   r   .  s   r   c                   @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
_AssertLogsContextz:A context manager used to implement TestCase.assertLogs().z"%(levelname)s:%(name)s:%(message)sc                 C   s:   t | | || _|r(tj||| _ntj| _d | _d S r)   )	rU   r   logger_namer   Z_nameToLevelgetlevelINFOrW   )r   r#   r   r   r   r   r   r   F  s    z_AssertLogsContext.__init__c                 C   s   t | jtjr| j }| _nt| j }| _t| j}t }|	| |j
| _
|jd d  | _|j| _|j| _|g|_|| j d|_|j
S )NF)r;   r   r   ZLoggerloggerZ	getLoggerZ	FormatterLOGGING_FORMATr   ZsetFormatterr   handlersold_handlersr   	old_level	propagateold_propagatesetLevel)r   r   Z	formatterZhandlerr   r   r   rj   O  s    
z_AssertLogsContext.__enter__c                 C   s`   | j | j_| j| j_| j| j |d k	r.dS t| jj	dkr\| 
dt| j| jj d S )NFr   z-no logs of level {} or higher triggered on {})r   r   r   r   r   r   r   lenr   r   rZ   rl   r   ZgetLevelNamer   rf   )r   rr   rs   rt   r   r   r   rv   `  s    


 z_AssertLogsContext.__exit__N)r   r   r   r   r   r   rj   rv   r   r   r   r   r   A  s
   	r   c                   @   s   e Zd Zdd ZdS )_OrderedChainMapc                 c   s8   t  }| jD ]&}|D ]}||kr|| |V  qqd S r)   )setmapsadd)r   seenmappingkr   r   r   __iter__n  s    

z_OrderedChainMap.__iter__N)r   r   r   r   r   r   r   r   r   m  s   r   c                   @   s  e Zd ZdZeZdZdZdZdZ	g Z
dddZd	d
 Zdd Zde_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#d0d1 Z$d2d3 Z%d4d5 Z&d6d7 Z'd8d9 Z(dd;d<Z)d=d> Z*ed?d@ Z+dAdB Z,dCdD Z-dEdF Z.ddGdHZ/ddIdJZ0ddKdLZ1dMdN Z2dOdP Z3dQdR Z4ddSdTZ5dUdV Z6ddWdXZ7ddYdZZ8dd[d\Z9dd]d^Z:dd_d`Z;ddadbZ<dcdd Z=ddedfZ>ddgdhZ?ddidjZ@ddkdlZAddmdnZBddodpZCddqdrZDddsdtZEddudvZFddwdxZGddydzZHdd{d|ZIdd}d~ZJdddZKdddZLdddZMdddZNdddZOdddZPdd ZQdd ZRdddZSdddZTdd ZUeUe8 ZVZWeUe9 ZXZYeUe: ZZZ[eUe; Z\Z]eUe1 Z^Z_eUe3Z`eUe0ZaeUeQZbeUeSZceUeTZdd:S )TestCaseaW  A class whose instances are single test cases.

    By default, the test code itself should be placed in a method named
    'runTest'.

    If the fixture may be used for many test cases, create as
    many test methods as are needed. When instantiating such a TestCase
    subclass, specify in the constructor arguments the name of the test method
    that the instance is to execute.

    Test authors should subclass TestCase for their own tests. Construction
    and deconstruction of the test's environment ('fixture') can be
    implemented by overriding the 'setUp' and 'tearDown' methods respectively.

    If it is necessary to override the __init__ method, the base class
    __init__ method must always be called. It is important that subclasses
    should not change the signature of their __init__ method, since instances
    of the classes are instantiated automatically by parts of the framework
    in order to be run.

    When subclassing TestCase, you can set these attributes:
    * failureException: determines which exception will be raised when
        the instance's assertion methods fail; test methods raising this
        exception will be deemed to have 'failed' rather than 'errored'.
    * longMessage: determines whether long messages (including repr of
        objects used in assert methods) will be printed on failure in *addition*
        to any explicit message passed.
    * maxDiff: sets the maximum length of a diff in failure messages
        by assert methods using difflib. It is looked up as an instance
        attribute so can be configured by individual tests if required.
    Ti  i   FrunTestc                 C   s   || _ d| _d| _zt| |}W n. tk
rN   |dkrJtd| j|f Y n
X |j| _g | _d| _	i | _
| td | td | td | td | td | td	 dS )
zCreate an instance of the class that will use the named test
           method when executed. Raises a ValueError if the instance does
           not have a method with the specified name.
        NzNo testr   zno such test method in %s: %sassertDictEqualassertListEqualassertTupleEqualassertSetEqualassertMultiLineEqual)_testMethodName_outcome_testMethodDocr   re   
ValueError	__class__r   	_cleanups_subtest_type_equality_funcsaddTypeEqualityFuncdictr|   rQ   r   	frozensetr    )r   Z
methodName
testMethodr   r   r   r     s(    zTestCase.__init__c                 C   s   || j |< dS )a[  Add a type specific assertEqual style function to compare a type.

        This method is for use by TestCase subclasses that need to register
        their own type equality functions to provide nicer error messages.

        Args:
            typeobj: The data type to call this function on when both values
                    are of the same type in assertEqual().
            function: The callable taking two arguments and an optional
                    msg= argument that raises self.failureException with a
                    useful error message when the two arguments are not equal.
        N)r   )r   Ztypeobjr-   r   r   r   r     s    zTestCase.addTypeEqualityFuncc                  O   s   t | dkr| ^}}} nV| s&tdnHd|krZ|d}| ^}} ddl}|jdtdd ntdt | d	  t| } |j|| |f dS )
a  Add a function, with arguments, to be called when the test is
        completed. Functions added are called on a LIFO basis and are
        called after tearDown on test failure or success.

        Cleanup items are called even if setUp fails (unlike tearDown).   z>descriptor 'addCleanup' of 'TestCase' object needs an argumentr-   r   Nz4Passing 'function' as keyword argument is deprecated)
stacklevelz:addCleanup expected at least 1 positional argument, got %dr   )	r   ra   r1   r   warnDeprecationWarningrQ   r   r   )r.   r/   r   r-   r   r   r   r   
addCleanup  s"    

 
zTestCase.addCleanupz%($self, function, /, *args, **kwargs)c                O   s   | j |||f dS )zpSame as addCleanup, except the cleanup items are called even if
        setUpClass fails (unlike tearDownClass).N)_class_cleanupsr   )clsr-   r.   r/   r   r   r   addClassCleanup  s    zTestCase.addClassCleanupc                 C   s   dS )zAHook method for setting up the test fixture before exercising it.Nr   ri   r   r   r   setUp  s    zTestCase.setUpc                 C   s   dS )zAHook method for deconstructing the test fixture after testing it.Nr   ri   r   r   r   tearDown  s    zTestCase.tearDownc                 C   s   dS )zKHook method for setting up class fixture before running tests in the class.Nr   r   r   r   r   
setUpClass  s    zTestCase.setUpClassc                 C   s   dS )zVHook method for deconstructing the class fixture after running all tests in the class.Nr   r   r   r   r   tearDownClass  s    zTestCase.tearDownClassc                 C   s   dS )Nr   r   ri   r   r   r   countTestCases  s    zTestCase.countTestCasesc                 C   s   t  S r)   )r   Z
TestResultri   r   r   r   defaultTestResult	  s    zTestCase.defaultTestResultc                 C   s$   | j }|r | dd  S dS )zReturns a one-line description of the test, or None if no
        description has been provided.

        The default implementation of this method returns the first line of
        the specified test method's docstring.
        
r   N)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   ri   r   r   r   id  s    zTestCase.idc                 C   s    t | t |k	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   ri   r   r   r   __hash__   s    zTestCase.__hash__c                 C   s   d| j t| jf S Nz%s (%s))r   r   r   ri   r   r   r   __str__#  s    zTestCase.__str__c                 C   s   dt | j| jf S )Nz<%s testMethod=%s>r   ri   r   r   r   __repr__&  s    zTestCase.__repr__c                 C   s<   t |dd }|d k	r ||| ntdtd || d S )NaddSkipz4TestResult has no addSkip method, skips not reportedr   )r   r   r   RuntimeWarning
addSuccess)r   r   r#   r9   r   r   r   r   _addSkip*  s     zTestCase._addSkipc              	   k   s   | j dks| j jsdV  dS | j}|dkr4t|}n|j|}t| ||| _zX| j j| jdd dV  W 5 Q R X | j js| j j	}|dk	r|j
rtn| j jrtW 5 || _X dS )aP  Return a context manager that will return the enclosed block
        of code in a subtest identified by the optional message and
        keyword parameters.  A failure in the subtest marks the test
        case as failed but resumes execution at the end of the enclosed
        block, allowing further test code to be executed.
        NTr$   )r   r   r   r   params	new_child_SubTestr&   r   r   Zfailfastr   r   )r   rW   r   parentZ
params_mapr   r   r   r   subTest3  s$    
zTestCase.subTestc                 C   s`   |D ]V\}}t |tr(||j|| q|d k	rt|d | jrN||| q||| qd S )Nr   )r;   r   r   r#   rS   rX   
addFailureZaddError)r   r   r   testr"   r   r   r   _feedErrorsToResultR  s    
zTestCase._feedErrorsToResultc                 C   sD   z
|j }W n* tk
r4   tdt ||  Y nX || | d S )Nz@TestResult has no addExpectedFailure method, reporting as passes)addExpectedFailurere   r   r   r   r   )r   r   r"   r   r   r   r   _addExpectedFailure\  s    
zTestCase._addExpectedFailurec                 C   sh   z
|j }W nP tk
rZ   tdt z
td W n$ tk
rT   || t  Y nX Y n
X ||  d S )NzCTestResult has no addUnexpectedSuccess method, reporting as failure)	addUnexpectedSuccessre   r   r   r   r   r   r!   r"   )r   r   r   r   r   r   _addUnexpectedSuccessf  s    

zTestCase._addUnexpectedSuccessc                 C   s   |    d S r)   )r   ri   r   r   r   
_callSetUpu  s    zTestCase._callSetUpc                 C   s
   |  d S r)   r   )r   methodr   r   r   _callTestMethodx  s    zTestCase._callTestMethodc                 C   s   |    d S r)   )r   ri   r   r   r   _callTearDown{  s    zTestCase._callTearDownc                O   s   ||| d S r)   r   r   r-   r.   r/   r   r   r   _callCleanup~  s    zTestCase._callCleanupNc              
   C   s  |}|d kr.|   }t|dd }|d k	r.|  ||  t| | j}t| jdds^t|ddrz,t| jddpxt|dd}| || | W 5 ||  X d S t|dd}t| dd}|p|}t|}	z|	| _|	|  |   W 5 Q R X |	jr@||	_|	j| dd	 | | W 5 Q R X d|	_|	|  |   W 5 Q R X |   |	jD ]\}}| ||| qN| ||	j |	jr|r|	j
r| ||	j
 n
| | n
||  |W S ||  |d krt|dd }
|
d k	r|
  |	j	  d |	_
d | _X d S )
NstartTestRunr?   Fr@   rC   rK   stopTestRunTr   )r   r   Z	startTestr   r   ZstopTestr   r   r   clearr   r   r&   r   r   r   r   r   
doCleanupsr   r   r   r   r   )r   r   Zorig_resultr   r   Zskip_whyZexpecting_failure_methodZexpecting_failure_classr   outcomer   r   r9   r   r   r   run  st    


  




zTestCase.runc              	   C   sR   | j p
t }| jrL| j \}}}||  | j|f|| W 5 Q R X q|jS )zNExecute all cleanup functions. Normally called for you after
        tearDown.)r   r   r   r1   r&   r   r   )r   r   r-   r.   r/   r   r   r   r     s    zTestCase.doCleanupsc              
   C   sd   g | _ | jr`| j \}}}z||| W q tk
r\ } z| j t  W 5 d}~X Y qX qdS )zYExecute all class cleanup functions. Normally called for you after
        tearDownClass.N)ZtearDown_exceptionsr   r1   r2   r   r!   r"   )r   r-   r.   r/   r4   r   r   r   doClassCleanups  s    zTestCase.doClassCleanupsc                 O   s   | j ||S r)   )r   )r   r.   kwdsr   r   r   __call__  s    zTestCase.__call__c                 C   sF   |    t| | j  |   | jrB| jd\}}}||| qdS )z6Run the test without collecting errors in a TestResultN)r   r   r   r   r   r1   r   r   r   r   debug  s    zTestCase.debugc                 C   s   t |dS )zSkip this test.Nr6   )r   r9   r   r   r   skipTest  s    zTestCase.skipTestc                 C   s   |  |dS )z)Fail immediately, with the given message.N)rX   )r   rW   r   r   r   fail  s    zTestCase.failc                 C   s&   |r"|  |dt| }| |dS )z#Check that the expression is false.z%s is not falseNrV   r   rX   r   exprrW   r   r   r   assertFalse  s    zTestCase.assertFalsec                 C   s&   |s"|  |dt| }| |dS )z"Check that the expression is true.z%s is not trueNr  r  r   r   r   
assertTrue  s    zTestCase.assertTruec                 C   sV   | j s|p|S |dkr|S zd||f W S  tk
rP   dt|t|f  Y S X dS )a  Honour the longMessage attribute when generating failure messages.
        If longMessage is False this means:
        * Use only an explicit message if it is provided
        * Otherwise use the standard message for the assert

        If longMessage is True:
        * Use the standard message
        * If an explicit message is provided, plus ' : ' and the explicit message
        Nz%s : %s)longMessageUnicodeDecodeErrorr   )r   rW   rY   r   r   r   rV     s    
zTestCase._formatMessagec                 O   s(   t || }z|d||W S d}X dS )a=  Fail unless an exception of class expected_exception is raised
           by the callable when invoked with specified positional and
           keyword arguments. If a different type of exception is
           raised, it will not be caught, and the test case will be
           deemed to have suffered an error, exactly as for an
           unexpected exception.

           If called with the callable and arguments omitted, will return a
           context object used like this::

                with self.assertRaises(SomeException):
                    do_something()

           An optional keyword argument 'msg' can be provided when assertRaises
           is used as a context object.

           The context manager keeps a reference to the exception as
           the 'exception' attribute. This allows you to inspect the
           exception after the assertion::

               with self.assertRaises(SomeException) as cm:
                   do_something()
               the_exception = cm.exception
               self.assertEqual(the_exception.error_code, 3)
        NassertRaisesrh   rg   )r   expected_exceptionr.   r/   contextr   r   r   r    s    
zTestCase.assertRaisesc                 O   s   t || }|d||S )a  Fail unless a warning of class warnClass is triggered
           by the callable when invoked with specified positional and
           keyword arguments.  If a different type of warning is
           triggered, it will not be handled: depending on the other
           warning filtering rules in effect, it might be silenced, printed
           out, or raised as an exception.

           If called with the callable and arguments omitted, will return a
           context object used like this::

                with self.assertWarns(SomeWarning):
                    do_something()

           An optional keyword argument 'msg' can be provided when assertWarns
           is used as a context object.

           The context manager keeps a reference to the first matching
           warning as the 'warning' attribute; similarly, the 'filename'
           and 'lineno' attributes give you information about the line
           of Python code from which the warning was triggered.
           This allows you to inspect the warning after the assertion::

               with self.assertWarns(SomeWarning) as cm:
                   do_something()
               the_warning = cm.warning
               self.assertEqual(the_warning.some_attribute, 147)
        assertWarnsrx   rg   )r   expected_warningr.   r/   r  r   r   r   r  5  s    
zTestCase.assertWarnsc                 C   s   t | ||S )a  Fail unless a log message of level *level* or higher is emitted
        on *logger_name* or its children.  If omitted, *level* defaults to
        INFO and *logger* defaults to the root logger.

        This method must be used as a context manager, and will yield
        a recording object with two attributes: `output` and `records`.
        At the end of the context manager, the `output` attribute will
        be a list of the matching formatted log messages and the
        `records` attribute will be a list of the corresponding LogRecord
        objects.

        Example::

            with self.assertLogs('foo', level='INFO') as cm:
                logging.getLogger('foo').info('first message')
                logging.getLogger('foo.bar').error('second message')
            self.assertEqual(cm.output, ['INFO:foo:first message',
                                         'ERROR:foo.bar:second message'])
        )r   )r   r   r   r   r   r   
assertLogsT  s    zTestCase.assertLogsc                 C   sF   t |t |kr@| jt |}|dk	r@t|tr<t| |}|S | jS )a  Get a detailed comparison function for the types of the two args.

        Returns: A callable accepting (first, second, msg=None) that will
        raise a failure exception if first != second with a useful human
        readable error message for those types.
        N)r<   r   r   r;   r    r   _baseAssertEqual)r   firstsecondZasserterr   r   r   _getAssertEqualityFuncj  s    

zTestCase._getAssertEqualityFuncc                 C   s0   ||ks,dt || }| ||}| |dS )z:The default assertEqual implementation, not type specific.%s != %sN)r   rV   rX   )r   r  r  rW   rY   r   r   r   r    s    zTestCase._baseAssertEqualc                 C   s   |  ||}||||d dS )z[Fail if the two objects are unequal as determined by the '=='
           operator.
        )rW   N)r  )r   r  r  rW   Zassertion_funcr   r   r   assertEqual  s    zTestCase.assertEqualc                 C   s2   ||ks.|  |dt|t|f }| |dS )zYFail if the two objects are equal as determined by the '!='
           operator.
        z%s == %sNr  )r   r  r  rW   r   r   r   assertNotEqual  s
    zTestCase.assertNotEqualc                 C   s   ||krdS |dk	r$|dk	r$t dt|| }|dk	rf||krDdS dt|t|t|t|f }n:|dkrrd}t||dkrdS dt|t||t|f }| ||}| |dS )a'  Fail if the two objects are unequal as determined by their
           difference rounded to the given number of decimal places
           (default 7) and comparing to zero, or by comparing that the
           difference between the two objects is more than the given
           delta.

           Note that decimal places (from zero) are usually not the same
           as significant digits (measured from the most significant digit).

           If the two objects compare equal then they will automatically
           compare almost equal.
        N specify delta or places not bothz(%s != %s within %s delta (%s difference)   r   z)%s != %s within %r places (%s difference)ra   absr   roundrV   rX   r   r  r  ZplacesrW   ZdeltadiffrY   r   r   r   assertAlmostEqual  s4    zTestCase.assertAlmostEqualc                 C   s   |dk	r|dk	rt dt|| }|dk	rb||ks@||kr@dS dt|t|t|t|f }n<|dkrnd}||kst||dkrdS dt|t||f }| ||}| |dS )a  Fail if the two objects are equal as determined by their
           difference rounded to the given number of decimal places
           (default 7) and comparing to zero, or by comparing that the
           difference between the two objects is less than the given delta.

           Note that decimal places (from zero) are usually not the same
           as significant digits (measured from the most significant digit).

           Objects that are equal automatically fail.
        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k	rP|j }t||s.| d|t|f t||sT| d|t|f nd}d}zt|}W n  ttfk
r   d| }Y nX |dkrzt|}W n  ttfk
r   d| }Y nX |dkr||krdS d| ft||  }t	t
||D ]}	z||	 }
W n4 tttfk
r<   |d|	|f 7 }Y  qY nX z||	 }W n4 tttfk
r~   |d	|	|f 7 }Y  qY nX |
|kr|d
|	ft|
|  7 } qq||kr|dkrt|t|krdS ||kr<|d||| f 7 }z|d|t|| f 7 }W n, tttfk
r8   |d||f 7 }Y nX nh||k r|d||| f 7 }z|d|t|| f 7 }W n, tttfk
r   |d||f 7 }Y nX |}ddtt| t|  }| ||}| ||}| | dS )aA  An equality assertion for ordered sequences (like lists and tuples).

        For the purposes of this function, a valid ordered sequence type is one
        which can be indexed, has a length, and has an equality operator.

        Args:
            seq1: The first sequence to compare.
            seq2: The second sequence to compare.
            seq_type: The expected datatype of the sequences, or None if no
                    datatype should be enforced.
            msg: Optional message to use on failure instead of a list of
                    differences.
        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;   rX   r   r   ra   NotImplementedError
capitalizer   rangemin
IndexErrorr<   joindifflibndiffpprintpformat
splitlines_truncateMessagerV   r   )r   Zseq1Zseq2rW   seq_typeZseq_type_nameZ	differingZlen1Zlen2iZitem1Zitem2rY   diffMsgr   r   r   assertSequenceEqual  s    












zTestCase.assertSequenceEqualc                 C   s2   | j }|d kst||kr"|| S |tt|  S r)   )maxDiffr   DIFF_OMITTED)r   r   r  Zmax_diffr   r   r   r+  N  s    zTestCase._truncateMessagec                 C   s   | j |||td dS )a  A list-specific equality assertion.

        Args:
            list1: The first list to compare.
            list2: The second list to compare.
            msg: Optional message to use on failure instead of a list of
                    differences.

        r,  N)r/  r|   )r   Zlist1Zlist2rW   r   r   r   r   T  s    
zTestCase.assertListEqualc                 C   s   | j |||td dS )a  A tuple-specific equality assertion.

        Args:
            tuple1: The first tuple to compare.
            tuple2: The second tuple to compare.
            msg: Optional message to use on failure instead of a list of
                    differences.
        r2  N)r/  rQ   )r   Ztuple1Ztuple2rW   r   r   r   r   `  s    	zTestCase.assertTupleEqualc           
   
   C   s`  z| |}W n^ tk
r> } z| d|  W 5 d}~X Y n0 tk
rl } z| d|  W 5 d}~X Y nX z| |}W n^ tk
r } z| d|  W 5 d}~X Y n0 tk
r } z| d|  W 5 d}~X Y nX |s|sdS g }|r|d |D ]}|t| q |r@|d |D ]}|t| q*d|}	| | ||	 dS )a  A set-specific equality assertion.

        Args:
            set1: The first set to compare.
            set2: The second set to compare.
            msg: Optional message to use on failure instead of a list of
                    differences.

        assertSetEqual uses ducktyping to support different types of sets, and
        is optimized for sets specifically (parameters must support a
        difference method).
        z/invalid type when attempting set difference: %sNz2first 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   )
differencera   r   re   r   reprr%  rV   )
r   Zset1Zset2rW   Zdifference1r%   Zdifference2linesitemrY   r   r   r   r   k  s2      


zTestCase.assertSetEqualc                 C   s2   ||kr.dt |t |f }| | || dS )zDJust like self.assertTrue(a in b), but with a nicer default message.z%s not found in %sNr   r   rV   r   memberZ	containerrW   rY   r   r   r   assertIn  s
    zTestCase.assertInc                 C   s2   ||kr.dt |t |f }| | || dS )zHJust like self.assertTrue(a not in b), but with a nicer default message.z%s unexpectedly found in %sNr7  r8  r   r   r   assertNotIn  s
    zTestCase.assertNotInc                 C   s2   ||k	r.dt |t |f }| | || dS )zDJust like self.assertTrue(a is b), but with a nicer default message.z%s is not %sNr7  r   Zexpr1Zexpr2rW   rY   r   r   r   assertIs  s
    zTestCase.assertIsc                 C   s,   ||kr(dt |f }| | || dS )zHJust like self.assertTrue(a is not b), but with a nicer default message.zunexpectedly identical: %sNr7  r<  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   rV   )r   Zd1Zd2rW   rY   r  r   r   r   r     s    
zTestCase.assertDictEqualc           	   	   C   s   t dt g }g }| D ]L\}}||k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 )z2Checks whether dictionary is a superset of subset.z&assertDictContainsSubset is deprecatedz%s, expected: %s, actual: %sNrC   zMissing: %s,c                 s   s   | ]}t |V  qd S r)   )r   )rM   r   r   r   r   rP     s     z4TestCase.assertDictContainsSubset.<locals>.<genexpr>z; zMismatched values: %s)	r   r   r   itemsr   r   r%  r   rV   )	r   ZsubsetZ
dictionaryrW   ZmissingZ
mismatchedkeyvaluerY   r   r   r   assertDictContainsSubset  s4    

z!TestCase.assertDictContainsSubsetc           
      C   s   t |t | }}zt|}t|}W n tk
rH   t||}Y nX ||krVdS t||}|rd}dd |D }d|}	| ||	}| ||}| 	| dS )a[  Asserts that two iterables have the same elements, the same number of
        times, without regard to order.

            self.assertEqual(Counter(list(first)),
                             Counter(list(second)))

         Example:
            - [0, 1, 1] and [1, 0, 1] compare equal.
            - [0, 0, 1] and [0, 1] compare unequal.

        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>  s     z-TestCase.assertCountEqual.<locals>.<listcomp>r   )
r|   collectionsCounterra   r   r   r%  r+  rV   r   )
r   r  r  rW   Z	first_seqZ
second_seqZdifferencesrY   r5  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 )z-Assert that two multi-line strings are equal.zFirst argument is not a stringzSecond argument is not a stringT)keependsr   z
r   r  rC   N)r?  r    r   _diffThresholdr  r*  r   r   r%  r&  r'  r+  r   rV   )r   r  r  rW   Z
firstlinesZsecondlinesrY   r  r   r   r   r     s     

zTestCase.assertMultiLineEqualc                 C   s2   ||k s.dt |t |f }| | || dS )zCJust like self.assertTrue(a < b), but with a nicer default message.z%s not less than %sNr7  r   abrW   rY   r   r   r   
assertLess  s    zTestCase.assertLessc                 C   s2   ||ks.dt |t |f }| | || dS )zDJust like self.assertTrue(a <= b), but with a nicer default message.z%s not less than or equal to %sNr7  rK  r   r   r   assertLessEqual  s    zTestCase.assertLessEqualc                 C   s2   ||ks.dt |t |f }| | || dS )zCJust like self.assertTrue(a > b), but with a nicer default message.z%s not greater than %sNr7  rK  r   r   r   assertGreater  s    zTestCase.assertGreaterc                 C   s2   ||ks.dt |t |f }| | || dS )zDJust like self.assertTrue(a >= b), but with a nicer default message.z"%s not greater than or equal to %sNr7  rK  r   r   r   assertGreaterEqual   s    zTestCase.assertGreaterEqualc                 C   s,   |dk	r(dt |f }| | || dS )zCSame as self.assertTrue(obj is None), with a nicer default message.Nz%s is not Noner7  r   r*   rW   rY   r   r   r   assertIsNone&  s    zTestCase.assertIsNonec                 C   s"   |dkrd}|  | || dS )z(Included for symmetry with assertIsNone.Nzunexpectedly None)r   rV   rR  r   r   r   assertIsNotNone,  s    zTestCase.assertIsNotNonec                 C   s0   t ||s,dt||f }| | || dS )zTSame as self.assertTrue(isinstance(obj, cls)), with a nicer
        default message.z%s is not an instance of %rNr;   r   r   rV   r   r*   r   rW   rY   r   r   r   r?  2  s    
zTestCase.assertIsInstancec                 C   s0   t ||r,dt||f }| | || dS )z,Included for symmetry with assertIsInstance.z%s is an instance of %rNrU  rV  r   r   r   assertNotIsInstance9  s    
zTestCase.assertNotIsInstancec                 O   s   t || |}|d||S )a  Asserts that the message in a raised exception matches a regex.

        Args:
            expected_exception: Exception class expected to be raised.
            expected_regex: Regex (re.Pattern object or string) expected
                    to be found in error message.
            args: Function to be called and extra positional args.
            kwargs: Extra kwargs.
            msg: Optional message used in case of failure. Can only be used
                    when assertRaisesRegex is used as a context manager.
        assertRaisesRegexr	  )r   r
  r^   r.   r/   r  r   r   r   rX  ?  s    zTestCase.assertRaisesRegexc                 O   s   t || |}|d||S )a  Asserts that the message in a triggered warning matches a regexp.
        Basic functioning is similar to assertWarns() with the addition
        that only warnings whose messages also match the regular expression
        are considered successful matches.

        Args:
            expected_warning: Warning class expected to be triggered.
            expected_regex: Regex (re.Pattern object or string) expected
                    to be found in error message.
            args: Function to be called and extra positional args.
            kwargs: Extra kwargs.
            msg: Optional message used in case of failure. Can only be used
                    when assertWarnsRegex is used as a context manager.
        assertWarnsRegexr  )r   r  r^   r.   r/   r  r   r   r   rY  O  s    zTestCase.assertWarnsRegexc                 C   sV   t |ttfr$|stdt|}||sRd|j|f }| ||}| 	|dS )z=Fail the test unless the text matches the regular expression.z!expected_regex must not be empty.z&Regex didn't match: %r not found in %rN)
r;   r    bytesAssertionErrorr\   r]   rp   rq   rV   rX   )r   textr^   rW   rY   r   r   r   assertRegexb  s    

 zTestCase.assertRegexc                 C   s`   t |ttfrt|}||}|r\d|| |  |j|f }| 	||}| 
|dS )z9Fail the test if the text matches the regular expression.z"Regex matched: %r matches %r in %rN)r;   r    rZ  r\   r]   rp   startendrq   rV   rX   )r   r\  Zunexpected_regexrW   matchrY   r   r   r   assertNotRegexn  s    

zTestCase.assertNotRegexc                    s    fdd}|S )Nc                     s    t d jtd  | |S )NzPlease use {0} instead.r   )r   r   rl   r   r   r7   original_funcr   r   deprecated_func~  s    
 z,TestCase._deprecate.<locals>.deprecated_funcr   )rc  rd  r   rb  r   
_deprecate}  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)er   r   r   r   r[  rX   r  r0  rJ  Z_classSetupFailedr   r   r   r   __text_signature__classmethodr   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  rV   r  r  r  r  r  r  r  r  r  r/  r+  r   r   r   r:  r;  r=  r>  r   rD  rH  r   rN  rO  rP  rQ  rS  rT  r?  rW  rX  rY  r]  ra  re  ZfailUnlessEqualZassertEqualsZfailIfEqualZassertNotEqualsZfailUnlessAlmostEqualZassertAlmostEqualsZfailIfAlmostEqualZassertNotAlmostEqualsZ
failUnlessZassert_ZfailUnlessRaisesZfailIfZassertRaisesRegexpZassertRegexpMatchesZassertNotRegexpMatchesr   r   r   r   r   w  s    
 


	


E
	


!



	  
-  
#
c


+






 










	r   c                       sj   e Zd 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 )FunctionTestCaseaI  A test case that wraps a test function.

    This is useful for slipping pre-existing test functions into the
    unittest framework. Optionally, set-up and tidy-up functions can be
    supplied. As with TestCase, the tidy-up ('tearDown') function will
    always be called if the set-up ('setUp') function ran successfully.
    Nc                    s*   t t|   || _|| _|| _|| _d S r)   )superri  r   
_setUpFunc_tearDownFunc	_testFunc_description)r   ZtestFuncr   r   Zdescriptionr   r   r   r     s
    zFunctionTestCase.__init__c                 C   s   | j d k	r|    d S r)   )rk  ri   r   r   r   r     s    
zFunctionTestCase.setUpc                 C   s   | j d k	r|    d S r)   )rl  ri   r   r   r   r     s    
zFunctionTestCase.tearDownc                 C   s   |    d S r)   )rm  ri   r   r   r   r     s    zFunctionTestCase.runTestc                 C   s   | j jS r)   )rm  r   ri   r   r   r   r     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   rk  rl  rm  rn  r   r   r   r   r     s    


zFunctionTestCase.__eq__c                 C   s   t t| | j| j| j| jfS r)   )r   r<   rk  rl  rm  rn  ri   r   r   r   r     s     zFunctionTestCase.__hash__c                 C   s   dt | j| jjf S r   )r   r   rm  r   ri   r   r   r   r     s    
zFunctionTestCase.__str__c                 C   s   dt | j| jf S )Nz<%s tec=%s>)r   r   rm  ri   r   r   r   r     s    
zFunctionTestCase.__repr__c                 C   s2   | j d k	r| j S | jj}|r.|dd  p0d S )Nr   r   )rn  rm  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   r   __classcell__r   r   ro  r   ri    s   	ri  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)   )rj  r   _messager#   r   rX   )r   r#   r   r   ro  r   r   r     s
    
z_SubTest.__init__c                 C   s   t dd S )Nzsubtests cannot be run directly)r   ri   r   r   r   r     s    z_SubTest.runTestc                 C   s^   g }| j tk	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)rl   )rM   r   r   r   r   r   rP     s   z+_SubTest._subDescription.<locals>.<genexpr>z({}) z(<subtest>))rq  rh  r   rl   r   r%  rA  )r   partsZparams_descr   r   r   _subDescription  s    

z_SubTest._subDescriptionc                 C   s   d | j |  S Nz{} {})rl   r#   r   rt  ri   r   r   r   r     s    z_SubTest.idc                 C   s
   | j  S )zlReturns a one-line description of the subtest, or None if no
        description has been provided.
        )r#   r   ri   r   r   r   r     s    z_SubTest.shortDescriptionc                 C   s   d | j|  S ru  )rl   r#   rt  ri   r   r   r   r     s    z_SubTest.__str__)
r   r   r   r   r   rt  r   r   r   rp  r   r   ro  r   r     s   r   )4r   r!   r=   r&  r   r(  r\   r   rF  r'   rm   rD   rC   r   utilr   r   r   r   r   Z
__unittestobjectrh  r1  r2   r	   r   r   r   r+   r,   r0   r5   rF   rI   rJ   r   rL   rU   r[   rh   rx   
namedtupler   r   r   r   ChainMapr   r   ri  r   r   r   r   r   <module>   sd   (	*%5,
        $:                                                                                                                                                                                                          result.cpython-38.opt-1.pyc                                                                         0000644                 00000016175 15175327600 0011471 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   s\   d Z ddlZddlZddlZddlmZ ddlmZ dZdd Z	d	Z
d
ZG dd deZdS )zTest result object    N   )utilwrapsTc                    s   t   fdd}|S )Nc                    s$   t | ddr|    | f||S )NfailfastF)getattrstop)selfargskwmethod '/usr/lib64/python3.8/unittest/result.pyinner   s    zfailfast.<locals>.innerr   )r   r   r   r   r   r      s    r   z
Stdout:
%sz
Stderr:
%sc                   @   s   e Zd ZdZdZdZdZd.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dd Zedd Zdd Zdd Zdd Z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S )/
TestResulta  Holder for test result information.

    Test results are automatically managed by the TestCase and TestSuite
    classes, and do not need to be explicitly manipulated by writers of tests.

    Each instance holds the total number of tests run, and collections of
    failures and errors that occurred among those test runs. The collections
    contain tuples of (testcase, exceptioninfo), where exceptioninfo is the
    formatted traceback of the error that occurred.
    NFc                 C   sb   d| _ g | _g | _d| _g | _g | _g | _d| _d| _d| _	d | _
d | _tj| _tj| _d| _d S )NFr   )r   failureserrorstestsRunskippedexpectedFailuresunexpectedSuccesses
shouldStopbuffer	tb_locals_stdout_buffer_stderr_buffersysstdout_original_stdoutstderr_original_stderr_mirrorOutput)r	   streamZdescriptions	verbosityr   r   r   __init__&   s    zTestResult.__init__c                 C   s   dS )z#Called by TestRunner after test runNr   r	   r   r   r   printErrors7   s    zTestResult.printErrorsc                 C   s    |  j d7  _ d| _|   dS )z-Called when the given test is about to be runr   FN)r   r"   _setupStdoutr	   testr   r   r   	startTest:   s    zTestResult.startTestc                 C   s8   | j r4| jd kr$t | _t | _| jt_| jt_d S )N)r   r   ioStringIOr   r   r   r    r&   r   r   r   r(   @   s    


zTestResult._setupStdoutc                 C   s   dS )zpCalled once before any tests are executed.

        See startTest for a method called before each test.
        Nr   r&   r   r   r   startTestRunH   s    zTestResult.startTestRunc                 C   s   |    d| _dS )z'Called when the given test has been runFN)_restoreStdoutr"   r)   r   r   r   stopTestN   s    zTestResult.stopTestc                 C   s   | j r| jrltj }tj }|rF|ds6|d7 }| jt	|  |rl|ds\|d7 }| j
t|  | jt_| j
t_| jd | j  | jd | j  d S )N
r   )r   r"   r   r   getvaluer    endswithr   writeSTDOUT_LINEr!   STDERR_LINEr   seektruncater   )r	   outputerrorr   r   r   r/   S   s$    




zTestResult._restoreStdoutc                 C   s   dS )zmCalled once after all tests are executed.

        See stopTest for a method called after each test.
        Nr   r&   r   r   r   stopTestRunh   s    zTestResult.stopTestRunc                 C   s"   | j || ||f d| _dS )zmCalled when an error has occurred. 'err' is a tuple of values as
        returned by sys.exc_info().
        TN)r   append_exc_info_to_stringr"   r	   r*   errr   r   r   addErrorn   s    zTestResult.addErrorc                 C   s"   | j || ||f d| _dS )zdCalled when an error has occurred. 'err' is a tuple of values as
        returned by sys.exc_info().TN)r   r<   r=   r"   r>   r   r   r   
addFailurev   s    zTestResult.addFailurec                 C   sZ   |dk	rVt | ddr|   t|d |jr4| j}n| j}||| ||f d| _dS )zCalled at the end of a subtest.
        'err' is None if the subtest ended successfully, otherwise it's a
        tuple of values as returned by sys.exc_info().
        Nr   Fr   T)	r   r   
issubclassfailureExceptionr   r   r<   r=   r"   )r	   r*   Zsubtestr?   r   r   r   r   
addSubTest}   s    zTestResult.addSubTestc                 C   s   dS )z-Called when a test has completed successfullyNr   r)   r   r   r   
addSuccess   s    zTestResult.addSuccessc                 C   s   | j ||f dS )zCalled when a test is skipped.N)r   r<   )r	   r*   reasonr   r   r   addSkip   s    zTestResult.addSkipc                 C   s   | j || ||f dS )z/Called when an expected failure/error occurred.N)r   r<   r=   r>   r   r   r   addExpectedFailure   s    zTestResult.addExpectedFailurec                 C   s   | j | dS )z5Called when a test was expected to fail, but succeed.N)r   r<   r)   r   r   r   addUnexpectedSuccess   s    zTestResult.addUnexpectedSuccessc                 C   s>   t | jt | j  kodkn  o<t| d p<t | jdkS )z/Tells whether or not this result was a success.r   r   )lenr   r   hasattrr   r&   r   r   r   wasSuccessful   s    $zTestResult.wasSuccessfulc                 C   s
   d| _ dS )z+Indicates that the tests should be aborted.TN)r   r&   r   r   r   r      s    zTestResult.stopc                 C   s   |\}}}|r |  |r |j}q
||jkr6| |}nd}tj||||| jd}t| }| j	rt
j }	t
j }
|	r|	ds|	d7 }	|t|	  |
r|
ds|
d7 }
|t|
  d|S )z>Converts a sys.exc_info()-style tuple of values into a string.N)limitcapture_localsr1    )_is_relevant_tb_leveltb_nextrC   _count_relevant_tb_levels	tracebackTracebackExceptionr   listformatr   r   r   r2   r    r3   r<   r5   r6   join)r	   r?   r*   exctypevaluetblengthZtb_eZmsgLinesr9   r:   r   r   r   r=      s4    

    



zTestResult._exc_info_to_stringc                 C   s   d|j jkS )N
__unittest)tb_frame	f_globals)r	   rZ   r   r   r   rP      s    z TestResult._is_relevant_tb_levelc                 C   s&   d}|r"|  |s"|d7 }|j}q|S )Nr   r   )rP   rQ   )r	   rZ   r[   r   r   r   rR      s
    z$TestResult._count_relevant_tb_levelsc                 C   s&   dt | j| jt| jt| jf S )Nz!<%s run=%i errors=%i failures=%i>)r   Zstrclass	__class__r   rJ   r   r   r&   r   r   r   __repr__   s
    zTestResult.__repr__)NNN)__name__
__module____qualname____doc__Z_previousTestClassZ_testRunEnteredZ_moduleSetUpFailedr%   r'   r+   r(   r.   r0   r/   r;   r   r@   rA   rD   rE   rG   rH   rI   rL   r   r=   rP   rR   r`   r   r   r   r   r      s8   




	r   )rd   r,   r   rS   rO   r   	functoolsr   r\   r   r5   r6   objectr   r   r   r   r   <module>   s                                                                                                                                                                                                                                                                                                                                                                                                      __main__.cpython-38.opt-1.pyc                                                                       0000644                 00000000621 15175327600 0011660 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   s`   d Z ddlZejd drBddlZejejZed ejd< [dZ	ddl
m
Z
 e
dd dS )	zMain entry point    Nz__main__.pyz -m unittestT   )main)module)__doc__sysargvendswithZos.pathospathbasename
executableZ
__unittestr    r   r   )/usr/lib64/python3.8/unittest/__main__.py<module>   s                                                                                                                  case.cpython-38.opt-2.pyc                                                                           0000644                 00000104730 15175327600 0011062 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   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
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(e)d'd(d)gZ*G d*d+ d+ej+Z,G d,d- d-e%Z-G d.d/ d/ej.Z/G d0d1 d1eZ0G d2d3 d3e0Z1G d4d5 d5e0Z2dS )6    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/lib64/python3.8/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k
r.    Y n tk
rh } zd| _ | j|t|f W 5 d }~X Y nj tk
rz   Y nX   t }| j	r|| _
nd| _ | j||f d }Y nX | jr| j r| j|d f W 5 | j o|| _ X d S )NTF)r   KeyboardInterruptr	   r   appendstrr   sysexc_infor   r   r   r   )r   	test_caseisTestZold_successer!   r   r   r   testPartExecutor7   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   _idU   s    r*   c                O   s   t | ||f d S r(   )_module_cleanupsr   )functionargskwargsr   r   r   addModuleCleanupZ   s    r/   c               
   C   sd   g } t rTt  \}}}z||| W q tk
rP } z| | W 5 d }~X Y qX q| r`| 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_wrapperv   s    z-skip.<locals>.decorator.<locals>.skip_wrapperT)
isinstancetype	functoolswraps__unittest_skip____unittest_skip_why__)	test_itemr:   r8   r   r   	decoratort   s    
zskip.<locals>.decorator )r;   typesFunctionType)r9   rB   rA   r   r8   r   skipp   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>   s     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   standardMsgrW   r   r   r   _raiseFailure   s    z"_BaseTestCaseContext._raiseFailureN)r   r   r   r   rZ   r   r   r   r   rU      s   rU   c                   @   s   e Zd ZdddZdd ZdS )_AssertRaisesBaseContextNc                 C   s@   t | | || _|| _|d k	r*t|}|| _d | _d | _d S r(   )	rU   r   rT   r"   recompileexpected_regexobj_namerW   )r   rT   r"   r^   r   r   r   r      s    
z!_AssertRaisesBaseContext.__init__c              	   C   s   zt | j| js"td|| jf |sV|dd | _|rNtdtt|f | W TS |^}}z|j	| _
W n tk
r   t|| _
Y nX |  ||| W 5 Q R X W 5 d } X d S )Nz%s() arg 1 must be %srW   z3%r is an invalid keyword argument for this function)rL   rT   
_base_type	TypeError_base_type_strr1   rW   nextiterr   r_   AttributeErrorr   )r   namer-   r.   Zcallable_objr   r   r   handle   s(    z_AssertRaisesBaseContext.handle)N)r   r   r   r   rg   r   r   r   r   r[      s   

r[   c                   @   s$   e Zd ZeZdZdd Zdd 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 krbz| j j}W n tk
r2   t| j }Y nX | jrP| d|| j ql| d| n
t| t	|| j s|dS |
d | _| jd krdS | j}|t|s| d|jt| dS )Nz{} not raised by {}z{} not raisedFT"{}" does not match "{}")rT   r   re   r   r_   rZ   format	tracebackclear_framesrS   with_tracebackZ	exceptionr^   searchpattern)r   exc_type	exc_valuetbexc_namer^   r   r   r   __exit__   s.    


 z_AssertRaisesContext.__exit__N)r   r   r   BaseExceptionr`   rb   rj   rv   r   r   r   r   rh      s   rh   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getattrry   warningscatch_warningswarnings_managerrj   simplefilterrT   )r   vr   r   r   rj      s    z_AssertWarnsContext.__enter__c                 C   s   | j ||| |d k	rd S z| jj}W n tk
rF   t| j}Y nX d }| jD ]Z}|j}t|| jsjqR|d krv|}| j	d k	r| j	
t|sqR|| _|j| _|j| _ d S |d k	r| d| j	jt| | jr| d|| j n| d| d S )Nrk   z{} not triggered by {}z{} not triggered)r   rv   rT   r   re   r   r   messager;   r^   rp   ZwarningfilenamelinenorZ   rl   rq   r_   )r   rr   rs   rt   ru   Zfirst_matchingmwr   r   r   rv     s@    

 
z_AssertWarnsContext.__exit__N)r   r   r   Warningr`   rb   rj   rv   r   r   r   r   rx      s   rx   _LoggingWatcherrecordsoutputc                   @   s$   e Zd Zdd Zdd Zdd ZdS )_CapturingHandlerc                 C   s   t j|  tg g | _d S r(   )loggingHandlerr   r   watcherri   r   r   r   r   3  s    z_CapturingHandler.__init__c                 C   s   d S r(   r   ri   r   r   r   flush7  s    z_CapturingHandler.flushc                 C   s*   | j j| | |}| j j| d S r(   )r   r   r   rl   r   )r   rz   rW   r   r   r   emit:  s    
z_CapturingHandler.emitN)r   r   r   r   r   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S )	_AssertLogsContextz"%(levelname)s:%(name)s:%(message)sc                 C   s:   t | | || _|r(tj||| _ntj| _d | _d S r(   )	rU   r   logger_namer   Z_nameToLevelgetlevelINFOrW   )r   r"   r   r   r   r   r   r   F  s    z_AssertLogsContext.__init__c                 C   s   t | jtjr| j }| _nt| j }| _t| j}t }|	| |j
| _
|jd d  | _|j| _|j| _|g|_|| j d|_|j
S )NF)r;   r   r   ZLoggerloggerZ	getLoggerZ	FormatterLOGGING_FORMATr   ZsetFormatterr   handlersold_handlersr   	old_level	propagateold_propagatesetLevel)r   r   Z	formatterZhandlerr   r   r   rj   O  s    
z_AssertLogsContext.__enter__c                 C   s`   | j | j_| j| j_| j| j |d k	r.dS t| jj	dkr\| 
dt| j| jj d S )NFr   z-no logs of level {} or higher triggered on {})r   r   r   r   r   r   r   lenr   r   rZ   rl   r   ZgetLevelNamer   rf   )r   rr   rs   rt   r   r   r   rv   `  s    


 z_AssertLogsContext.__exit__N)r   r   r   r   r   rj   rv   r   r   r   r   r   A  s   	r   c                   @   s   e Zd Zdd ZdS )_OrderedChainMapc                 c   s8   t  }| jD ]&}|D ]}||kr|| |V  qqd S r(   )setmapsadd)r   seenmappingkr   r   r   __iter__n  s    

z_OrderedChainMap.__iter__N)r   r   r   r   r   r   r   r   r   m  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de_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/d0 Z#d1d2 Z$d3d4 Z%d5d6 Z&d7d8 Z'dd:d;Z(d<d= Z)ed>d? Z*d@dA Z+dBdC Z,dDdE Z-ddFdGZ.ddHdIZ/ddJdKZ0dLdM Z1dNdO Z2dPdQ Z3ddRdSZ4dTdU Z5ddVdWZ6ddXdYZ7ddZd[Z8dd\d]Z9dd^d_Z:dd`daZ;dbdc Z<ddddeZ=ddfdgZ>ddhdiZ?ddjdkZ@ddldmZAddndoZBddpdqZCddrdsZDddtduZEddvdwZFddxdyZGddzd{ZHdd|d}ZIdd~dZJdddZKdddZLdddZMdddZNdddZOdd ZPdd ZQdddZRdddZSdd ZTeTe7 ZUZVeTe8 ZWZXeTe9 ZYZZeTe: Z[Z\eTe0 Z]Z^eTe2Z_eTe/Z`eTePZaeTeRZbeTeSZcd9S )TestCaseTi  i   FrunTestc                 C   s   || _ d | _d| _zt| |}W n. tk
rN   |dkrJtd| j|f Y n
X |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   re   
ValueError	__class____doc__	_cleanups_subtest_type_equality_funcsaddTypeEqualityFuncdictr|   rQ   r   	frozensetr   )r   Z
methodName
testMethodr   r   r   r     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   t | dkr| ^}}} nV| s&tdnHd|krZ|d}| ^}} dd l}|jdtdd ntdt | d  t| } |j|| |f d S )	N   z>descriptor 'addCleanup' of 'TestCase' object needs an argumentr,   r   z4Passing 'function' as keyword argument is deprecated)
stacklevelz:addCleanup expected at least 1 positional argument, got %dr   )	r   ra   r1   r   warnDeprecationWarningrQ   r   r   )r-   r.   r   r,   r   r   r   r   
addCleanup  s"    

 
zTestCase.addCleanupz%($self, function, /, *args, **kwargs)c                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   ri   r   r   r   setUp  s    zTestCase.setUpc                 C   s   d S r(   r   ri   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   ri   r   r   r   countTestCases  s    zTestCase.countTestCasesc                 C   s   t  S r(   )r   Z
TestResultri   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   ri   r   r   r   id  s    zTestCase.idc                 C   s    t | t |k	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   ri   r   r   r   __hash__   s    zTestCase.__hash__c                 C   s   d| j t| jf S Nz%s (%s))r   r   r   ri   r   r   r   __str__#  s    zTestCase.__str__c                 C   s   dt | j| jf S )Nz<%s testMethod=%s>r   ri   r   r   r   __repr__&  s    zTestCase.__repr__c                 C   s<   t |dd }|d k	r ||| ntdtd || d S )NaddSkipz4TestResult has no addSkip method, skips not reportedr   )r   r   r   RuntimeWarning
addSuccess)r   r   r"   r9   r   r   r   r   _addSkip*  s     zTestCase._addSkipc              	   k   s   | j d ks| j jsd V  d S | j}|d kr4t|}n|j|}t| ||| _zX| j j| jdd d V  W 5 Q R X | j js| j j	}|d k	r|j
rtn| j jrtW 5 || _X d S )NTr#   )r   r   r   r   params	new_child_SubTestr%   r   r   Zfailfastr   r   )r   rW   r   parentZ
params_mapr   r   r   r   subTest3  s$    
zTestCase.subTestc                 C   s`   |D ]V\}}t |tr(||j|| q|d k	rt|d | jrN||| q||| qd S r0   )r;   r   r   r"   rS   rX   
addFailureZaddError)r   r   r   testr!   r   r   r   _feedErrorsToResultR  s    
zTestCase._feedErrorsToResultc                 C   sD   z
|j }W n* tk
r4   tdt ||  Y nX || | d S )Nz@TestResult has no addExpectedFailure method, reporting as passes)addExpectedFailurere   r   r   r   r   )r   r   r!   r   r   r   r   _addExpectedFailure\  s    
zTestCase._addExpectedFailurec                 C   sh   z
|j }W nP tk
rZ   tdt z
td W n$ tk
rT   || t  Y nX Y n
X ||  d S )NzCTestResult has no addUnexpectedSuccess method, reporting as failure)	addUnexpectedSuccessre   r   r   r   r   r   r    r!   )r   r   r   r   r   r   _addUnexpectedSuccessf  s    

zTestCase._addUnexpectedSuccessc                 C   s   |    d S r(   )r   ri   r   r   r   
_callSetUpu  s    zTestCase._callSetUpc                 C   s
   |  d S r(   r   )r   methodr   r   r   _callTestMethodx  s    zTestCase._callTestMethodc                 C   s   |    d S r(   )r   ri   r   r   r   _callTearDown{  s    zTestCase._callTearDownc                O   s   ||| d S r(   r   r   r,   r-   r.   r   r   r   _callCleanup~  s    zTestCase._callCleanupNc              
   C   s  |}|d kr.|   }t|dd }|d k	r.|  ||  t| | j}t| jdds^t|ddrz,t| jddpxt|dd}| || | W 5 ||  X d S t|dd}t| dd}|p|}t|}	z|	| _|	|  |   W 5 Q R X |	jr@||	_|	j| dd	 | | W 5 Q R X d|	_|	|  |   W 5 Q R X |   |	jD ]\}}| ||| qN| ||	j |	jr|r|	j
r| ||	j
 n
| | n
||  |W S ||  |d krt|dd }
|
d k	r|
  |	j	  d |	_
d | _X d S )
NstartTestRunr?   Fr@   rC   rK   stopTestRunTr   )r   r   Z	startTestr   r   ZstopTestr   r   r   clearr   r   r%   r   r   r   r   r   
doCleanupsr   r   r   r   r   )r   r   Zorig_resultr   r   Zskip_whyZexpecting_failure_methodZexpecting_failure_classr   outcomer   r   r9   r   r   r   run  st    


  




zTestCase.runc              	   C   sR   | j p
t }| jrL| j \}}}||  | j|f|| W 5 Q R X q|jS r(   )r   r   r   r1   r%   r   r   )r   r   r,   r-   r.   r   r   r   r     s    zTestCase.doCleanupsc              
   C   sd   g | _ | jr`| j \}}}z||| W q tk
r\ } z| j t  W 5 d }~X Y qX qd S r(   )ZtearDown_exceptionsr   r1   r2   r   r    r!   )r   r,   r-   r.   r4   r   r   r   doClassCleanups  s    zTestCase.doClassCleanupsc                 O   s   | j ||S r(   )r   )r   r-   kwdsr   r   r   __call__  s    zTestCase.__call__c                 C   sF   |    t| | j  |   | jrB| jd\}}}||| qd S )N)r   r   r   r   r   r1   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(   )rX   )r   rW   r   r   r   fail  s    zTestCase.failc                 C   s&   |r"|  |dt| }| |d S )Nz%s is not falserV   r   rX   r   exprrW   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   sV   | j s|p|S |d kr|S zd||f W S  tk
rP   dt|t|f  Y S X d S )Nz%s : %s)longMessageUnicodeDecodeErrorr   )r   rW   rY   r   r   r   rV     s    
zTestCase._formatMessagec                 O   s(   t || }z|d||W S d }X d S )NassertRaisesrh   rg   )r   expected_exceptionr-   r.   contextr   r   r   r
    s    
zTestCase.assertRaisesc                 O   s   t || }|d||S )NassertWarnsrx   rg   )r   expected_warningr-   r.   r  r   r   r   r  5  s    
zTestCase.assertWarnsc                 C   s   t | ||S r(   )r   )r   r   r   r   r   r   
assertLogsT  s    zTestCase.assertLogsc                 C   sF   t |t |kr@| jt |}|d k	r@t|tr<t| |}|S | jS r(   )r<   r   r   r;   r   r   _baseAssertEqual)r   firstsecondZasserterr   r   r   _getAssertEqualityFuncj  s    

zTestCase._getAssertEqualityFuncc                 C   s0   ||ks,dt || }| ||}| |d S )N%s != %s)r   rV   rX   )r   r  r  rW   rY   r   r   r   r    s    zTestCase._baseAssertEqualc                 C   s   |  ||}||||d d S )N)rW   )r  )r   r  r  rW   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  rW   r   r   r   assertNotEqual  s
    zTestCase.assertNotEqualc                 C   s   ||krd S |d k	r$|d k	r$t dt|| }|d k	rf||krDd S dt|t|t|t|f }n:|d k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)ra   absr   roundrV   rX   r   r  r  ZplacesrW   ZdeltadiffrY   r   r   r   assertAlmostEqual  s4    zTestCase.assertAlmostEqualc                 C   s   |d k	r|d k	rt dt|| }|d k	rb||ks@||kr@d S dt|t|t|t|f }n<|d k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 k	rP|j }t||s.| d|t|f t||sT| d|t|f nd}d }zt|}W n  ttfk
r   d| }Y nX |d krzt|}W n  ttfk
r   d| }Y nX |d kr||krd S d| ft||  }t	t
||D ]}	z||	 }
W n4 tttfk
r<   |d|	|f 7 }Y  qY nX z||	 }W n4 tttfk
r~   |d|	|f 7 }Y  qY nX |
|kr|d	|	ft|
|  7 } qq||kr|d krt|t|krd S ||kr<|d
||| f 7 }z|d|t|| f 7 }W n, tttfk
r8   |d||f 7 }Y nX nh||k r|d||| f 7 }z|d|t|| f 7 }W n, tttfk
r   |d||f 7 }Y nX |}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;   rX   r   r   ra   NotImplementedError
capitalizer   rangemin
IndexErrorr<   joindifflibndiffpprintpformat
splitlines_truncateMessagerV   r  )r   Zseq1Zseq2rW   seq_typeZseq_type_nameZ	differingZlen1Zlen2iZitem1Zitem2rY   diffMsgr   r   r   assertSequenceEqual  s    












zTestCase.assertSequenceEqualc                 C   s2   | j }|d kst||kr"|| S |tt|  S r(   )maxDiffr   DIFF_OMITTED)r   r   r  Zmax_diffr   r   r   r-  N  s    zTestCase._truncateMessagec                 C   s   | j |||td d S N)r.  )r1  r|   )r   Zlist1Zlist2rW   r   r   r   r   T  s    
zTestCase.assertListEqualc                 C   s   | j |||td d S r4  )r1  rQ   )r   Ztuple1Ztuple2rW   r   r   r   r   `  s    	zTestCase.assertTupleEqualc           
   
   C   s`  z| |}W n^ tk
r> } z| d|  W 5 d }~X Y n0 tk
rl } z| d|  W 5 d }~X Y nX z| |}W n^ tk
r } z| d|  W 5 d }~X Y n0 tk
r } z| d|  W 5 d }~X Y nX |s|sd S g }|r|d |D ]}|t| q |r@|d |D ]}|t| q*d|}	| | ||	 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   )
differencera   r  re   r   reprr'  rV   )
r   Zset1Zset2rW   Zdifference1r$   Zdifference2linesitemrY   r   r   r   r   k  s2      


zTestCase.assertSetEqualc                 C   s2   ||kr.dt |t |f }| | || d S )Nz%s not found in %sr   r  rV   r   memberZ	containerrW   rY   r   r   r   assertIn  s
    zTestCase.assertInc                 C   s2   ||kr.dt |t |f }| | || d S )Nz%s unexpectedly found in %sr9  r:  r   r   r   assertNotIn  s
    zTestCase.assertNotInc                 C   s2   ||k	r.dt |t |f }| | || d S )Nz%s is not %sr9  r   Zexpr1Zexpr2rW   rY   r   r   r   assertIs  s
    zTestCase.assertIsc                 C   s,   ||kr(dt |f }| | || d S )Nzunexpectedly identical: %sr9  r>  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  rV   )r   Zd1Zd2rW   rY   r  r   r   r   r     s    
zTestCase.assertDictEqualc           	   	   C   s   t dt g }g }| D ]L\}}||k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     s     z4TestCase.assertDictContainsSubset.<locals>.<genexpr>z; zMismatched values: %s)	r   r   r   itemsr   r   r'  r  rV   )	r   ZsubsetZ
dictionaryrW   ZmissingZ
mismatchedkeyvaluerY   r   r   r   assertDictContainsSubset  s4    

z!TestCase.assertDictContainsSubsetc           
      C   s   t |t | }}zt|}t|}W n tk
rH   t||}Y nX ||krVd 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>  s     z-TestCase.assertCountEqual.<locals>.<listcomp>r   )
r|   collectionsCounterra   r   r   r'  r-  rV   r  )
r   r  r  rW   Z	first_seqZ
second_seqZdifferencesrY   r7  r0  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   )rA  r   r   _diffThresholdr  r,  r   r   r'  r(  r)  r-  r  rV   )r   r  r  rW   Z
firstlinesZsecondlinesrY   r  r   r   r   r     s     

zTestCase.assertMultiLineEqualc                 C   s2   ||k s.dt |t |f }| | || d S )Nz%s not less than %sr9  r   abrW   rY   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 %sr9  rM  r   r   r   assertLessEqual  s    zTestCase.assertLessEqualc                 C   s2   ||ks.dt |t |f }| | || d S )Nz%s not greater than %sr9  rM  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 %sr9  rM  r   r   r   assertGreaterEqual   s    zTestCase.assertGreaterEqualc                 C   s,   |d k	r(dt |f }| | || d S )Nz%s is not Noner9  r   r)   rW   rY   r   r   r   assertIsNone&  s    zTestCase.assertIsNonec                 C   s"   |d krd}|  | || d S )Nzunexpectedly None)r  rV   rT  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  rV   r   r)   r   rW   rY   r   r   r   rA  2  s    
zTestCase.assertIsInstancec                 C   s0   t ||r,dt||f }| | || d S )Nz%s is an instance of %rrW  rX  r   r   r   assertNotIsInstance9  s    
zTestCase.assertNotIsInstancec                 O   s   t || |}|d||S )NassertRaisesRegexr  )r   r  r^   r-   r.   r  r   r   r   rZ  ?  s    zTestCase.assertRaisesRegexc                 O   s   t || |}|d||S )NassertWarnsRegexr  )r   r  r^   r-   r.   r  r   r   r   r[  O  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]   rp   rq   rV   rX   )r   textr^   rW   rY   r   r   r   assertRegexb  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   r\  r\   r]   rp   startendrq   rV   rX   )r   r]  Zunexpected_regexrW   matchrY   r   r   r   assertNotRegexn  s    

zTestCase.assertNotRegexc                    s    fdd}|S )Nc                     s    t d jtd  | |S )NzPlease use {0} instead.r   )r   r   rl   r   r   r7   original_funcr   r   deprecated_func~  s    
 z,TestCase._deprecate.<locals>.deprecated_funcr   )rd  re  r   rc  r   
_deprecate}  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)dr   r   r   AssertionErrorrX   r  r2  rL  Z_classSetupFailedr   r   r   r   __text_signature__classmethodr   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  rV   r
  r  r  r  r  r  r  r   r!  r1  r-  r   r   r   r<  r=  r?  r@  r   rF  rJ  r   rP  rQ  rR  rS  rU  rV  rA  rY  rZ  r[  r^  rb  rf  ZfailUnlessEqualZassertEqualsZfailIfEqualZassertNotEqualsZfailUnlessAlmostEqualZassertAlmostEqualsZfailIfAlmostEqualZassertNotAlmostEqualsZ
failUnlessZassert_ZfailUnlessRaisesZfailIfZassertRaisesRegexpZassertRegexpMatchesZassertNotRegexpMatchesr   r   r   r   r   w  s   !
 


	


E
	


!



	  
-  
#
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(   )superrk  r   
_setUpFunc_tearDownFunc	_testFunc_description)r   ZtestFuncr   r   Zdescriptionr   r   r   r     s
    zFunctionTestCase.__init__c                 C   s   | j d k	r|    d S r(   )rm  ri   r   r   r   r     s    
zFunctionTestCase.setUpc                 C   s   | j d k	r|    d S r(   )rn  ri   r   r   r   r     s    
zFunctionTestCase.tearDownc                 C   s   |    d S r(   )ro  ri   r   r   r   r     s    zFunctionTestCase.runTestc                 C   s   | j jS r(   )ro  r   ri   r   r   r   r     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   rm  rn  ro  rp  r   r   r   r   r     s    


zFunctionTestCase.__eq__c                 C   s   t t| | j| j| j| jfS r(   )r   r<   rm  rn  ro  rp  ri   r   r   r   r     s     zFunctionTestCase.__hash__c                 C   s   dt | j| jjf S r   )r   r   ro  r   ri   r   r   r   r     s    
zFunctionTestCase.__str__c                 C   s   dt | j| jf S )Nz<%s tec=%s>)r   r   ro  ri   r   r   r   r     s    
zFunctionTestCase.__repr__c                 C   s2   | j d k	r| j S | jj}|r.|dd  p0d S r   )rp  ro  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   rq  r   rk    s   		rk  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(   )rl  r   _messager"   r   rX   )r   r"   r   r   rq  r   r   r     s
    
z_SubTest.__init__c                 C   s   t dd S )Nzsubtests cannot be run directly)r"  ri   r   r   r   r     s    z_SubTest.runTestc                 C   s^   g }| j tk	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)rl   )rM   r   r   r   r   r   rP     s   z+_SubTest._subDescription.<locals>.<genexpr>z({}) z(<subtest>))rs  rj  r   rl   r   r'  rC  )r   partsZparams_descr   r   r   _subDescription  s    

z_SubTest._subDescriptionc                 C   s   d | j |  S Nz{} {})rl   r"   r   rv  ri   r   r   r   r     s    z_SubTest.idc                 C   s
   | j  S r(   )r"   r   ri   r   r   r   r     s    z_SubTest.shortDescriptionc                 C   s   d | j|  S rw  )rl   r"   rv  ri   r   r   r   r     s    z_SubTest.__str__)
r   r   r   r   r   rv  r   r   r   rr  r   r   rq  r   r     s   r   )3r    r=   r(  r   r*  r\   r   rH  r&   rm   rD   rC   r   utilr   r   r   r   r   Z
__unittestobjectrj  r3  r2   r	   r   r   r   r*   r+   r/   r5   rF   rI   rJ   r   rL   rU   r[   rh   rx   
namedtupler   r   r   r   ChainMapr   r   rk  r   r   r   r   r   <module>   sb   (	*%5,
        $:                                        __main__.cpython-38.opt-2.pyc                                                                       0000644                 00000000560 15175327600 0011663 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   s\   d dl Z e jd  dr>d dlZeje jZed e jd < [dZddl	m	Z	 e	dd dS )    Nz__main__.pyz -m unittestT   )main)module)
sysargvendswithZos.pathospathbasename
executableZ
__unittestr    r   r   )/usr/lib64/python3.8/unittest/__main__.py<module>   s                                                                                                                                                   util.cpython-38.opt-2.pyc                                                                           0000644                 00000007070 15175327600 0011123 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d_                     @   s   d dl mZmZ d dlmZ dZdZdZdZdZ	dZ
eee e
 e e	  Zdd Zd	d
 ZdddZdd Zdd Zdd Zdd ZeddZdd Zdd ZdS )    )
namedtupleCounter)commonprefixTP         c                 C   sB   t | | | }|tkr>d| d | || t | | d  f } | S )Nz%s[%d chars]%s)len_PLACEHOLDER_LEN)s	prefixlenZ	suffixlenskip r   %/usr/lib64/python3.8/unittest/util.py_shorten   s    &r   c                     s   t tt| } ttt| }|tkr(| S t|  t t| t t  }|t	krxt
 t| t  fdd| D S t
 tt	 t  fdd| D S )Nc                 3   s   | ]} |d   V  qd S Nr   .0r
   prefixr   r   r   	<genexpr>'   s     z'_common_shorten_repr.<locals>.<genexpr>c                 3   s&   | ]} t |d  tt V  qd S r   )r   _MIN_DIFF_LEN_MIN_END_LENr   r   r   r   r   *   s   )tuplemap	safe_reprmaxr   _MAX_LENGTHr   _MIN_BEGIN_LENr	   _MIN_COMMON_LENr   )argsmaxlenZ
common_lenr   r   r   _common_shorten_repr   s     r!   Fc                 C   sP   zt | }W n tk
r*   t| }Y nX |r<t|tk r@|S |d t d S )Nz [truncated]...)repr	Exceptionobject__repr__r   r   )objZshortresultr   r   r   r   -   s    r   c                 C   s   d| j | jf S )Nz%s.%s)
__module____qualname__)clsr   r   r   strclass6   s    r+   c                 C   s  d }}g }g }z| | }|| }||k rT| | |d7 }| | |kr|d7 }q<nv||kr| | |d7 }|| |kr|d7 }qnnD|d7 }z| | |kr|d7 }qW 5 |d7 }|| |kr|d7 }qX W q tk
r   || |d   |||d   Y qY qX q||fS Nr      )append
IndexErrorextend)expectedactualijmissingZ
unexpectedear   r   r   sorted_list_difference9   s8    

r8   c                 C   sH   g }| r@|   }z|| W q tk
r<   || Y qX q||fS r   )popremove
ValueErrorr.   )r1   r2   r5   itemr   r   r   unorderable_list_differenceb   s    r=   c                 C   s   | |k| |k  S r   r   )xyr   r   r   three_way_cmps   s    r@   ZMismatchzactual expected valuec                 C   s,  t | t | }}t|t| }}t }g }t|D ]\}}	|	|krHq6d }
}t||D ] }|| |	krZ|
d7 }
|||< qZt|D ] \}}||	kr|d7 }|||< q|
|kr6t|
||	}|| q6t|D ]X\}}	|	|krqd}t||D ] }|| |	kr|d7 }|||< qtd||	}|| q|S r,   )listr   r$   	enumeraterange	_Mismatchr.   )r2   r1   r
   tmnZNULLr'   r3   elemcnt_scnt_tr4   Z
other_elemdiffr   r   r   _count_diff_all_purposey   s<    


rL   c           	      C   s   t | t | }}g }| D ]2\}}||d}||krt|||}|| q| D ]&\}}||krZtd||}|| qZ|S )Nr   )r   itemsgetrD   r.   )	r2   r1   r
   rE   r'   rH   rI   rJ   rK   r   r   r   _count_diff_hashable   s    rO   N)F)collectionsr   r   Zos.pathr   Z
__unittestr   r	   r   r   r   r   r   r!   r   r+   r8   r=   r@   rD   rL   rO   r   r   r   r   <module>   s0   

	)
#                                                                                                                                                                                                                                                                                                                                                                                                                                                                        suite.cpython-38.opt-2.pyc                                                                          0000644                 00000021331 15175327600 0011273 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d2                     @   sx   d dl Z ddlmZ ddlmZ dZdd ZG dd	 d	eZG d
d deZG dd deZ	dd Z
G dd deZdS )    N   )case)utilTc                 C   s   t | |dd }|  d S )Nc                   S   s   d S N r   r   r   &/usr/lib64/python3.8/unittest/suite.py<lambda>       z!_call_if_exists.<locals>.<lambda>)getattr)parentattrfuncr   r   r   _call_if_exists   s    r   c                   @   sj   e Zd ZdZd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S )BaseTestSuiteTr   c                 C   s   g | _ d| _| | d S Nr   )_tests_removed_testsaddTests)selftestsr   r   r   __init__   s    zBaseTestSuite.__init__c                 C   s   dt | jt| f S )Nz<%s tests=%s>)r   strclass	__class__listr   r   r   r   __repr__   s    zBaseTestSuite.__repr__c                 C   s    t || jstS t| t|kS r   )
isinstancer   NotImplementedr   )r   otherr   r   r   __eq__   s    zBaseTestSuite.__eq__c                 C   s
   t | jS r   )iterr   r   r   r   r   __iter__"   s    zBaseTestSuite.__iter__c                 C   s$   | j }| D ]}|r
|| 7 }q
|S r   )r   countTestCases)r   Zcasestestr   r   r   r"   %   s
    zBaseTestSuite.countTestCasesc                 C   sL   t |stdt|t|tr<t|tjt	fr<td| j
| d S )Nz{} is not callablezNTestCases and TestSuites must be instantiated before passing them to addTest())callable	TypeErrorformatreprr   type
issubclassr   ZTestCase	TestSuiter   appendr   r#   r   r   r   addTest,   s    zBaseTestSuite.addTestc                 C   s*   t |trtd|D ]}| | qd S )Nz0tests must be an iterable of tests, not a string)r   strr%   r-   )r   r   r#   r   r   r   r   6   s    
zBaseTestSuite.addTestsc                 C   s8   t | D ]*\}}|jr q4|| | jr| | q|S r   )	enumerate
shouldStop_cleanup_removeTestAtIndex)r   resultindexr#   r   r   r   run<   s    zBaseTestSuite.runc                 C   sN   z| j | }W n tk
r"   Y n(X t|dr@|  j| 7  _d | j |< d S )Nr"   )r   r%   hasattrr   r"   )r   r4   r#   r   r   r   r2   E   s    
z BaseTestSuite._removeTestAtIndexc                 O   s   | j ||S r   r5   )r   argskwdsr   r   r   __call__S   s    zBaseTestSuite.__call__c                 C   s   | D ]}|   qd S r   )debugr,   r   r   r   r;   V   s    zBaseTestSuite.debugN)r   )__name__
__module____qualname__r1   r   r   r   r!   r"   r-   r   r5   r2   r:   r;   r   r   r   r   r      s   

	r   c                   @   sZ   e Zd ZdddZdd Zdd Zdd	 Zd
d ZdddZdddZ	dd Z
dd ZdS )r*   Fc                 C   s   d}t |dddkrd |_}t| D ]\}}|jr8 qt|r| || | || | || |j|_	t |jdds&t |ddrq&|s|| n|
  | jr&| | q&|r| d | | | d|_|S )NF_testRunEnteredT_classSetupFailed_moduleSetUpFailed)r
   r?   r/   r0   _isnotsuite_tearDownPreviousClass_handleModuleFixture_handleClassSetUpr   _previousTestClassr;   r1   r2   _handleModuleTearDown)r   r3   r;   ZtopLevelr4   r#   r   r   r   r5   f   s2    



zTestSuite.runc                 C   s   t  }| |d d S )NT)_DebugResultr5   )r   r;   r   r   r   r;      s    zTestSuite.debugc           	      C   s2  t |dd }|j}||krd S |jr(d S t |ddr8d S z
d|_W n tk
rV   Y nX t |dd }|d k	r.t|d z^z
|  W nN t
k
r } z0t|tr d|_t|}| 	||d| W 5 d }~X Y nX W 5 t|d |jdkr,|  t|jdkr,|jD ]}| j	||d	 d||d
 qX d S )NrF   __unittest_skip__F
setUpClass_setupStdout_restoreStdoutTr   r   info)r
   r   rA   r@   r%   r   doClassCleanupslentearDown_exceptions"_createClassOrModuleLevelException	Exceptionr   rH   r   r   )	r   r#   r3   previousClasscurrentClassrJ   exc	classNameer   r   r   rE      sL    







   zTestSuite._handleClassSetUpc                 C   s"   d }t |dd }|d k	r|j}|S )NrF   )r
   r=   )r   r3   previousModulerT   r   r   r   _get_previous_module   s
    zTestSuite._get_previous_modulec           	      C   s  |  |}|jj}||krd S | | d|_ztj| }W n tk
rR   Y d S X t|dd }|d k	rt	|d zz
|  W n t
k
r } zfzt  W n2 t
k
r } z| ||d| W 5 d }~X Y nX t|tr d|_| ||d| W 5 d }~X Y nX W 5 t	|d X d S )NFsetUpModulerK   rL   T)rZ   r   r=   rG   rA   sysmodulesKeyErrorr
   r   rS   r   doModuleCleanupsrR   r   rH   )	r   r#   r3   rY   ZcurrentModulemoduler[   rX   rV   r   r   r   rD      s>    





zTestSuite._handleModuleFixtureNc                 C   s$   | d| d}|  |||| d S )Nz ())_addClassOrModuleLevelException)r   r3   rV   Zmethod_namer   rN   	errorNamer   r   r   rR      s    z,TestSuite._createClassOrModuleLevelExceptionc                 C   s^   t |}t|dd }|d k	r8t|tjr8||t| n"|sN||t  n||| d S )NaddSkip)	_ErrorHolderr
   r   r   ZSkipTestr.   ZaddErrorr\   exc_info)r   r3   Z	exceptionrc   rN   errorrd   r   r   r   rb      s    z)TestSuite._addClassOrModuleLevelExceptionc                 C   s  |  |}|d krd S |jr d S ztj| }W n tk
rD   Y d S X t|dd }|d k	rt|d zNz
|  W n> t	k
r } z t|tr | 
||d| W 5 d }~X Y nX W 5 t|d zt  W n4 t	k
r  } z| 
||d| W 5 d }~X Y nX X d S )NtearDownModulerK   rL   )rZ   rA   r\   r]   r^   r
   r   r   r_   rS   rR   r   rH   )r   r3   rY   r`   rh   rX   r   r   r   rG      s:    





zTestSuite._handleModuleTearDownc           	      C   s  t |dd }|j}||krd S t |ddr.d S t |ddr>d S t |ddrNd S t |dd }|d k	rt|d zXz
|  W nH t	k
r } z*t
|tr t|}| ||d| W 5 d }~X Y nX W 5 t|d |  t|jd	kr|jD ]&}t|}| j||d
 d||d qX d S )NrF   r@   FrA   rI   tearDownClassrK   rL   r   r   rM   )r
   r   r   rO   rP   rQ   r   r   rR   rS   r   rH   )	r   r#   r3   rT   rU   ri   rV   rW   rX   r   r   r   rC     sB    







z TestSuite._tearDownPreviousClass)F)N)N)r<   r=   r>   r5   r;   rE   rZ   rD   rR   rb   rG   rC   r   r   r   r   r*   \   s   

!($ 
 
 r*   c                   @   sP   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S )re   Nc                 C   s
   || _ d S r   description)r   rk   r   r   r   r   B  s    z_ErrorHolder.__init__c                 C   s   | j S r   rj   r   r   r   r   idE  s    z_ErrorHolder.idc                 C   s   d S r   r   r   r   r   r   shortDescriptionH  s    z_ErrorHolder.shortDescriptionc                 C   s   d| j f S )Nz<ErrorHolder description=%r>rj   r   r   r   r   r   K  s    z_ErrorHolder.__repr__c                 C   s   |   S r   )rl   r   r   r   r   __str__N  s    z_ErrorHolder.__str__c                 C   s   d S r   r   r   r3   r   r   r   r5   Q  s    z_ErrorHolder.runc                 C   s
   |  |S r   r7   ro   r   r   r   r:   V  s    z_ErrorHolder.__call__c                 C   s   dS r   r   r   r   r   r   r"   Y  s    z_ErrorHolder.countTestCases)r<   r=   r>   ZfailureExceptionr   rl   rm   r   rn   r5   r:   r"   r   r   r   r   re   6  s   
re   c                 C   s(   zt |  W n tk
r"   Y dS X dS )NTF)r    r%   )r#   r   r   r   rB   \  s
    rB   c                   @   s   e Zd ZdZdZdZdS )rH   NF)r<   r=   r>   rF   rA   r0   r   r   r   r   rH   e  s   rH   )r\    r   r   Z
__unittestr   objectr   r*   re   rB   rH   r   r   r   r   <module>   s   L [&	                                                                                                                                                                                                                                                                                                       runner.cpython-38.opt-2.pyc                                                                         0000644                 00000014403 15175327600 0011455 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dW                     @   sj   d dl Z d dlZd dlZddlmZ ddlmZ dZG dd deZ	G dd	 d	ej
ZG d
d deZdS )    N   )result)registerResultTc                   @   s&   e Zd Zdd Zdd ZdddZdS )	_WritelnDecoratorc                 C   s
   || _ d S N)stream)selfr    r	   '/usr/lib64/python3.8/unittest/runner.py__init__   s    z_WritelnDecorator.__init__c                 C   s   |dkrt |t| j|S )N)r   __getstate__)AttributeErrorgetattrr   )r   attrr	   r	   r
   __getattr__   s    z_WritelnDecorator.__getattr__Nc                 C   s   |r|  | |  d d S N
)write)r   argr	   r	   r
   writeln   s    
z_WritelnDecorator.writeln)N)__name__
__module____qualname__r   r   r   r	   r	   r	   r
   r      s   r   c                       s   e Zd ZdZdZ fddZdd Z fddZ fd	d
Z fddZ	 fddZ
 fddZ fddZ fddZdd Zdd Z  ZS )TextTestResultzF======================================================================zF----------------------------------------------------------------------c                    s8   t t| ||| || _|dk| _|dk| _|| _d S )Nr   )superr   r   r   showAlldotsdescriptions)r   r   r   	verbosity	__class__r	   r
   r   %   s
    

zTextTestResult.__init__c                 C   s0   |  }| jr$|r$dt||fS t|S d S r   )ZshortDescriptionr   joinstr)r   testZdoc_first_liner	   r	   r
   getDescription,   s    
zTextTestResult.getDescriptionc                    sB   t t| | | jr>| j| | | jd | j  d S )Nz ... )r   r   	startTestr   r   r   r$   flushr   r#   r   r	   r
   r%   3   s
    zTextTestResult.startTestc                    sD   t t| | | jr$| jd n| jr@| jd | j  d S )Nok.)	r   r   
addSuccessr   r   r   r   r   r&   r'   r   r	   r
   r*   :   s    zTextTestResult.addSuccessc                    sF   t t| || | jr&| jd n| jrB| jd | j  d S )NERRORE)	r   r   addErrorr   r   r   r   r   r&   r   r#   errr   r	   r
   r-   B   s    zTextTestResult.addErrorc                    sF   t t| || | jr&| jd n| jrB| jd | j  d S )NFAILF)	r   r   
addFailurer   r   r   r   r   r&   r.   r   r	   r
   r2   J   s    zTextTestResult.addFailurec                    sL   t t| || | jr,| jd| n| jrH| jd | j	  d S )Nzskipped {0!r}s)
r   r   addSkipr   r   r   formatr   r   r&   )r   r#   reasonr   r	   r
   r4   R   s    zTextTestResult.addSkipc                    sF   t t| || | jr&| jd n| jrB| jd | j  d S )Nzexpected failurex)	r   r   addExpectedFailurer   r   r   r   r   r&   r.   r   r	   r
   r8   Z   s    z!TextTestResult.addExpectedFailurec                    sD   t t| | | jr$| jd n| jr@| jd | j  d S )Nzunexpected successu)	r   r   addUnexpectedSuccessr   r   r   r   r   r&   r'   r   r	   r
   r:   b   s    z#TextTestResult.addUnexpectedSuccessc                 C   s6   | j s| jr| j  | d| j | d| j d S )Nr+   r0   )r   r   r   r   printErrorListerrorsfailuresr   r	   r	   r
   printErrorsj   s    
zTextTestResult.printErrorsc                 C   sX   |D ]N\}}| j | j | j d|| |f  | j | j | j d|  qd S )Nz%s: %sz%s)r   r   
separator1r$   
separator2)r   Zflavourr<   r#   r/   r	   r	   r
   r;   p   s
    zTextTestResult.printErrorList)r   r   r   r@   rA   r   r$   r%   r*   r-   r2   r4   r8   r:   r?   r;   __classcell__r	   r	   r   r
   r      s   r   c                   @   s0   e Zd ZeZdddddZdd	 Zd
d ZdS )TextTestRunnerNTr   F)	tb_localsc          	      C   sN   |d krt j}t|| _|| _|| _|| _|| _|| _|| _	|d k	rJ|| _
d S r   )sysstderrr   r   r   r   failfastbufferrD   warningsresultclass)	r   r   r   r   rG   rH   rJ   rI   rD   r	   r	   r
   r      s    
zTextTestRunner.__init__c                 C   s   |  | j| j| jS r   )rJ   r   r   r   r>   r	   r	   r
   _makeResult   s    zTextTestRunner._makeResultc                 C   s2  |   }t| | j|_| j|_| j|_t  | jr^t| j | jdkr^tjdt	dd t
 }t|dd }|d k	r|  z|| W 5 t|dd }|d k	r|  X t
 }W 5 Q R X || }|  t|dr| j|j |j}| jd||d	kod
pd|f  | j  d }	 }
}ztt|j|j|jf}W n tk
rT   Y nX |\}	}
}g }| s| jd t|jt|j }}|r|d|  |r|d|  n| jd |r|d|  |	r|d|	  |
r|d|
  |r"| jdd|f  n| jd |S )N)defaultalwaysmodulezPlease use assert\w+ instead.)categorymessagestartTestRunstopTestRunrA   zRan %d test%s in %.3fsr   r3    r   ZFAILEDzfailures=%dz	errors=%dZOKz
skipped=%dzexpected failures=%dzunexpected successes=%dz (%s)z, r   )rK   r   rG   rH   rD   rI   catch_warningssimplefilterfilterwarningsDeprecationWarningtimeperf_counterr   r?   hasattrr   r   rA   ZtestsRunmaplenZexpectedFailuresunexpectedSuccessesskippedr   ZwasSuccessfulr   r=   r<   appendr!   )r   r#   r   Z	startTimerQ   rR   ZstopTimeZ	timeTakenrunZexpectedFailsr]   r^   ZresultsZinfosZfailedZerroredr	   r	   r
   r`      sx    






zTextTestRunner.run)NTr   FFNN)r   r   r   r   rJ   r   rK   r`   r	   r	   r	   r
   rC   x   s           rC   )rE   rX   rI   rS   r   Zsignalsr   Z
__unittestobjectr   Z
TestResultr   rC   r	   r	   r	   r
   <module>   s   [                                                                                                                                                                                                                                                             async_case.cpython-38.opt-1.pyc                                                                     0000644                 00000010005 15175327600 0012245 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   s0   d dl Z d dlZddlmZ G dd deZdS )    N   )TestCasec                       s   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dd Zdd Zdd Zd  fdd	Z  ZS )!IsolatedAsyncioTestCaserunTestc                    s   t  | d | _d | _d S N)super__init___asyncioTestLoop_asyncioCallsQueue)selfZ
methodName	__class__ +/usr/lib64/python3.8/unittest/async_case.pyr   "   s    z IsolatedAsyncioTestCase.__init__c                    s   d S r   r   r   r   r   r   
asyncSetUp'   s    z"IsolatedAsyncioTestCase.asyncSetUpc                    s   d S r   r   r   r   r   r   asyncTearDown*   s    z%IsolatedAsyncioTestCase.asyncTearDownc                O   s   | j |f|| d S r   )Z
addCleanup)r   funcargskwargsr   r   r   addAsyncCleanup-   s    z'IsolatedAsyncioTestCase.addAsyncCleanupc                 C   s   |    | | j d S r   )ZsetUp
_callAsyncr   r   r   r   r   
_callSetUp<   s    z"IsolatedAsyncioTestCase._callSetUpc                 C   s   |  | d S r   _callMaybeAsync)r   methodr   r   r   _callTestMethod@   s    z'IsolatedAsyncioTestCase._callTestMethodc                 C   s   |  | j |   d S r   )r   r   ZtearDownr   r   r   r   _callTearDownC   s    z%IsolatedAsyncioTestCase._callTearDownc                 O   s   | j |f|| d S r   r   )r   Zfunctionr   r   r   r   r   _callCleanupG   s    z$IsolatedAsyncioTestCase._callCleanupc                O   s0   |||}| j  }| j||f | j |S r   )r	   create_futurer
   
put_nowaitrun_until_completer   r   r   r   retfutr   r   r   r   J   s    

z"IsolatedAsyncioTestCase._callAsyncc                O   sB   |||}t |r:| j }| j||f | j|S |S d S r   )inspectZisawaitabler	   r   r
   r    r!   r"   r   r   r   r   R   s    


z'IsolatedAsyncioTestCase._callMaybeAsyncc              
      s   t   | _}|d  | I d H }|  |d kr:d S |\}}z |I d H }| s`|| W q ttfk
r|    Y q t	t j
fk
r } z| s|| W 5 d }~X Y qX qd S r   )asyncioZQueuer
   Z
set_resultgetZ	task_done	cancelled
SystemExitKeyboardInterruptBaseExceptionZCancelledErrorZset_exception)r   r$   ZqueueZqueryZ	awaitabler#   Zexr   r   r   _asyncioLoopRunner\   s     

z*IsolatedAsyncioTestCase._asyncioLoopRunnerc                 C   sJ   t  }t | |d || _| }|| || _|	| d S )NT)
r&   Znew_event_loopset_event_loopZ	set_debugr	   r   Zcreate_taskr,   Z_asyncioCallsTaskr!   )r   loopr$   r   r   r   _setupAsyncioLoopo   s    

z)IsolatedAsyncioTestCase._setupAsyncioLoopc              	   C   s   | j }d | _ | jd  || j  zt|}|s@W vd S |D ]}|	  qD|tj
||dd |D ]0}| r|qn| d k	rn|d| |d qn||  W 5 td  |  X d S )NT)r.   Zreturn_exceptionsz(unhandled exception during test shutdown)message	exceptiontask)r	   r
   r    r!   joinr&   r-   closeZ	all_tasksZcancelZgatherr(   r1   Zcall_exception_handlerZshutdown_asyncgens)r   r.   Z	to_cancelr2   r   r   r   _tearDownAsyncioLoopy   s2    



z,IsolatedAsyncioTestCase._tearDownAsyncioLoopNc                    s(   |    zt |W S |   X d S r   )r/   r5   r   run)r   resultr   r   r   r6      s    zIsolatedAsyncioTestCase.run)r   )N)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   r   r,   r/   r5   r6   __classcell__r   r   r   r   r      s   

"r   )r&   r%   Zcaser   r   r   r   r   r   <module>   s                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              suite.cpython-38.opt-1.pyc                                                                          0000644                 00000023321 15175327600 0011273 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d2                     @   s|   d Z ddlZddlmZ ddlmZ dZdd ZG d	d
 d
eZG dd  d eZ	G dd deZ
dd ZG dd deZdS )	TestSuite    N   )case)utilTc                 C   s   t | |dd }|  d S )Nc                   S   s   d S N r   r   r   &/usr/lib64/python3.8/unittest/suite.py<lambda>       z!_call_if_exists.<locals>.<lambda>)getattr)parentattrfuncr   r   r   _call_if_exists   s    r   c                   @   sn   e Zd ZdZdZd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S )BaseTestSuitezNA simple test suite that doesn't provide class or module shared fixtures.
    Tr   c                 C   s   g | _ d| _| | d S Nr   )_tests_removed_testsaddTests)selftestsr   r   r   __init__   s    zBaseTestSuite.__init__c                 C   s   dt | jt| f S )Nz<%s tests=%s>)r   strclass	__class__listr   r   r   r   __repr__   s    zBaseTestSuite.__repr__c                 C   s    t || jstS t| t|kS r   )
isinstancer   NotImplementedr   )r   otherr   r   r   __eq__   s    zBaseTestSuite.__eq__c                 C   s
   t | jS r   )iterr   r   r   r   r   __iter__"   s    zBaseTestSuite.__iter__c                 C   s$   | j }| D ]}|r
|| 7 }q
|S r   )r   countTestCases)r   Zcasestestr   r   r   r#   %   s
    zBaseTestSuite.countTestCasesc                 C   sL   t |stdt|t|tr<t|tjt	fr<td| j
| d S )Nz{} is not callablezNTestCases and TestSuites must be instantiated before passing them to addTest())callable	TypeErrorformatreprr   type
issubclassr   ZTestCaser   r   appendr   r$   r   r   r   addTest,   s    zBaseTestSuite.addTestc                 C   s*   t |trtd|D ]}| | qd S )Nz0tests must be an iterable of tests, not a string)r   strr&   r-   )r   r   r$   r   r   r   r   6   s    
zBaseTestSuite.addTestsc                 C   s8   t | D ]*\}}|jr q4|| | jr| | q|S r   )	enumerate
shouldStop_cleanup_removeTestAtIndex)r   resultindexr$   r   r   r   run<   s    zBaseTestSuite.runc                 C   sN   z| j | }W n tk
r"   Y n(X t|dr@|  j| 7  _d| j |< dS )z2Stop holding a reference to the TestCase at index.r#   N)r   r&   hasattrr   r#   )r   r4   r$   r   r   r   r2   E   s    
z BaseTestSuite._removeTestAtIndexc                 O   s   | j ||S r   r5   )r   argskwdsr   r   r   __call__S   s    zBaseTestSuite.__call__c                 C   s   | D ]}|   qdS )7Run the tests without collecting errors in a TestResultN)debugr,   r   r   r   r<   V   s    zBaseTestSuite.debugN)r   )__name__
__module____qualname____doc__r1   r   r   r    r"   r#   r-   r   r5   r2   r:   r<   r   r   r   r   r      s   

	r   c                   @   s^   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdddZ	dddZ
dd Zdd ZdS )r   a  A test suite is a composite test consisting of a number of TestCases.

    For use, create an instance of TestSuite, then add test case instances.
    When all tests have been added, the suite can be passed to a test
    runner, such as TextTestRunner. It will run the individual test cases
    in the order in which they were added, aggregating the results. When
    subclassing, do not forget to call the base class constructor.
    Fc                 C   s   d}t |dddkrd |_}t| D ]\}}|jr8 qt|r| || | || | || |j|_	t |jdds&t |ddrq&|s|| n|
  | jr&| | q&|r| d | | | d|_|S )NF_testRunEnteredT_classSetupFailed_moduleSetUpFailed)r   rA   r/   r0   _isnotsuite_tearDownPreviousClass_handleModuleFixture_handleClassSetUpr   _previousTestClassr<   r1   r2   _handleModuleTearDown)r   r3   r<   ZtopLevelr4   r$   r   r   r   r5   f   s2    



zTestSuite.runc                 C   s   t  }| |d dS )r;   TN)_DebugResultr5   )r   r<   r   r   r   r<      s    zTestSuite.debugc           	      C   s2  t |dd }|j}||krd S |jr(d S t |ddr8d S z
d|_W n tk
rV   Y nX t |dd }|d k	r.t|d z^z
|  W nN t
k
r } z0t|tr d|_t|}| 	||d| W 5 d }~X Y nX W 5 t|d |jdkr,|  t|jdkr,|jD ]}| j	||d	 d||d
 qX d S )NrH   __unittest_skip__F
setUpClass_setupStdout_restoreStdoutTr   r   info)r   r   rC   rB   r&   r   doClassCleanupslentearDown_exceptions"_createClassOrModuleLevelException	Exceptionr   rJ   r   r   )	r   r$   r3   previousClasscurrentClassrL   exc	classNameer   r   r   rG      sL    







   zTestSuite._handleClassSetUpc                 C   s"   d }t |dd }|d k	r|j}|S )NrH   )r   r>   )r   r3   previousModulerV   r   r   r   _get_previous_module   s
    zTestSuite._get_previous_modulec           	      C   s  |  |}|jj}||krd S | | d|_ztj| }W n tk
rR   Y d S X t|dd }|d k	rt	|d zz
|  W n t
k
r } zfzt  W n2 t
k
r } z| ||d| W 5 d }~X Y nX t|tr d|_| ||d| W 5 d }~X Y nX W 5 t	|d X d S )NFsetUpModulerM   rN   T)r\   r   r>   rI   rC   sysmodulesKeyErrorr   r   rU   r   doModuleCleanupsrT   r   rJ   )	r   r$   r3   r[   ZcurrentModulemoduler]   rZ   rX   r   r   r   rF      s>    





zTestSuite._handleModuleFixtureNc                 C   s$   | d| d}|  |||| d S )Nz ())_addClassOrModuleLevelException)r   r3   rX   Zmethod_namer   rP   	errorNamer   r   r   rT      s    z,TestSuite._createClassOrModuleLevelExceptionc                 C   s^   t |}t|dd }|d k	r8t|tjr8||t| n"|sN||t  n||| d S )NaddSkip)	_ErrorHolderr   r   r   ZSkipTestr.   ZaddErrorr^   exc_info)r   r3   Z	exceptionre   rP   errorrf   r   r   r   rd      s    z)TestSuite._addClassOrModuleLevelExceptionc                 C   s  |  |}|d krd S |jr d S ztj| }W n tk
rD   Y d S X t|dd }|d k	rt|d zNz
|  W n> t	k
r } z t|tr | 
||d| W 5 d }~X Y nX W 5 t|d zt  W n4 t	k
r  } z| 
||d| W 5 d }~X Y nX X d S )NtearDownModulerM   rN   )r\   rC   r^   r_   r`   r   r   r   ra   rU   rT   r   rJ   )r   r3   r[   rb   rj   rZ   r   r   r   rI      s:    





zTestSuite._handleModuleTearDownc           	      C   s  t |dd }|j}||krd S t |ddr.d S t |ddr>d S t |ddrNd S t |dd }|d k	rt|d zXz
|  W nH t	k
r } z*t
|tr t|}| ||d| W 5 d }~X Y nX W 5 t|d |  t|jd	kr|jD ]&}t|}| j||d
 d||d qX d S )NrH   rB   FrC   rK   tearDownClassrM   rN   r   r   rO   )r   r   r   rQ   rR   rS   r   r   rT   rU   r   rJ   )	r   r$   r3   rV   rW   rk   rX   rY   rZ   r   r   r   rE     sB    







z TestSuite._tearDownPreviousClass)F)N)N)r=   r>   r?   r@   r5   r<   rG   r\   rF   rT   rd   rI   rE   r   r   r   r   r   \   s   	
!($ 
 
 c                   @   sT   e Zd 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S )rg   z
    Placeholder for a TestCase inside a result. As far as a TestResult
    is concerned, this looks exactly like a unit test. Used to insert
    arbitrary errors into a test suite run.
    Nc                 C   s
   || _ d S r   description)r   rm   r   r   r   r   B  s    z_ErrorHolder.__init__c                 C   s   | j S r   rl   r   r   r   r   idE  s    z_ErrorHolder.idc                 C   s   d S r   r   r   r   r   r   shortDescriptionH  s    z_ErrorHolder.shortDescriptionc                 C   s   d| j f S )Nz<ErrorHolder description=%r>rl   r   r   r   r   r   K  s    z_ErrorHolder.__repr__c                 C   s   |   S r   )rn   r   r   r   r   __str__N  s    z_ErrorHolder.__str__c                 C   s   d S r   r   r   r3   r   r   r   r5   Q  s    z_ErrorHolder.runc                 C   s
   |  |S r   r7   rq   r   r   r   r:   V  s    z_ErrorHolder.__call__c                 C   s   dS r   r   r   r   r   r   r#   Y  s    z_ErrorHolder.countTestCases)r=   r>   r?   r@   ZfailureExceptionr   rn   ro   r   rp   r5   r:   r#   r   r   r   r   rg   6  s   	rg   c                 C   s(   zt |  W n tk
r"   Y dS X dS )z?A crude way to tell apart testcases and suites with duck-typingTF)r!   r&   )r$   r   r   r   rD   \  s
    rD   c                   @   s   e Zd ZdZdZdZdZdS )rJ   zCUsed by the TestSuite to hold previous class when running in debug.NF)r=   r>   r?   r@   rH   rC   r0   r   r   r   r   rJ   e  s   rJ   )r@   r^    r   r   Z
__unittestr   objectr   r   rg   rD   rJ   r   r   r   r   <module>   s   L [&	                                                                                                                                                                                                                                                                                                               util.cpython-38.pyc                                                                                 0000644                 00000010521 15175327600 0010156 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d_                     @   s   d Z ddlmZmZ ddlmZ dZdZdZdZ	dZ
dZee	e e e e
  Zedks\tdd	 Zd
d ZdddZdd Zdd Zdd Zdd ZeddZdd Zdd ZdS )zVarious utility functions.    )
namedtupleCounter)commonprefixTP         c                 C   sB   t | | | }|tkr>d| d | || t | | d  f } | S )Nz%s[%d chars]%s)len_PLACEHOLDER_LEN)s	prefixlenZ	suffixlenskip r   %/usr/lib64/python3.8/unittest/util.py_shorten   s    &r   c                     s   t tt| } ttt| }|tkr(| S t|  t t| t t  }|t	krtt t	 |  tk spt
t t| t  fdd| D S t tt	 t  fdd| D S )Nc                 3   s   | ]} |d   V  qd S Nr   .0r
   prefixr   r   r   	<genexpr>'   s     z'_common_shorten_repr.<locals>.<genexpr>c                 3   s&   | ]} t |d  tt V  qd S r   )r   _MIN_DIFF_LEN_MIN_END_LENr   r   r   r   r   *   s   )tuplemap	safe_reprmaxr   _MAX_LENGTHr   _MIN_BEGIN_LENr	   _MIN_COMMON_LENAssertionErrorr   )argsmaxlenZ
common_lenr   r   r   _common_shorten_repr   s*    
r"   Fc                 C   sP   zt | }W n tk
r*   t| }Y nX |r<t|tk r@|S |d t d S )Nz [truncated]...)repr	Exceptionobject__repr__r   r   )objZshortresultr   r   r   r   -   s    r   c                 C   s   d| j | jf S )Nz%s.%s)
__module____qualname__)clsr   r   r   strclass6   s    r,   c                 C   s  d }}g }g }z| | }|| }||k rT| | |d7 }| | |kr|d7 }q<nv||kr| | |d7 }|| |kr|d7 }qnnD|d7 }z| | |kr|d7 }qW 5 |d7 }|| |kr|d7 }qX W q tk
r   || |d  |||d  Y qY qX q||fS )ar  Finds elements in only one or the other of two, sorted input lists.

    Returns a two-element tuple of lists.    The first list contains those
    elements in the "expected" list but not in the "actual" list, and the
    second contains those elements in the "actual" list but not in the
    "expected" list.    Duplicate elements in either input list are ignored.
    r      N)append
IndexErrorextend)expectedactualijmissingZ
unexpectedear   r   r   sorted_list_difference9   s8    

r8   c                 C   sH   g }| r@|   }z|| W q tk
r<   || Y qX q||fS )zSame behavior as sorted_list_difference but
    for lists of unorderable items (like dicts).

    As it does a linear search per item (remove) it
    has O(n*n) performance.)popremove
ValueErrorr.   )r1   r2   r5   itemr   r   r   unorderable_list_differenceb   s    r=   c                 C   s   | |k| |k  S )z.Return -1 if x < y, 0 if x == y and 1 if x > yr   )xyr   r   r   three_way_cmps   s    r@   ZMismatchzactual expected valuec                 C   s,  t | t | }}t|t| }}t }g }t|D ]\}}	|	|krHq6d }
}t||D ] }|| |	krZ|
d7 }
|||< qZt|D ] \}}||	kr|d7 }|||< q|
|kr6t|
||	}|| q6t|D ]X\}}	|	|krqd}t||D ] }|| |	kr|d7 }|||< qtd||	}|| q|S )HReturns list of (cnt_act, cnt_exp, elem) triples where the counts differr   r-   )listr   r%   	enumeraterange	_Mismatchr.   )r2   r1   r
   tmnZNULLr(   r3   elemcnt_scnt_tr4   Z
other_elemdiffr   r   r   _count_diff_all_purposey   s<    


rM   c           	      C   s   t | t | }}g }| D ]2\}}||d}||krt|||}|| q| D ]&\}}||krZtd||}|| qZ|S )rA   r   )r   itemsgetrE   r.   )	r2   r1   r
   rF   r(   rI   rJ   rK   rL   r   r   r   _count_diff_hashable   s    rP   N)F)__doc__collectionsr   r   Zos.pathr   Z
__unittestr   r	   r   r   r   r   r   r   r"   r   r,   r8   r=   r@   rE   rM   rP   r   r   r   r   <module>   s4   

	)
#                                                                                                                                                                               suite.cpython-38.pyc                                                                                0000644                 00000023321 15175327600 0010334 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d2                     @   s|   d Z ddlZddlmZ ddlmZ dZdd ZG d	d
 d
eZG dd  d eZ	G dd deZ
dd ZG dd deZdS )	TestSuite    N   )case)utilTc                 C   s   t | |dd }|  d S )Nc                   S   s   d S N r   r   r   &/usr/lib64/python3.8/unittest/suite.py<lambda>       z!_call_if_exists.<locals>.<lambda>)getattr)parentattrfuncr   r   r   _call_if_exists   s    r   c                   @   sn   e Zd ZdZdZd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S )BaseTestSuitezNA simple test suite that doesn't provide class or module shared fixtures.
    Tr   c                 C   s   g | _ d| _| | d S Nr   )_tests_removed_testsaddTests)selftestsr   r   r   __init__   s    zBaseTestSuite.__init__c                 C   s   dt | jt| f S )Nz<%s tests=%s>)r   strclass	__class__listr   r   r   r   __repr__   s    zBaseTestSuite.__repr__c                 C   s    t || jstS t| t|kS r   )
isinstancer   NotImplementedr   )r   otherr   r   r   __eq__   s    zBaseTestSuite.__eq__c                 C   s
   t | jS r   )iterr   r   r   r   r   __iter__"   s    zBaseTestSuite.__iter__c                 C   s$   | j }| D ]}|r
|| 7 }q
|S r   )r   countTestCases)r   Zcasestestr   r   r   r#   %   s
    zBaseTestSuite.countTestCasesc                 C   sL   t |stdt|t|tr<t|tjt	fr<td| j
| d S )Nz{} is not callablezNTestCases and TestSuites must be instantiated before passing them to addTest())callable	TypeErrorformatreprr   type
issubclassr   ZTestCaser   r   appendr   r$   r   r   r   addTest,   s    zBaseTestSuite.addTestc                 C   s*   t |trtd|D ]}| | qd S )Nz0tests must be an iterable of tests, not a string)r   strr&   r-   )r   r   r$   r   r   r   r   6   s    
zBaseTestSuite.addTestsc                 C   s8   t | D ]*\}}|jr q4|| | jr| | q|S r   )	enumerate
shouldStop_cleanup_removeTestAtIndex)r   resultindexr$   r   r   r   run<   s    zBaseTestSuite.runc                 C   sN   z| j | }W n tk
r"   Y n(X t|dr@|  j| 7  _d| j |< dS )z2Stop holding a reference to the TestCase at index.r#   N)r   r&   hasattrr   r#   )r   r4   r$   r   r   r   r2   E   s    
z BaseTestSuite._removeTestAtIndexc                 O   s   | j ||S r   r5   )r   argskwdsr   r   r   __call__S   s    zBaseTestSuite.__call__c                 C   s   | D ]}|   qdS )7Run the tests without collecting errors in a TestResultN)debugr,   r   r   r   r<   V   s    zBaseTestSuite.debugN)r   )__name__
__module____qualname____doc__r1   r   r   r    r"   r#   r-   r   r5   r2   r:   r<   r   r   r   r   r      s   

	r   c                   @   s^   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdddZ	dddZ
dd Zdd ZdS )r   a  A test suite is a composite test consisting of a number of TestCases.

    For use, create an instance of TestSuite, then add test case instances.
    When all tests have been added, the suite can be passed to a test
    runner, such as TextTestRunner. It will run the individual test cases
    in the order in which they were added, aggregating the results. When
    subclassing, do not forget to call the base class constructor.
    Fc                 C   s   d}t |dddkrd |_}t| D ]\}}|jr8 qt|r| || | || | || |j|_	t |jdds&t |ddrq&|s|| n|
  | jr&| | q&|r| d | | | d|_|S )NF_testRunEnteredT_classSetupFailed_moduleSetUpFailed)r   rA   r/   r0   _isnotsuite_tearDownPreviousClass_handleModuleFixture_handleClassSetUpr   _previousTestClassr<   r1   r2   _handleModuleTearDown)r   r3   r<   ZtopLevelr4   r$   r   r   r   r5   f   s2    



zTestSuite.runc                 C   s   t  }| |d dS )r;   TN)_DebugResultr5   )r   r<   r   r   r   r<      s    zTestSuite.debugc           	      C   s2  t |dd }|j}||krd S |jr(d S t |ddr8d S z
d|_W n tk
rV   Y nX t |dd }|d k	r.t|d z^z
|  W nN t
k
r } z0t|tr d|_t|}| 	||d| W 5 d }~X Y nX W 5 t|d |jdkr,|  t|jdkr,|jD ]}| j	||d	 d||d
 qX d S )NrH   __unittest_skip__F
setUpClass_setupStdout_restoreStdoutTr   r   info)r   r   rC   rB   r&   r   doClassCleanupslentearDown_exceptions"_createClassOrModuleLevelException	Exceptionr   rJ   r   r   )	r   r$   r3   previousClasscurrentClassrL   exc	classNameer   r   r   rG      sL    







   zTestSuite._handleClassSetUpc                 C   s"   d }t |dd }|d k	r|j}|S )NrH   )r   r>   )r   r3   previousModulerV   r   r   r   _get_previous_module   s
    zTestSuite._get_previous_modulec           	      C   s  |  |}|jj}||krd S | | d|_ztj| }W n tk
rR   Y d S X t|dd }|d k	rt	|d zz
|  W n t
k
r } zfzt  W n2 t
k
r } z| ||d| W 5 d }~X Y nX t|tr d|_| ||d| W 5 d }~X Y nX W 5 t	|d X d S )NFsetUpModulerM   rN   T)r\   r   r>   rI   rC   sysmodulesKeyErrorr   r   rU   r   doModuleCleanupsrT   r   rJ   )	r   r$   r3   r[   ZcurrentModulemoduler]   rZ   rX   r   r   r   rF      s>    





zTestSuite._handleModuleFixtureNc                 C   s$   | d| d}|  |||| d S )Nz ())_addClassOrModuleLevelException)r   r3   rX   Zmethod_namer   rP   	errorNamer   r   r   rT      s    z,TestSuite._createClassOrModuleLevelExceptionc                 C   s^   t |}t|dd }|d k	r8t|tjr8||t| n"|sN||t  n||| d S )NaddSkip)	_ErrorHolderr   r   r   ZSkipTestr.   ZaddErrorr^   exc_info)r   r3   Z	exceptionre   rP   errorrf   r   r   r   rd      s    z)TestSuite._addClassOrModuleLevelExceptionc                 C   s  |  |}|d krd S |jr d S ztj| }W n tk
rD   Y d S X t|dd }|d k	rt|d zNz
|  W n> t	k
r } z t|tr | 
||d| W 5 d }~X Y nX W 5 t|d zt  W n4 t	k
r  } z| 
||d| W 5 d }~X Y nX X d S )NtearDownModulerM   rN   )r\   rC   r^   r_   r`   r   r   r   ra   rU   rT   r   rJ   )r   r3   r[   rb   rj   rZ   r   r   r   rI      s:    





zTestSuite._handleModuleTearDownc           	      C   s  t |dd }|j}||krd S t |ddr.d S t |ddr>d S t |ddrNd S t |dd }|d k	rt|d zXz
|  W nH t	k
r } z*t
|tr t|}| ||d| W 5 d }~X Y nX W 5 t|d |  t|jd	kr|jD ]&}t|}| j||d
 d||d qX d S )NrH   rB   FrC   rK   tearDownClassrM   rN   r   r   rO   )r   r   r   rQ   rR   rS   r   r   rT   rU   r   rJ   )	r   r$   r3   rV   rW   rk   rX   rY   rZ   r   r   r   rE     sB    







z TestSuite._tearDownPreviousClass)F)N)N)r=   r>   r?   r@   r5   r<   rG   r\   rF   rT   rd   rI   rE   r   r   r   r   r   \   s   	
!($ 
 
 c                   @   sT   e Zd 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S )rg   z
    Placeholder for a TestCase inside a result. As far as a TestResult
    is concerned, this looks exactly like a unit test. Used to insert
    arbitrary errors into a test suite run.
    Nc                 C   s
   || _ d S r   description)r   rm   r   r   r   r   B  s    z_ErrorHolder.__init__c                 C   s   | j S r   rl   r   r   r   r   idE  s    z_ErrorHolder.idc                 C   s   d S r   r   r   r   r   r   shortDescriptionH  s    z_ErrorHolder.shortDescriptionc                 C   s   d| j f S )Nz<ErrorHolder description=%r>rl   r   r   r   r   r   K  s    z_ErrorHolder.__repr__c                 C   s   |   S r   )rn   r   r   r   r   __str__N  s    z_ErrorHolder.__str__c                 C   s   d S r   r   r   r3   r   r   r   r5   Q  s    z_ErrorHolder.runc                 C   s
   |  |S r   r7   rq   r   r   r   r:   V  s    z_ErrorHolder.__call__c                 C   s   dS r   r   r   r   r   r   r#   Y  s    z_ErrorHolder.countTestCases)r=   r>   r?   r@   ZfailureExceptionr   rn   ro   r   rp   r5   r:   r#   r   r   r   r   rg   6  s   	rg   c                 C   s(   zt |  W n tk
r"   Y dS X dS )z?A crude way to tell apart testcases and suites with duck-typingTF)r!   r&   )r$   r   r   r   rD   \  s
    rD   c                   @   s   e Zd ZdZdZdZdZdS )rJ   zCUsed by the TestSuite to hold previous class when running in debug.NF)r=   r>   r?   r@   rH   rC   r0   r   r   r   r   rJ   e  s   rJ   )r@   r^    r   r   Z
__unittestr   objectr   r   rg   rD   rJ   r   r   r   r   <module>   s   L [&	                                                                                                                                                                                                                                                                                                               result.cpython-38.opt-2.pyc                                                                         0000644                 00000013117 15175327600 0011463 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   sX   d dl Z d dlZd dlZddlmZ d dlmZ dZdd ZdZ	d	Z
G d
d deZdS )    N   )utilwrapsTc                    s   t   fdd}|S )Nc                    s$   t | ddr|    | f||S )NfailfastF)getattrstop)selfargskwmethod '/usr/lib64/python3.8/unittest/result.pyinner   s    zfailfast.<locals>.innerr   )r   r   r   r   r   r      s    r   z
Stdout:
%sz
Stderr:
%sc                   @   s   e Zd ZdZdZdZd-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dd Zedd Zdd Zdd Zdd Z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S ).
TestResultNFc                 C   sb   d| _ g | _g | _d| _g | _g | _g | _d| _d| _d| _	d | _
d | _tj| _tj| _d| _d S )NFr   )r   failureserrorstestsRunskippedexpectedFailuresunexpectedSuccesses
shouldStopbuffer	tb_locals_stdout_buffer_stderr_buffersysstdout_original_stdoutstderr_original_stderr_mirrorOutput)r	   streamZdescriptions	verbosityr   r   r   __init__&   s    zTestResult.__init__c                 C   s   d S Nr   r	   r   r   r   printErrors7   s    zTestResult.printErrorsc                 C   s    |  j d7  _ d| _|   d S )Nr   F)r   r"   _setupStdoutr	   testr   r   r   	startTest:   s    zTestResult.startTestc                 C   s8   | j r4| jd kr$t | _t | _| jt_| jt_d S r&   )r   r   ioStringIOr   r   r   r    r'   r   r   r   r)   @   s    


zTestResult._setupStdoutc                 C   s   d S r&   r   r'   r   r   r   startTestRunH   s    zTestResult.startTestRunc                 C   s   |    d| _d S )NF)_restoreStdoutr"   r*   r   r   r   stopTestN   s    zTestResult.stopTestc                 C   s   | j r| jrltj }tj }|rF|ds6|d7 }| jt	|  |rl|ds\|d7 }| j
t|  | jt_| j
t_| jd | j  | jd | j  d S )N
r   )r   r"   r   r   getvaluer    endswithr   writeSTDOUT_LINEr!   STDERR_LINEr   seektruncater   )r	   outputerrorr   r   r   r0   S   s$    




zTestResult._restoreStdoutc                 C   s   d S r&   r   r'   r   r   r   stopTestRunh   s    zTestResult.stopTestRunc                 C   s"   | j || ||f d| _d S NT)r   append_exc_info_to_stringr"   r	   r+   errr   r   r   addErrorn   s    zTestResult.addErrorc                 C   s"   | j || ||f d| _d S r=   )r   r>   r?   r"   r@   r   r   r   
addFailurev   s    zTestResult.addFailurec                 C   sZ   |d k	rVt | ddr|   t|d |jr4| j}n| j}||| ||f d| _d S )Nr   Fr   T)	r   r   
issubclassfailureExceptionr   r   r>   r?   r"   )r	   r+   ZsubtestrA   r   r   r   r   
addSubTest}   s    zTestResult.addSubTestc                 C   s   d S r&   r   r*   r   r   r   
addSuccess   s    zTestResult.addSuccessc                 C   s   | j ||f d S r&   )r   r>   )r	   r+   reasonr   r   r   addSkip   s    zTestResult.addSkipc                 C   s   | j || ||f d S r&   )r   r>   r?   r@   r   r   r   addExpectedFailure   s    zTestResult.addExpectedFailurec                 C   s   | j | d S r&   )r   r>   r*   r   r   r   addUnexpectedSuccess   s    zTestResult.addUnexpectedSuccessc                 C   s>   t | jt | j  kodkn  o<t| d p<t | jdkS )Nr   r   )lenr   r   hasattrr   r'   r   r   r   wasSuccessful   s    $zTestResult.wasSuccessfulc                 C   s
   d| _ d S r=   )r   r'   r   r   r   r      s    zTestResult.stopc                 C   s   |\}}}|r |  |r |j}q
||jkr6| |}nd }tj||||| jd}t| }| j	rt
j }	t
j }
|	r|	ds|	d7 }	|t|	  |
r|
ds|
d7 }
|t|
  d|S )N)limitcapture_localsr2    )_is_relevant_tb_leveltb_nextrE   _count_relevant_tb_levels	tracebackTracebackExceptionr   listformatr   r   r   r3   r    r4   r>   r6   r7   join)r	   rA   r+   exctypevaluetblengthZtb_eZmsgLinesr:   r;   r   r   r   r?      s4    

    



zTestResult._exc_info_to_stringc                 C   s   d|j jkS )N
__unittest)tb_frame	f_globals)r	   r\   r   r   r   rR      s    z TestResult._is_relevant_tb_levelc                 C   s&   d}|r"|  |s"|d7 }|j}q|S )Nr   r   )rR   rS   )r	   r\   r]   r   r   r   rT      s
    z$TestResult._count_relevant_tb_levelsc                 C   s&   dt | j| jt| jt| jf S )Nz!<%s run=%i errors=%i failures=%i>)r   Zstrclass	__class__r   rL   r   r   r'   r   r   r   __repr__   s
    zTestResult.__repr__)NNN)__name__
__module____qualname__Z_previousTestClassZ_testRunEnteredZ_moduleSetUpFailedr%   r(   r,   r)   r/   r1   r0   r<   r   rB   rC   rF   rG   rI   rJ   rK   rN   r   r?   rR   rT   rb   r   r   r   r   r      s6   



	r   )r-   r   rU   rQ   r   	functoolsr   r^   r   r6   r7   objectr   r   r   r   r   <module>   s                                                                                                                                                                                                                                                                                                                                                                                                                                                    signals.cpython-38.opt-1.pyc                                                                        0000644                 00000004256 15175327600 0011610 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dc	                     @   sb   d dl Z d dlZd dlmZ dZG dd deZe Zdd Z	dd	 Z
dad
d ZdddZdS )    N)wrapsTc                   @   s   e Zd Zdd Zdd ZdS )_InterruptHandlerc                 C   sN   d| _ || _t|trD|tjkr(tj}n|tjkr<dd }ntd|| _	d S )NFc                 S   s   d S N )Zunused_signumZunused_framer   r   (/usr/lib64/python3.8/unittest/signals.pydefault_handler   s    z3_InterruptHandler.__init__.<locals>.default_handlerzYexpected SIGINT signal handler to be signal.SIG_IGN, signal.SIG_DFL, or a callable object)
calledoriginal_handler
isinstanceintsignalSIG_DFLdefault_int_handlerSIG_IGN	TypeErrorr   )selfr   r   r   r   __init__
   s    



z_InterruptHandler.__init__c                 C   sR   t t j}|| k	r | || | jr2| || d| _t D ]}|  q@d S )NT)r   	getsignalSIGINTr   r   _resultskeysstop)r   ZsignumframeZinstalled_handlerresultr   r   r   __call__   s    z_InterruptHandler.__call__N)__name__
__module____qualname__r   r   r   r   r   r   r   	   s   r   c                 C   s   dt | < d S )N   )r   r   r   r   r   registerResult*   s    r    c                 C   s   t t| d S r   )boolr   popr   r   r   r   removeResult-   s    r#   c                  C   s.   t d kr*ttj} t| a ttjt  d S r   )_interrupt_handlerr   r   r   r   )r   r   r   r   installHandler1   s    r%   c                    s<    d k	r t   fdd}|S td k	r8ttjtj d S )Nc               
      s6   t t j}t  z | |W S t  t j| X d S r   )r   r   r   removeHandler)argskwargsinitialmethodr   r   inner;   s
    zremoveHandler.<locals>.inner)r   r$   r   r   r	   )r+   r,   r   r*   r   r&   9   s    r&   )N)r   weakref	functoolsr   Z
__unittestobjectr   WeakKeyDictionaryr   r    r#   r$   r%   r&   r   r   r   r   <module>   s                                                                                                                                                                                                                                                                                                                                                      main.cpython-38.pyc                                                                                 0000644                 00000016560 15175327600 0010136 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d+                     @   st   d Z ddlZddlZddlZddlmZmZ ddlmZ dZ	dZ
dZd	d
 Zdd Zdd ZG dd deZeZdS )zUnittest main program    N   )loaderrunner)installHandlerTa  Examples:
  %(prog)s test_module               - run tests from test_module
  %(prog)s module.TestClass          - run tests from module.TestClass
  %(prog)s module.Class.test_method  - run specified test method
  %(prog)s path/to/test_file.py      - run tests from test_file.py
aF  Examples:
  %(prog)s                           - run default set of tests
  %(prog)s MyTestSuite               - run suite 'MyTestSuite'
  %(prog)s MyTestCase.testSomething  - run MyTestCase.testSomething
  %(prog)s MyTestCase                - run all 'test*' test methods
                                       in MyTestCase
c                 C   sx   t j| rt|  drtt j| rXt j| t  }t j|sP|t j	rT| S |} | d d 
dd
ddS | S )Nz.py\./)ospathisfilelowerendswithisabsrelpathgetcwd
startswithpardirreplace)nameZrel_path r   %/usr/lib64/python3.8/unittest/main.py_convert_name   s    r   c                 C   s   dd | D S )Nc                 S   s   g | ]}t |qS r   )r   ).0r   r   r   r   
<listcomp>.   s     z"_convert_names.<locals>.<listcomp>r   )namesr   r   r   _convert_names-   s    r   c                 C   s   d| krd|  } | S )N*z*%s*r   )patternr   r   r   _convert_select_pattern1   s    r   c                   @   s   e Zd ZdZdZdZd Z Z Z Z	 Z
ZdZddddejddddddfdddd	Zdd
dZdd Zdd ZdddZdd Zdd Zdd Zdd Zd ddZdd ZdS )!TestProgramzA command-line program that runs a set of tests; this is primarily
       for making test modules conveniently executable.
    Nr   __main__TF)	tb_localsc                C   s   t |tr<t|| _|ddd  D ]}t| j|| _q&n|| _|d krPtj}|| _|| _	|	| _
|| _|
| _|| _|d krtjsd| _n|| _|| _|| _|| _tj|d | _| | |   d S )Nr   r   defaultr   )
isinstancestr
__import__modulesplitgetattrsysargvexitfailfast
catchbreak	verbositybufferr"   warnoptionswarningsdefaultTest
testRunner
testLoaderr
   r   basenameprogName	parseArgsrunTests)selfr'   r3   r+   r4   r5   r,   r/   r-   r.   r0   r2   r"   partr   r   r   __init__A   s,    


zTestProgram.__init__c                 C   s4   |rt | | jd kr|   |   td d S )N   )print_discovery_parser_initArgParsers_print_helpr*   r,   )r:   msgr   r   r   	usageExitg   s    
zTestProgram.usageExitc                 O   sZ   | j d kr6t| j  ttd| ji  | j  n t| j  ttd| ji  d S )Nprog)	r'   r>   _main_parserZformat_helpMAIN_EXAMPLESr7   r?   
print_helpMODULE_EXAMPLES)r:   argskwargsr   r   r   rA   o   s    
zTestProgram._print_helpc                 C   s   |    | jd krpt|dkrD|d  dkrD| |dd   d S | j|dd  |  | js| g  d S n| j|dd  |  | jrt| j| _	t
dkrd | _n6| jd krd | _	n$t| jtr| jf| _	nt| j| _	|   d S )Nr   discoverr=   r!   )r@   r'   lenr   _do_discoveryrE   
parse_argstestsr   	testNames__name__r3   r$   r%   listcreateTests)r:   r+   r   r   r   r8   x   s(    


zTestProgram.parseArgsc                 C   st   | j r| j | j_ |r@|d kr"| jn| }|| j| j| j| _n0| jd kr\| j| j	| _n| j
| j| j	| _d S N)testNamePatternsr5   rK   startr   toptestrP   ZloadTestsFromModuler'   ZloadTestsFromNames)r:   from_discoveryLoaderr   r   r   r   rS      s    


zTestProgram.createTestsc                 C   s$   |   }| || _| || _d S rT   )_getParentArgParser_getMainArgParserrE   _getDiscoveryArgParserr?   )r:   Zparent_parserr   r   r   r@      s    zTestProgram._initArgParsersc                 C   s   t jdd}|jddddddd	 |jd
dddddd	 |jddddd | jd krn|jdddddd d| _| jd kr|jdddddd d| _| jd kr|jdddddd d| _| jd kr|jdd d!td"d# g | _|S )$NF)Zadd_helpz-vz	--verboser/   Zstore_constr=   zVerbose output)destactionZconsthelpz-qz--quietr   zQuiet outputz--localsr"   
store_truez"Show local variables in tracebacks)r^   r_   r`   z-fz
--failfastr-   zStop on first fail or errorz-cz--catchr.   z'Catch Ctrl-C and display results so farz-bz--bufferr0   z%Buffer stdout and stderr during testsz-krU   appendz.Only run tests which match the given substring)r^   r_   typer`   )argparseArgumentParseradd_argumentr-   r.   r0   rU   r   )r:   parserr   r   r   r[      sR    
 
 






 zTestProgram._getParentArgParserc                 C   s2   t j|gd}| j|_| j|_|jdddd |S )NparentsrO   r   z?a list of any number of test modules, classes and test methods.)nargsr`   )rd   re   r7   rD   rA   rG   rf   )r:   parentrg   r   r   r   r\      s    zTestProgram._getMainArgParserc                 C   sz   t j|gd}d| j |_d|_|jddddd |jd	d
ddd |jddddd dD ]}|j|dt jt jd qZ|S )Nrh   z%s discoverzcFor test discovery all test modules must be importable from the top level directory of the project.z-sz--start-directoryrV   z*Directory to start discovery ('.' default))r^   r`   z-pz	--patternr   z+Pattern to match tests ('test*.py' default)z-tz--top-level-directoryrW   z<Top level directory of project (defaults to start directory))rV   r   rW   ?)rj   r#   r`   )rd   re   r7   rD   Zepilogrf   ZSUPPRESS)r:   rk   rg   argr   r   r   r]      s$    


z"TestProgram._getDiscoveryArgParserc                 C   sL   d| _ d| _d | _|d k	r:| jd kr,|   | j||  | jd|d d S )Nr   ztest*.pyT)rY   rZ   )rV   r   rW   r?   r@   rN   rS   )r:   r+   rZ   r   r   r   rM      s    
zTestProgram._do_discoveryc              	   C   s   | j rt  | jd krtj| _t| jtrzVz"| j| j| j| j	| j
| jd}W n. tk
r|   | j| j| j| j	| j
d}Y nX W q tk
r   |  }Y qX n| j}|| j| _| jrt| j   d S )N)r/   r-   r0   r2   r"   )r/   r-   r0   r2   )r.   r   r4   r   ZTextTestRunnerr$   rc   r/   r-   r0   r2   r"   	TypeErrorrunrX   resultr,   r*   ZwasSuccessful)r:   r4   r   r   r   r9      s2    

zTestProgram.runTests)N)FN)N)rQ   
__module____qualname____doc__r'   r/   r-   r.   r0   r7   r2   rU   r?   r   ZdefaultTestLoaderr<   rC   rA   r8   rS   r@   r[   r\   r]   rM   r9   r   r   r   r   r    7   s6        &
	
#
r    )rs   r*   rd   r
    r   r   Zsignalsr   Z
__unittestrF   rH   r   r   r   objectr    mainr   r   r   r   <module>   s   	 ]                                                                                                                                                signals.cpython-38.opt-2.pyc                                                                        0000644                 00000004256 15175327600 0011611 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dc	                     @   sb   d dl Z d dlZd dlmZ dZG dd deZe Zdd Z	dd	 Z
dad
d ZdddZdS )    N)wrapsTc                   @   s   e Zd Zdd Zdd ZdS )_InterruptHandlerc                 C   sN   d| _ || _t|trD|tjkr(tj}n|tjkr<dd }ntd|| _	d S )NFc                 S   s   d S N )Zunused_signumZunused_framer   r   (/usr/lib64/python3.8/unittest/signals.pydefault_handler   s    z3_InterruptHandler.__init__.<locals>.default_handlerzYexpected SIGINT signal handler to be signal.SIG_IGN, signal.SIG_DFL, or a callable object)
calledoriginal_handler
isinstanceintsignalSIG_DFLdefault_int_handlerSIG_IGN	TypeErrorr   )selfr   r   r   r   __init__
   s    



z_InterruptHandler.__init__c                 C   sR   t t j}|| k	r | || | jr2| || d| _t D ]}|  q@d S )NT)r   	getsignalSIGINTr   r   _resultskeysstop)r   ZsignumframeZinstalled_handlerresultr   r   r   __call__   s    z_InterruptHandler.__call__N)__name__
__module____qualname__r   r   r   r   r   r   r   	   s   r   c                 C   s   dt | < d S )N   )r   r   r   r   r   registerResult*   s    r    c                 C   s   t t| d S r   )boolr   popr   r   r   r   removeResult-   s    r#   c                  C   s.   t d kr*ttj} t| a ttjt  d S r   )_interrupt_handlerr   r   r   r   )r   r   r   r   installHandler1   s    r%   c                    s<    d k	r t   fdd}|S td k	r8ttjtj d S )Nc               
      s6   t t j}t  z | |W S t  t j| X d S r   )r   r   r   removeHandler)argskwargsinitialmethodr   r   inner;   s
    zremoveHandler.<locals>.inner)r   r$   r   r   r	   )r+   r,   r   r*   r   r&   9   s    r&   )N)r   weakref	functoolsr   Z
__unittestobjectr   WeakKeyDictionaryr   r    r#   r$   r%   r&   r   r   r   r   <module>   s                                                                                                                                                                                                                                                                                                                                                      runner.cpython-38.pyc                                                                               0000644                 00000015552 15175327600 0010523 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dW                     @   sn   d Z ddlZddlZddlZddlmZ ddlmZ dZG dd de	Z
G d	d
 d
ejZG dd de	ZdS )zRunning tests    N   )result)registerResultTc                   @   s*   e Zd ZdZdd Zdd Zd	ddZdS )
_WritelnDecoratorz@Used to decorate file-like objects with a handy 'writeln' methodc                 C   s
   || _ d S N)stream)selfr    r	   '/usr/lib64/python3.8/unittest/runner.py__init__   s    z_WritelnDecorator.__init__c                 C   s   |dkrt |t| j|S )N)r   __getstate__)AttributeErrorgetattrr   )r   attrr	   r	   r
   __getattr__   s    z_WritelnDecorator.__getattr__Nc                 C   s   |r|  | |  d d S N
)write)r   argr	   r	   r
   writeln   s    
z_WritelnDecorator.writeln)N)__name__
__module____qualname____doc__r   r   r   r	   r	   r	   r
   r      s   r   c                       s   e Zd ZdZdZdZ fddZdd Z fdd	Z fd
dZ	 fddZ
 fddZ fddZ fddZ fddZdd Zdd Z  ZS )TextTestResultzhA test result class that can print formatted text results to a stream.

    Used by TextTestRunner.
    zF======================================================================zF----------------------------------------------------------------------c                    s8   t t| ||| || _|dk| _|dk| _|| _d S )Nr   )superr   r   r   showAlldotsdescriptions)r   r   r   	verbosity	__class__r	   r
   r   %   s
    

zTextTestResult.__init__c                 C   s0   |  }| jr$|r$dt||fS t|S d S r   )ZshortDescriptionr   joinstr)r   testZdoc_first_liner	   r	   r
   getDescription,   s    
zTextTestResult.getDescriptionc                    sB   t t| | | jr>| j| | | jd | j  d S )Nz ... )r   r   	startTestr   r   r   r%   flushr   r$   r    r	   r
   r&   3   s
    zTextTestResult.startTestc                    sD   t t| | | jr$| jd n| jr@| jd | j  d S )Nok.)	r   r   
addSuccessr   r   r   r   r   r'   r(   r    r	   r
   r+   :   s    zTextTestResult.addSuccessc                    sF   t t| || | jr&| jd n| jrB| jd | j  d S )NERRORE)	r   r   addErrorr   r   r   r   r   r'   r   r$   errr    r	   r
   r.   B   s    zTextTestResult.addErrorc                    sF   t t| || | jr&| jd n| jrB| jd | j  d S )NFAILF)	r   r   
addFailurer   r   r   r   r   r'   r/   r    r	   r
   r3   J   s    zTextTestResult.addFailurec                    sL   t t| || | jr,| jd| n| jrH| jd | j	  d S )Nzskipped {0!r}s)
r   r   addSkipr   r   r   formatr   r   r'   )r   r$   reasonr    r	   r
   r5   R   s    zTextTestResult.addSkipc                    sF   t t| || | jr&| jd n| jrB| jd | j  d S )Nzexpected failurex)	r   r   addExpectedFailurer   r   r   r   r   r'   r/   r    r	   r
   r9   Z   s    z!TextTestResult.addExpectedFailurec                    sD   t t| | | jr$| jd n| jr@| jd | j  d S )Nzunexpected successu)	r   r   addUnexpectedSuccessr   r   r   r   r   r'   r(   r    r	   r
   r;   b   s    z#TextTestResult.addUnexpectedSuccessc                 C   s6   | j s| jr| j  | d| j | d| j d S )Nr,   r1   )r   r   r   r   printErrorListerrorsfailuresr   r	   r	   r
   printErrorsj   s    
zTextTestResult.printErrorsc                 C   sX   |D ]N\}}| j | j | j d|| |f  | j | j | j d|  qd S )Nz%s: %sz%s)r   r   
separator1r%   
separator2)r   Zflavourr=   r$   r0   r	   r	   r
   r<   p   s
    zTextTestResult.printErrorList)r   r   r   r   rA   rB   r   r%   r&   r+   r.   r3   r5   r9   r;   r@   r<   __classcell__r	   r	   r    r
   r      s   r   c                   @   s4   e Zd ZdZeZdddddZd	d
 Zdd ZdS )TextTestRunnerzA test runner class that displays results in textual form.

    It prints out the names of tests as they are run, errors as they
    occur, and a summary of the results at the end of the test run.
    NTr   F)	tb_localsc          	      C   sN   |dkrt j}t|| _|| _|| _|| _|| _|| _|| _	|dk	rJ|| _
dS )zConstruct a TextTestRunner.

        Subclasses should accept **kwargs to ensure compatibility as the
        interface changes.
        N)sysstderrr   r   r   r   failfastbufferrE   warningsresultclass)	r   r   r   r   rH   rI   rK   rJ   rE   r	   r	   r
   r      s    
zTextTestRunner.__init__c                 C   s   |  | j| j| jS r   )rK   r   r   r   r?   r	   r	   r
   _makeResult   s    zTextTestRunner._makeResultc                 C   s2  |   }t| | j|_| j|_| j|_t  | jr^t| j | jdkr^tjdt	dd t
 }t|dd}|dk	r|  z|| W 5 t|dd}|dk	r|  X t
 }W 5 Q R X || }|  t|dr| j|j |j}| jd	||d
kodpd|f  | j  d }	 }
}ztt|j|j|jf}W n tk
rT   Y nX |\}	}
}g }| s| jd t|jt|j }}|r|d|  |r|d|  n| jd |r|d|  |	r|d|	  |
r|d|
  |r"| jdd|f  n| jd |S )z&Run the given test case or test suite.)defaultalwaysmodulezPlease use assert\w+ instead.)categorymessagestartTestRunNstopTestRunrB   zRan %d test%s in %.3fsr   r4    r   ZFAILEDzfailures=%dz	errors=%dZOKz
skipped=%dzexpected failures=%dzunexpected successes=%dz (%s)z, r   )rL   r   rH   rI   rE   rJ   catch_warningssimplefilterfilterwarningsDeprecationWarningtimeperf_counterr   r@   hasattrr   r   rB   ZtestsRunmaplenZexpectedFailuresunexpectedSuccessesskippedr   ZwasSuccessfulr   r>   r=   appendr"   )r   r$   r   Z	startTimerR   rS   ZstopTimeZ	timeTakenrunZexpectedFailsr^   r_   ZresultsZinfosZfailedZerroredr	   r	   r
   ra      sx    






zTextTestRunner.run)NTr   FFNN)	r   r   r   r   r   rK   r   rL   ra   r	   r	   r	   r
   rD   x   s           rD   )r   rF   rY   rJ   rT   r   Zsignalsr   Z
__unittestobjectr   Z
TestResultr   rD   r	   r	   r	   r
   <module>   s   [                                                                                                                                                      util.cpython-38.opt-1.pyc                                                                           0000644                 00000010410 15175327600 0011112 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d_                     @   s   d Z ddlmZmZ ddlmZ dZdZdZdZ	dZ
dZee	e e e e
  Zdd	 Zd
d ZdddZdd Zdd Zdd Zdd ZeddZdd Zdd ZdS )zVarious utility functions.    )
namedtupleCounter)commonprefixTP         c                 C   sB   t | | | }|tkr>d| d | || t | | d  f } | S )Nz%s[%d chars]%s)len_PLACEHOLDER_LEN)s	prefixlenZ	suffixlenskip r   %/usr/lib64/python3.8/unittest/util.py_shorten   s    &r   c                     s   t tt| } ttt| }|tkr(| S t|  t t| t t  }|t	krxt
 t| t  fdd| D S t
 tt	 t  fdd| D S )Nc                 3   s   | ]} |d   V  qd S Nr   .0r
   prefixr   r   r   	<genexpr>'   s     z'_common_shorten_repr.<locals>.<genexpr>c                 3   s&   | ]} t |d  tt V  qd S r   )r   _MIN_DIFF_LEN_MIN_END_LENr   r   r   r   r   *   s   )tuplemap	safe_reprmaxr   _MAX_LENGTHr   _MIN_BEGIN_LENr	   _MIN_COMMON_LENr   )argsmaxlenZ
common_lenr   r   r   _common_shorten_repr   s     r!   Fc                 C   sP   zt | }W n tk
r*   t| }Y nX |r<t|tk r@|S |d t d S )Nz [truncated]...)repr	Exceptionobject__repr__r   r   )objZshortresultr   r   r   r   -   s    r   c                 C   s   d| j | jf S )Nz%s.%s)
__module____qualname__)clsr   r   r   strclass6   s    r+   c                 C   s  d }}g }g }z| | }|| }||k rT| | |d7 }| | |kr|d7 }q<nv||kr| | |d7 }|| |kr|d7 }qnnD|d7 }z| | |kr|d7 }qW 5 |d7 }|| |kr|d7 }qX W q tk
r   || |d  |||d  Y qY qX q||fS )ar  Finds elements in only one or the other of two, sorted input lists.

    Returns a two-element tuple of lists.    The first list contains those
    elements in the "expected" list but not in the "actual" list, and the
    second contains those elements in the "actual" list but not in the
    "expected" list.    Duplicate elements in either input list are ignored.
    r      N)append
IndexErrorextend)expectedactualijmissingZ
unexpectedear   r   r   sorted_list_difference9   s8    

r7   c                 C   sH   g }| r@|   }z|| W q tk
r<   || Y qX q||fS )zSame behavior as sorted_list_difference but
    for lists of unorderable items (like dicts).

    As it does a linear search per item (remove) it
    has O(n*n) performance.)popremove
ValueErrorr-   )r0   r1   r4   itemr   r   r   unorderable_list_differenceb   s    r<   c                 C   s   | |k| |k  S )z.Return -1 if x < y, 0 if x == y and 1 if x > yr   )xyr   r   r   three_way_cmps   s    r?   ZMismatchzactual expected valuec                 C   s,  t | t | }}t|t| }}t }g }t|D ]\}}	|	|krHq6d }
}t||D ] }|| |	krZ|
d7 }
|||< qZt|D ] \}}||	kr|d7 }|||< q|
|kr6t|
||	}|| q6t|D ]X\}}	|	|krqd}t||D ] }|| |	kr|d7 }|||< qtd||	}|| q|S )HReturns list of (cnt_act, cnt_exp, elem) triples where the counts differr   r,   )listr   r$   	enumeraterange	_Mismatchr-   )r1   r0   r
   tmnZNULLr'   r2   elemcnt_scnt_tr3   Z
other_elemdiffr   r   r   _count_diff_all_purposey   s<    


rL   c           	      C   s   t | t | }}g }| D ]2\}}||d}||krt|||}|| q| D ]&\}}||krZtd||}|| qZ|S )r@   r   )r   itemsgetrD   r-   )	r1   r0   r
   rE   r'   rH   rI   rJ   rK   r   r   r   _count_diff_hashable   s    rO   N)F)__doc__collectionsr   r   Zos.pathr   Z
__unittestr   r	   r   r   r   r   r   r!   r   r+   r7   r<   r?   rD   rL   rO   r   r   r   r   <module>   s2   

	)
#                                                                                                                                                                                                                                                        loader.cpython-38.opt-1.pyc                                                                         0000644                 00000034137 15175327600 0011417 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dX                     @   s  d 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m	Z	 ddl
mZmZmZ dZedejZG dd	 d	ejZd
d Zdd Zdd Zdd Zdd ZG dd deZe ZdddZejdfddZdejejfddZ dejejfddZ!dS ) zLoading unittests.    N)fnmatchfnmatchcase   )casesuiteutilTz[_a-z]\w*\.py$c                       s,   e Zd ZdZ fddZ fddZ  ZS )_FailedTestNc                    s   || _ tt| | d S N)
_exceptionsuperr   __init__)selfZmethod_name	exception	__class__ '/usr/lib64/python3.8/unittest/loader.pyr      s    z_FailedTest.__init__c                    s*   | j krtt |S  fdd}|S )Nc                      s
    j d S r	   )r
   r   r   r   r   testFailure!   s    z,_FailedTest.__getattr__.<locals>.testFailure)_testMethodNamer   r   __getattr__)r   namer   r   r   r   r      s    
z_FailedTest.__getattr__)__name__
__module____qualname__r   r   r   __classcell__r   r   r   r   r      s   r   c                 C   s"   d| t  f }t| t|||S )Nz#Failed to import test module: %s
%s)	traceback
format_exc_make_failed_testImportError)r   
suiteClassmessager   r   r   _make_failed_import_test&   s
     r"   c                 C   s   dt  f }t| |||S )NzFailed to call load_tests:
%s)r   r   r   )r   r   r    r!   r   r   r   _make_failed_load_tests+   s       r#   c                 C   s   t | |}||f|fS r	   )r   )
methodnamer   r    r!   testr   r   r   r   0   s    
r   c                 C   s<   t t|dd }| |i}tdt jf|}||| fS )Nc                 S   s   d S r	   r   r   r   r   r   testSkipped5   s    z'_make_skipped_test.<locals>.testSkippedZModuleSkipped)r   skipstrtypeTestCase)r$   r   r    r&   attrsZ	TestClassr   r   r   _make_skipped_test4   s
    
r,   c                 C   s*   |   dr| d d S tj| d S )Nz	$py.classir   )lowerendswithospathsplitext)r0   r   r   r   _jython_aware_splitext<   s    r2   c                       s   e Zd ZdZdZeejZdZ	e
jZdZ fddZdd Zddd	d
Zd!ddZd"ddZdd Zd#ddZdd Zdd Zdd Zdd Zd$ddZd%dd Z  ZS )&
TestLoaderz
    This class is responsible for loading tests according to various criteria
    and returning them wrapped in a TestSuite
    r%   Nc                    s    t t|   g | _t | _d S r	   )r   r3   r   errorsset_loading_packagesr   r   r   r   r   M   s    zTestLoader.__init__c                 C   sF   t |tjrtd| |}|s2t|dr2dg}| t||}|S )z;Return a suite of all test cases contained in testCaseClasszYTest cases should not be derived from TestSuite. Maybe you meant to derive from TestCase?ZrunTest)
issubclassr   	TestSuite	TypeErrorgetTestCaseNameshasattrr    map)r   testCaseClassZtestCaseNamesZloaded_suiter   r   r   loadTestsFromTestCaseT   s    
z TestLoader.loadTestsFromTestCasepatternc             
   O   s:  t |dksd|kr,tdt |dd t |dkrRt |d }td|t |dkrxt|d }td|g }t|D ]4}t	||}t
|trt|tjr|| | qt	|dd}	| |}|	dk	r6z|	| ||W S  tk
r4 }
 z,t|j|
| j\}}| j| | W Y S d}
~
X Y nX |S )	z>Return a suite of all test cases contained in the given moduler   Zuse_load_testsz(use_load_tests is deprecated and ignoredNr   zCloadTestsFromModule() takes 1 positional argument but {} were givenz=loadTestsFromModule() got an unexpected keyword argument '{}'
load_tests)lenwarningswarnDeprecationWarningpopr9   formatsorteddirgetattr
isinstancer)   r7   r   r*   appendr>   r    	Exceptionr#   r   r4   )r   moduler@   argsZkwsZ	complainttestsr   objrA   e
error_caseerror_messager   r   r   loadTestsFromModuleb   s<    


  zTestLoader.loadTestsFromModulec                 C   sX  | d}d\}}|dkr|dd }|rzd|}t|}W qW q& tk
r   | }t|| j\}}|s| j| | Y S Y q&X q&|dd }|}	|D ]}
z|	t	|	|
 }}	W q t
k
rN } zvt	|	dddk	r|dk	r| j| | W Y D  S t|
|| jdt f \}}| j| | W Y 
  S W 5 d}~X Y qX qt|	tjrj| |	S t|	trt|	tjr| |	S t|	tjrt|trt|tjr|d }||}tt	||tjs| |gS nt|	tjr|	S t|	rH|	 }t|tjr|S t|tjr6| |gS td|	|f ntd	|	 dS )
aS  Return a suite of all test cases given a string specifier.

        The name may resolve either to a module, a test case class, a
        test method within a test case class, or a callable object which
        returns a TestCase or TestSuite instance.

        The method optionally resolves the names relative to a given module.
        .)NNNr   __path__zFailed to access attribute:
%sz"calling %s returned %s, not a testz$don't know how to make test from: %s)splitjoin
__import__r   rF   r"   r    r4   rL   rJ   AttributeErrorr   r   r   rK   types
ModuleTyperU   r)   r7   r   r*   r>   FunctionTyper   r8   callabler9   )r   r   rN   partsrS   rT   Z
parts_copymodule_nameZnext_attributerQ   partparentrR   instr%   r   r   r   loadTestsFromName   s    	

   $



zTestLoader.loadTestsFromNamec                    s    fdd|D } |S )zReturn a suite of all test cases found using the given sequence
        of string specifiers. See 'loadTestsFromName()'.
        c                    s   g | ]} | qS r   )rf   ).0r   rN   r   r   r   
<listcomp>   s     z1TestLoader.loadTestsFromNames.<locals>.<listcomp>)r    )r   namesrN   Zsuitesr   rh   r   loadTestsFromNames   s    zTestLoader.loadTestsFromNamesc                    s>    fdd}t t|t} jr:|jt jd |S )zLReturn a sorted sequence of method names found within testCaseClass
        c                    sZ   |  jsdS t| }t|s&dS djj| f  jd kpXt fddjD S )NFz%s.%s.%sc                 3   s   | ]}t  |V  qd S r	   )r   )rg   r@   ZfullNamer   r   	<genexpr>   s     zKTestLoader.getTestCaseNames.<locals>.shouldIncludeMethod.<locals>.<genexpr>)
startswithtestMethodPrefixrJ   r`   r   r   testNamePatternsany)attrnameZtestFuncr   r=   rl   r   shouldIncludeMethod   s    
  
z8TestLoader.getTestCaseNames.<locals>.shouldIncludeMethod)key)listfilterrI   sortTestMethodsUsingsort	functools
cmp_to_key)r   r=   rt   ZtestFnNamesr   rs   r   r:      s
    zTestLoader.getTestCaseNamestest*.pyc                 C   sJ  d}|dkr| j dk	r| j }n|dkr.d}|}tj|}|tjkrRtjd| || _ d}d}g }tjtj|rtj|}||krtjtj|d }npzt	| W n t
k
r   d}Y nJX tj| }|dd }	ztjtj|j}W n tk
r   z
|j}
W n tk
r8   d}
Y nX |
r|
jdkr|
jdk	rd}|jD ]P}|s|||s|qb||jdtjjd | _ || j||dd qbn*|jtjkrtddntd	|dY nX |r|s| |	| _ tj| ntj| |r*t
d
| |s@t| ||}|  |S )a%  Find and return all test modules from the specified start
        directory, recursing into subdirectories to find them and return all
        tests found within them. Only test files that match the pattern will
        be loaded. (Using shell style pattern matching.)

        All test modules must be importable from the top level of the project.
        If the start directory is not the top level directory then the top
        level directory must be specified separately.

        If a test package name (directory with '__init__.py') matches the
        pattern then the package will be checked for a 'load_tests' function. If
        this exists then it will be called with (loader, tests, pattern) unless
        the package has already had load_tests called from the same discovery
        invocation, in which case the package module object is not scanned for
        tests - this ensures that when a package uses discover to further
        discover child tests that infinite recursion does not happen.

        If load_tests exists then discovery does *not* recurse into the package,
        load_tests is responsible for loading all tests in the package.

        The pattern is deliberately not stored as a loader attribute so that
        packages can continue discovery themselves. top_level_dir is stored so
        load_tests does not need to pass this argument in to loader.discover().

        Paths are sorted before being imported to ensure reproducible execution
        order even on filesystems with non-alphabetical ordering like ext3/4.
        FNTr   __init__.pyrV   )	namespacez2Can not use builtin modules as dotted module namesz$don't know how to discover from {!r}z%Start directory is not importable: %r)!_top_level_dirr/   r0   abspathsysinsertisdirisfilerZ   r[   r   modulesrY   dirname__file__r\   __spec__loadersubmodule_search_locationsrW   rn   r   replacesepextend_find_testsbuiltin_module_namesr9   rG    _get_directory_containing_moduleremoverv   r    )r   	start_dirr@   Ztop_level_dirZset_implicit_topZis_not_importableis_namespacerP   Z
the_moduleZtop_partspecr0   r   r   r   discover   s    





 
zTestLoader.discoverc                 C   sR   t j| }tj|j}tj| drBtj	tj	|S tj	|S d S )Nr}   )
r   r   r/   r0   r   r   basenamer-   rn   r   )r   rb   rN   	full_pathr   r   r   r   `  s
    
z+TestLoader._get_directory_containing_modulec                 C   sB   || j krdS ttj|}tj|| j }|tjjd}|S )NrV   )r   r2   r/   r0   normpathrelpathr   r   )r   r0   Z_relpathr   r   r   r   _get_name_from_pathl  s    
zTestLoader._get_name_from_pathc                 C   s   t | tj| S r	   )r[   r   r   )r   r   r   r   r   _get_module_from_namex  s    z TestLoader._get_module_from_namec                 C   s
   t ||S r	   )r   )r   r0   r   r@   r   r   r   _match_path|  s    zTestLoader._match_pathFc           
   
   c   s   |  |}|dkrD|| jkrD| |||\}}|dk	r<|V  |sDdS tt|}|D ]t}tj||}	| |	||\}}|dk	r|V  |rV|  |	}| j| z| 
|	||E dH  W 5 | j	| X qVdS )z/Used by discovery. Yields test suites it loads.rV   N)r   r6   _find_test_pathrH   r/   listdirr0   rZ   adddiscardr   )
r   r   r@   r~   r   rP   Zshould_recursepathsr0   r   r   r   r   r     s6    
    
zTestLoader._find_testsc              
   C   st  t j|}t j|rVt|s(dS | |||s:dS | |}z| |}W nh t	j
k
r } zt||| jdf W Y S d}~X Y n   t|| j\}}	| j|	 |df Y S X t jt|d|}
tt j|
}tt j|}| | kr@t j|}tt j|}t j|}d}t||||f | j||ddfS nt j|rl|st jt j|dsdS d}d}| |}z| |}W nj t	j
k
r } zt||| jdf W Y S d}~X Y n   t|| j\}}	| j|	 |df Y S X t|dd}| j| z0| j||d}|dk	rP|dfW S |d	fW S | j| X ndS dS )
zUsed by discovery.

        Loads tests from a single file, or a directories' __init__.py when
        passed the directory.

        Returns a tuple (None_or_tests_from_file, should_recurse).
        )NFFNr   zW%r module incorrectly imported from %r. Expected %r. Is this module globally installed?r?   r}   rA   T)r/   r0   r   r   VALID_MODULE_NAMEmatchr   r   r   r   ZSkipTestr,   r    r"   r4   rL   r   rJ   r2   realpathr-   r   r   rU   r   rZ   r6   r   r   )r   r   r@   r~   r   r   rN   rR   rS   rT   Zmod_filer   Zfullpath_noextZ
module_dirZmod_nameZexpected_dirmsgrA   rP   packager   r   r   r     s|    

&





&

zTestLoader._find_test_path)N)N)r|   N)F)F)r   r   r   __doc__ro   staticmethodr   three_way_cmprx   rp   r   r8   r    r   r   r>   rU   rf   rk   r:   r   r   r   r   r   r   r   r   r   r   r   r   r3   B   s&   
(
N

n
"r3   c                 C   s&   t  }||_| |_||_|r"||_|S r	   )r3   rx   ro   rp   r    )prefix	sortUsingr    rp   r   r   r   r   _makeLoader  s    r   c                 C   s   t |||d| S )N)rp   )r   r:   )r=   r   r   rp   r   r   r   r:     s    r:   r%   c                 C   s   t |||| S r	   )r   r>   )r=   r   r   r    r   r   r   	makeSuite  s    r   c                 C   s   t |||| S r	   )r   rU   )rN   r   r   r    r   r   r   findTestCases  s    r   )NN)"r   r/   rer   r   r]   rz   rC   r   r    r   r   r   Z
__unittestcompile
IGNORECASEr   r*   r   r"   r#   r   r,   r2   objectr3   ZdefaultTestLoaderr   r   r:   r8   r   r   r   r   r   r   <module>   s<      /
	
                                                                                                                                                                                                                                                                                                                                                                                                                                 mock.cpython-38.pyc                                                                                 0000644                 00000227070 15175327600 0010143 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                    @   s  d Z d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
mZmZ ddlmZ ddlmZmZ dd eeD Zd	ZeZd
d Zdd Zdd Zdd Zdd Zdd ZdddZdd Zdd Zdd Z dd  Z!dd!d"Z"d#d$ Z#d%d& Z$d'd( Z%G d)d* d*e&Z'G d+d, d,e&Z(e( Z)e)j*Z*e)j+Z,e)j-Z.d-d.d/d0d1d2d3d4hZ/d5d6 Z0G d7d8 d8e1Z2d9d: Z3G d;d< d<e&Z4G d=d> d>e&Z5G d?d@ d@e5Z6dAdB Z7G dCdD dDe5Z8G dEdF dFe8e6Z9dGdH Z:dIdJ Z;G dKdL dLe&Z<dMdN Z=e*dddddfdOdPZ>ddQdRZ?e*dddddfdSdTZ@G dUdV dVe&ZAdWdX ZBdYdZ ZCe>e@_&eAe@_De?e@_EeCe@_Fd[e@_Gd\ZHd]ZId^Jd_d` eIK D ZLd^Jdad` eIK D ZMdbdcdddedfdgdhdidjdkdldmdndodpdqdrdshZNdtdu ZOdvd d^JeHeIeLeMgK D ZPdwdxdyhZQdzhZReQeRB ZSePeNB ZTeTeSB ZUd{d|d}d~ddddhZVdd dd dd dd dZWeXeXeXeXddddddd	dddZYdd ZZdd Z[dd Z\dd Z]eZe[e\e]dZ^dd Z_G dd de5Z`G dd de`e6ZaG dd de`ZbG dd de`e9ZcG dd de5ZdG dd de5ZeG dd deeebe9ZfG dd de&Zgeg Zhdd ZiG dd dejZkekddZldddZmdd ZnG dd de&ZoepemepehjqfZrdasdd ZtdddZuG dd de9Zvdd ZwG dd dZxdS ))Mock	MagicMockpatchsentinelDEFAULTANYcallcreate_autospec	AsyncMock
FILTER_DIRNonCallableMockNonCallableMagicMock	mock_openPropertyMocksealz1.0    N)CodeType
ModuleType
MethodType)	safe_repr)wrapspartialc                 C   s   h | ]}| d s|qS _
startswith).0name r   %/usr/lib64/python3.8/unittest/mock.py	<setcomp>(   s     
 r   Tc                 C   s>   t | rt| tsdS t| dr*t| d} t| p<t| S )NF__func__)	_is_instance_mock
isinstancer	   hasattrgetattrasyncioiscoroutinefunctioninspectZisawaitableobjr   r   r   _is_async_obj0   s
    

r*   c                 C   s   t | dd rt| S dS d S )N__code__F)r$   r%   r&   funcr   r   r   _is_async_func8   s    
r.   c                 C   s   t t| tS N)
issubclasstyper   r(   r   r   r   r!   ?   s    r!   c                 C   s   t | tpt | tot| tS r/   )r"   BaseExceptionr1   r0   r(   r   r   r   _is_exceptionE   s    
r3   c                 C   s"   t | trt| dr| jS | S d S Nmock)r"   FunctionTypesr#   r5   r(   r   r   r   _extract_mockL   s    r7   c                 C   s   t | tr|s| j} d}n,t | tsFz
| j} W n tk
rD   Y dS X |rVt| d}n| }z| t|fW S  t	k
r   Y dS X dS )z
    Given an arbitrary, possibly callable object, try to create a suitable
    signature object.
    Return a (reduced func, signature) tuple, or None.
    TN)
r"   r1   __init__r6   __call__AttributeErrorr   r'   	signature
ValueError)r-   Zas_instanceZeat_selfZsig_funcr   r   r   _get_signature_objectU   s    

r=   Fc                    sN   t | ||  d krd S  \}   fdd}t| | |t|_ t|_d S )Nc                   s    j || d S r/   bindselfargskwargssigr   r   checksigw   s    z"_check_signature.<locals>.checksig)r=   _copy_func_detailsr1   _mock_check_sig__signature__)r-   r5   	skipfirstinstancerF   r   rD   r   _check_signaturer   s    

rL   c              	   C   s:   dD ]0}zt ||t| | W q tk
r2   Y qX qd S )N)__name____doc____text_signature__
__module____defaults____kwdefaults__)setattrr$   r:   )r-   funcopy	attributer   r   r   rG   ~   s
    rG   c                 C   s@   t | trdS t | tttfr(t| jS t| dd d k	r<dS dS )NTr9   F)r"   r1   staticmethodclassmethodr   	_callabler    r$   r(   r   r   r   rX      s    

rX   c                 C   s   t | ttfkS r/   )r1   listtupler(   r   r   r   _is_list   s    r[   c                 C   sF   t | tst| dddk	S | f| j D ]}|jddk	r& dS q&dS )ztGiven an object, return True if the object is callable.
    For classes, return True if instances would be callable.r9   NTF)r"   r1   r$   __mro____dict__get)r)   baser   r   r   _instance_callable   s    
r`   c                    s   t |t}t|||}|d kr"| S |\}  fdd}t|| |j}| sRd}|| d}d| }	t|	| || }
t|
|   |
S )Nc                     s    j | | d S r/   r>   rB   rC   rD   r   r   rF      s    z _set_signature.<locals>.checksigrT   )Z
_checksig_r5   zYdef %s(*args, **kwargs):
    _checksig_(*args, **kwargs)
    return mock(*args, **kwargs))r"   r1   r=   rG   rM   isidentifierexec_setup_func)r5   originalrK   rJ   resultr-   rF   r   contextsrcrT   r   rD   r   _set_signature   s$    



ri   c                    s    _ fdd}fdd}fdd}fdd}fd	d
}fdd}fdd}	 fdd}
d _d _d  _t  _t  _t  _j _j	 _	j
 _
| _| _| _|	 _|
 _| _| _| _| _ _d S )Nc                     s    j | |S r/   )assert_called_withra   r5   r   r   rj      s    z'_setup_func.<locals>.assert_called_withc                     s    j | |S r/   )assert_calledra   rk   r   r   rl      s    z"_setup_func.<locals>.assert_calledc                     s    j | |S r/   )assert_not_calledra   rk   r   r   rm      s    z&_setup_func.<locals>.assert_not_calledc                     s    j | |S r/   )assert_called_oncera   rk   r   r   rn      s    z'_setup_func.<locals>.assert_called_oncec                     s    j | |S r/   )assert_called_once_withra   rk   r   r   ro      s    z,_setup_func.<locals>.assert_called_once_withc                     s    j | |S r/   )assert_has_callsra   rk   r   r   rp      s    z%_setup_func.<locals>.assert_has_callsc                     s    j | |S r/   )assert_any_callra   rk   r   r   rq      s    z$_setup_func.<locals>.assert_any_callc                     s:   t   _t   _   j} t| r6| k	r6|   d S r/   )	_CallListmethod_calls
mock_calls
reset_mockreturn_valuer!   )retrT   r5   r   r   ru      s    z_setup_func.<locals>.reset_mockFr   )r5   called
call_count	call_argsrr   call_args_listrs   rt   rv   side_effect_mock_childrenrj   ro   rp   rq   ru   rl   rm   rn   rI   _mock_delegate)rT   r5   rE   rj   rl   rm   rn   ro   rp   rq   ru   r   rx   r   rd      s8    rd   c                    sJ   t jj _d _d  _t  _ fdd}dD ]}t |t|| q.d S )Nr   c                   s   t  j| ||S r/   )r$   r5   )attrrB   rC   rk   r   r   wrapper   s    z"_setup_async_mock.<locals>.wrapper)assert_awaitedassert_awaited_onceassert_awaited_withassert_awaited_once_withassert_any_awaitassert_has_awaitsassert_not_awaited)	r%   
coroutines_is_coroutineawait_count
await_argsrr   await_args_listrS   r   )r5   r   rU   r   rk   r   _setup_async_mock   s    
r   c                 C   s   d| dd  | kS )N__%s__   r   r   r   r   r   	_is_magic  s    r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_SentinelObjectz!A unique, named, sentinel object.c                 C   s
   || _ d S r/   r   rA   r   r   r   r   r8     s    z_SentinelObject.__init__c                 C   s
   d| j  S Nzsentinel.%sr   rA   r   r   r   __repr__  s    z_SentinelObject.__repr__c                 C   s
   d| j  S r   r   r   r   r   r   
__reduce__  s    z_SentinelObject.__reduce__N)rM   rP   __qualname__rN   r8   r   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S )		_SentinelzAAccess attributes to return a named object, usable as a sentinel.c                 C   s
   i | _ d S r/   )
_sentinelsr   r   r   r   r8   #  s    z_Sentinel.__init__c                 C   s   |dkrt | j|t|S )N	__bases__)r:   r   
setdefaultr   r   r   r   r   __getattr__&  s    z_Sentinel.__getattr__c                 C   s   dS )Nr   r   r   r   r   r   r   ,  s    z_Sentinel.__reduce__N)rM   rP   r   rN   r8   r   r   r   r   r   r   r   !  s   r   rv   _mock_return_valuer}   _mock_side_effect_mock_parent_mock_new_parent
_mock_name_mock_new_namec                 C   s8   t |  d|  }| |fdd}| |fdd}t||S )NZ_mock_c                 S   s"   | j }|d krt| |S t||S r/   )r   r$   )rA   r   	_the_namerE   r   r   r   _getA  s    
z"_delegating_property.<locals>._getc                 S   s*   | j }|d kr|| j|< nt||| d S r/   )r   r]   rS   )rA   valuer   r   rE   r   r   r   _setF  s    z"_delegating_property.<locals>._set)_allowed_namesaddproperty)r   r   r   r   r   r   r   _delegating_property>  s
    
r   c                   @   s   e Zd Zdd Zdd ZdS )rr   c                 C   sl   t |tst| |S t|}t| }||kr2dS td|| d D ]"}| |||  }||krD dS qDdS )NFr      T)r"   rY   __contains__lenrange)rA   r   Z	len_valueZlen_selfiZsub_listr   r   r   r   S  s    
z_CallList.__contains__c                 C   s   t t| S r/   )pprintZpformatrY   r   r   r   r   r   a  s    z_CallList.__repr__N)rM   rP   r   r   r   r   r   r   r   rr   Q  s   rr   c                 C   s|   t |}t|sdS |js4|js4|jd k	s4|jd k	r8dS | }|d k	rX||krPdS |j}q<|rh| |_||_|rx| |_||_dS )NFT)r7   r!   r   r   r   r   )parentr   r   new_name_parentr   r   r   _check_and_set_parente  s*    r   c                   @   s   e Zd Zdd Zdd ZdS )	_MockIterc                 C   s   t || _d S r/   )iterr)   )rA   r)   r   r   r   r8     s    z_MockIter.__init__c                 C   s
   t | jS r/   )nextr)   r   r   r   r   __next__  s    z_MockIter.__next__N)rM   rP   r   r8   r   r   r   r   r   r     s   r   c                   @   s   e Zd ZeZdZdd ZdS )BaseNc                O   s   d S r/   r   r@   r   r   r   r8     s    zBase.__init__)rM   rP   r   r   r   r   r8   r   r   r   r   r     s   r   c                   @   sd  e Zd ZdZdd ZdLddZd	d
 ZdMddZdNddZdd Z	dd Z
dZee	e
eZedd ZedZedZedZedZedZdd Zdd ZeeeZdOdddd d!Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Z dPd3d4Z!d5d6 Z"d7d8 Z#d9d: Z$d;d< Z%d=d> Z&d?d@ Z'dAdB Z(dQdCdDZ)dEdF Z*dGdH Z+dRdJdKZ,dS )Sr   z A non-callable version of `Mock`c          	      O   s   | f}t | ts^ttj}|j| f||j}dd | D }|r^t	||d  r^t
| f}t| j|d| ji}tt| |}|S )Nc                 S   s   g | ]}| d r|qS specr   r   argr   r   r   
<listcomp>  s   
z+NonCallableMock.__new__.<locals>.<listcomp>r   rN   )r0   r	   r'   r;   r   r8   Zbind_partialZ	argumentskeysr*   AsyncMockMixinr1   rM   rN   _safe_super__new__)	clsrB   kwbasesrE   Z
bound_argsZspec_argnewrK   r   r   r   r     s    
zNonCallableMock.__new__N Fc                 K   s   |d kr|}| j }||d< ||d< ||d< ||d< d|d< |d k	rJ|}d}|
d krZ|d k	}
| |||	|
 i |d< ||d	< d |d
< d|d< d |d< d|d< t |d< t |d< t |d< ||d< |r| jf | tt| |||||| d S )Nr   r   r   r   F_mock_sealedTr~   _mock_wrapsr   Z_mock_calledZ_mock_call_argsr   Z_mock_call_countZ_mock_call_args_listZ_mock_mock_callsrs   _mock_unsafe)r]   _mock_add_specrr   configure_mockr   r   r8   )rA   r   r   r   spec_setr   _spec_state	_new_name_new_parent_spec_as_instance	_eat_selfZunsaferC   r]   r   r   r   r8     sD    



    zNonCallableMock.__init__c                 C   s0   t |}d|_d|_d|_d|_t| || dS )z
        Attach a mock as an attribute of this one, replacing its name and
        parent. Calls to the attached mock will be recorded in the
        `method_calls` and `mock_calls` attributes of this one.Nr   )r7   r   r   r   r   rS   )rA   r5   rU   Z
inner_mockr   r   r   attach_mock  s    zNonCallableMock.attach_mockc                 C   s   |  || dS zAdd a spec to a mock. `spec` can either be an object or a
        list of strings. Only attributes on the `spec` can be fetched as
        attributes from the mock.

        If `spec_set` is True then only attributes on the spec can be set.N)r   rA   r   r   r   r   r   mock_add_spec  s    zNonCallableMock.mock_add_specc                 C   s   d }d }g }t |D ] }tt||d r|| q|d k	r~t|s~t|trV|}nt|}t|||}	|	ot|	d }t |}| j	}
||
d< ||
d< ||
d< ||
d< ||
d< d S )Nr   _spec_class	_spec_set_spec_signature_mock_methods_spec_asyncs)
dirr%   r&   r$   appendr[   r"   r1   r=   r]   )rA   r   r   r   r   r   r   r   r   resr]   r   r   r   r     s,    
 zNonCallableMock._mock_add_specc                 C   s8   | j }| jd k	r| jj}|tkr4| j| dd}|| _|S )N()r   r   )r   r   rv   r   _get_child_mock)rA   rw   r   r   r   Z__get_return_value  s    
 z"NonCallableMock.__get_return_valuec                 C   s,   | j d k	r|| j _n|| _t| |d d d S )Nr   )r   rv   r   r   )rA   r   r   r   r   Z__set_return_value  s    

z"NonCallableMock.__set_return_valuez1The value to be returned when the mock is called.c                 C   s   | j d krt| S | j S r/   )r   r1   r   r   r   r   	__class__!  s    
zNonCallableMock.__class__ry   rz   r{   r|   rt   c                 C   sN   | j }|d kr| jS |j}|d k	rJt|sJt|tsJt|sJt|}||_|S r/   )r   r   r}   callabler"   r   r3   )rA   	delegatedZsfr   r   r   Z__get_side_effect.  s    z!NonCallableMock.__get_side_effectc                 C   s(   t |}| j}|d kr|| _n||_d S r/   )	_try_iterr   r   r}   )rA   r   r   r   r   r   Z__set_side_effect9  s
    z!NonCallableMock.__set_side_effect)rv   r}   c                C   s   |dkrg }t | |krdS |t |  d| _d| _d| _t | _t | _t | _|r^t	| _
|rhd| _| j D ]"}t|tsr|tkrqr|| qr| j
}t|r|| k	r|| dS )z-Restore the mock object to its initial state.NFr   )idr   ry   r{   rz   rr   rt   r|   rs   r   r   r   r~   valuesr"   
_SpecState_deletedru   r!   )rA   Zvisitedrv   r}   childrw   r   r   r   ru   D  s,    zNonCallableMock.reset_mockc                K   sX   t | dd dD ]>\}}|d}| }| }|D ]}t||}q6t||| qdS )aZ  Set attributes on the mock through keyword arguments.

        Attributes plus return values and side effects can be set on child
        mocks using standard dot notation and unpacking a dictionary in the
        method call:

        >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
        >>> mock.configure_mock(**attrs)c                 S   s   | d  dS )Nr   .)count)entryr   r   r   <lambda>o      z0NonCallableMock.configure_mock.<locals>.<lambda>)keyr   N)sorteditemssplitpopr$   rS   )rA   rC   r   valrB   finalr)   r   r   r   r   r   b  s    	
zNonCallableMock.configure_mockc                 C   s   |dkrt |n:| jd k	r<|| jks.|tkrLt d| nt|rLt || jsd|drdt d| j|}|tkrt |np|d krd }| j	d k	rt
| j	|}| j| |||| d}|| j|< n.t|trt|j|j|j|j|j}|| j|< |S )N>   r   r   zMock object has no attribute %r)assertZassretz1Attributes cannot start with 'assert' or 'assret')r   r   r   r   r   )r:   r   _all_magicsr   r   r   r~   r^   r   r   r$   r   r"   r   r   r   r   rK   r   r   )rA   r   rf   r   r   r   r   r   x  sF    




   
   
zNonCallableMock.__getattr__c                 C   s   | j g}| j}| }d}|dgkr$d}|d k	rZ|}||j |  d}|j dkrRd}|j}q$tt|}|jpnd}t|dkr|d dkr|d7 }||d< d|S )Nr   r   r   r5   r   )r   z().r   )r   r   r   rY   reversedr   r   join)rA   Z
_name_listr   ZlastdotZ_firstr   r   r   _extract_mock_name  s(    


z"NonCallableMock._extract_mock_namec                 C   s^   |   }d}|dkrd| }d}| jd k	rDd}| jr8d}|| jj }dt| j||t| f S )Nr   )r5   zmock.z name=%rz spec=%rz spec_set=%rz<%s%s%s id='%s'>)r   r   r   rM   r1   r   )rA   r   Zname_stringZspec_stringr   r   r   r     s     
zNonCallableMock.__repr__c                 C   sv   t st| S | jpg }tt| }t| j}dd | j	 D }dd |D }dd |D }t
t|| | | S )z8Filter the output of `dir(mock)` to only useful members.c                 S   s   g | ]\}}|t k	r|qS r   )r   )r   Zm_nameZm_valuer   r   r   r     s   z+NonCallableMock.__dir__.<locals>.<listcomp>c                 S   s   g | ]}| d s|qS r   r   r   er   r   r   r     s     
 c                 S   s"   g | ]}| d rt|r|qS r   )r   r   r   r   r   r   r     s     
)r
   object__dir__r   r   r1   rY   r]   r~   r   r   set)rA   ZextrasZ	from_typeZ	from_dictZfrom_child_mocksr   r   r   r    s    


zNonCallableMock.__dir__c                    sT  |t krt||S jrHjd k	rH|jkrH|jkrHtd| n|tkrbd| }t|n|tkrjd k	r|jkrtd| t	|st
t|t|| |  fdd}n(t|d | t
t|| |j|< n,|dkr|_d S t|||r|j|< jrFt|sF  d| }td| t||S )Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.c                     s    f| |S r/   r   rB   r   re   rA   r   r   r     r   z-NonCallableMock.__setattr__.<locals>.<lambda>r   r   zCannot set )r   r  __setattr__r   r   r]   r:   _unsupported_magicsr   r!   rS   r1   _get_methodr   r~   r   r   r#   r   )rA   r   r   msg	mock_namer   r  r   r    s<    

zNonCallableMock.__setattr__c                 C   s   |t kr2|t| jkr2tt| | || jkr2d S | j|t}|| jkr\tt| 	| n|t
krlt||tk	r|| j|= t
| j|< d S r/   )r   r1   r]   delattrr~   r^   _missingr   r   __delattr__r   r:   )rA   r   r)   r   r   r   r    s    

zNonCallableMock.__delattr__c                 C   s   | j pd}t|||S r4   )r   _format_call_signaturerA   rB   rC   r   r   r   r   _format_mock_call_signature  s    
z+NonCallableMock._format_mock_call_signaturer   c                 C   s.   d}|  ||}| j}| j | }||||f S )Nz.expected %s not found.
Expected: %s
Actual: %s)r  r{   )rA   rB   rC   actionmessageexpected_stringr{   Zactual_stringr   r   r   _format_mock_failure_message  s
    
z,NonCallableMock._format_mock_failure_messagec                 C   sj   |s
| j S d}|ddd}| j}|D ]:}||}|dksJt|trP qfq*t|}|j}|j }q*|S )aH  
        * If call objects are asserted against a method/function like obj.meth1
        then there could be no name for the call object to lookup. Hence just
        return the spec_signature of the method/function being asserted against.
        * If the name is not empty then remove () and split by '.' to get
        list of names to iterate through the children until a potential
        match is found. A child mock is created only during attribute access
        so if we get a _SpecState then no attributes of the spec were accessed
        and can be safely exited.
        Nr   r   r   )r   replacer   r~   r^   r"   r   r7   )rA   r   rE   namesZchildrenr   r   r   r   _get_call_signature_from_name'  s    
z-NonCallableMock._get_call_signature_from_namec              
   C   s   t |tr&t|dkr&| |d }n| j}|dk	rt|dkrNd}|\}}n
|\}}}z||j||fW S  tk
r } z|d W Y S d}~X Y qX n|S dS )a  
        Given a call (or simply an (args, kwargs) tuple), return a
        comparison key suitable for matching with other calls.
        This is a best effort method which relies on the spec's signature,
        if available, or falls back on the arguments themselves.
        r   r   Nr   )r"   rZ   r   r  r   r?   	TypeErrorwith_traceback)rA   _callrE   r   rB   rC   r  r   r   r   _call_matcherH  s    

"zNonCallableMock._call_matcherc                 C   s0   | j dkr,d| jpd| j |  f }t|dS )z/assert that the mock was never called.
        r   z9Expected '%s' to not have been called. Called %s times.%sr5   Nrz   r   _calls_reprAssertionErrorrA   r
  r   r   r   rm   b  s    
z!NonCallableMock.assert_not_calledc                 C   s$   | j dkr d| jpd }t|dS )z6assert that the mock was called at least once
        r   z"Expected '%s' to have been called.r5   N)rz   r   r  r   r   r   r   rl   l  s
    
zNonCallableMock.assert_calledc                 C   s0   | j dks,d| jpd| j |  f }t|dS )z3assert that the mock was called only once.
        r   z:Expected '%s' to have been called once. Called %s times.%sr5   Nr  r   r   r   r   rn   t  s    
z"NonCallableMock.assert_called_oncec                   s   j dkr. }d}d||f }t| fdd} f}j }||kr~t|trn|nd}t| |dS )zassert that the last call was made with the specified arguments.

        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock.Nznot called.z0expected call not found.
Expected: %s
Actual: %sc                     s     } | S r/   r  r
  rB   rC   rA   r   r   _error_message  s    z:NonCallableMock.assert_called_with.<locals>._error_message)r{   r  r  r  r"   	Exception)rA   rB   rC   expectedactualZerror_messager$  causer   r#  r   rj   ~  s    
z"NonCallableMock.assert_called_withc                O   s8   | j dks,d| jpd| j |  f }t|| j||S )ziassert that the mock was called exactly once and that that call was
        with the specified arguments.r   z3Expected '%s' to be called once. Called %s times.%sr5   )rz   r   r  r  rj   rA   rB   rC   r
  r   r   r   ro     s    
z'NonCallableMock.assert_called_once_withc           	   	      s   fdd|D }t dd |D d}t fdd jD }|s||kr|dkrXd}ndd	d |D }t| d
t|  jddd |dS t|}g }|D ]2}z|| W q t	k
r   |
| Y qX q|rtd jpdt||f |dS )a  assert the mock has been called with the specified calls.
        The `mock_calls` list is checked for the calls.

        If `any_order` is False (the default) then the calls must be
        sequential. There can be extra calls before or after the
        specified calls.

        If `any_order` is True then the calls can be in any order, but
        they must all appear in `mock_calls`.c                    s   g | ]}  |qS r   r  r   cr   r   r   r     s     z4NonCallableMock.assert_has_calls.<locals>.<listcomp>c                 s   s   | ]}t |tr|V  qd S r/   r"   r%  r   r   r   r   	<genexpr>  s     
 z3NonCallableMock.assert_has_calls.<locals>.<genexpr>Nc                 3   s   | ]}  |V  qd S r/   r*  r+  r   r   r   r.    s     zCalls not found.z+Error processing expected calls.
Errors: {}c                 S   s   g | ]}t |tr|nd qS r/   r-  r   r   r   r   r     s   
Expected: ZActual)prefixr   z@%r does not contain all of %r in its call list, found %r insteadr5   )r   rr   rt   formatr  r  rstriprY   remover<   r   r   rZ   )	rA   calls	any_orderr&  r(  Z	all_callsproblem	not_foundkallr   r   r   rp     sH    
" z NonCallableMock.assert_has_callsc                   sZ     ||f} fdd jD }||krVt|tr8|nd} ||}td| |dS )zassert the mock has been called with the specified arguments.

        The assert passes if the mock has *ever* been called, unlike
        `assert_called_with` and `assert_called_once_with` that only pass if
        the call is the most recent one.c                    s   g | ]}  |qS r   r*  r+  r   r   r   r     s     z3NonCallableMock.assert_any_call.<locals>.<listcomp>Nz%s call not found)r  r|   r"   r%  r  r  rA   rB   rC   r&  r'  r(  r  r   r   r   rq     s    zNonCallableMock.assert_any_callc                K   s   | d}|| jd kr"tf |S t| }t|trB|tkrBt}nbt|trp|tksd| j	rj|| j	krjt}qt}n4t|t
st|trt}qt|trt}n
|jd }| jrd|krd|d  nd}|  | }t||f |S )aP  Create the child mocks for attributes and return value.
        By default child mocks will be the same type as the parent.
        Subclasses of Mock may want to override this to customize the way
        child mocks are made.

        For non-callable mocks the callable variant will be used (rather than
        any custom subclass).r   r   r   r   r   r   )r^   r]   r	   r1   r0   r   _async_method_magicsr   _all_sync_magicsr   CallableMixinr   r   r   r\   r   r   r:   )rA   r   r   _typeklassrU   r  r   r   r   r     s2    






zNonCallableMock._get_child_mockCallsc                 C   s"   | j s
dS d| dt| j  dS )zRenders self.mock_calls as a string.

        Example: "
Calls: [call(1), call(2)]."

        If self.mock_calls is empty, an empty string is returned. The
        output will be truncated if very long.
        r   
z: r   )rt   r   )rA   r0  r   r   r   r    s    zNonCallableMock._calls_repr)NNNNNNr   NFNF)F)FF)N)r   )F)r?  )-rM   rP   r   rN   r   r8   r   r   r   Z"_NonCallableMock__get_return_valueZ"_NonCallableMock__set_return_valueZ"_NonCallableMock__return_value_docr   rv   r   r   ry   rz   r{   r|   rt   Z!_NonCallableMock__get_side_effectZ!_NonCallableMock__set_side_effectr}   ru   r   r   r   r   r  r  r  r  r  r  r  rm   rl   rn   rj   ro   rp   rq   r   r  r   r   r   r   r     sp                      
-
	  


''
!


-'r   c                 C   sL   | d kr| S t | r| S t| r$| S z
t| W S  tk
rF   |  Y S X d S r/   )r3   rX   r   r  r(   r   r   r   r     s    
r   c                
   @   sR   e Zd Zddedddddddf
ddZdd Zdd Zd	d
 Zdd Zdd Z	dS )r<  Nr   c              	   K   s6   || j d< tt| j|||||||	|
f| || _d S )Nr   )r]   r   r<  r8   r}   )rA   r   r}   rv   r   r   r   r   r   r   r   rC   r   r   r   r8   #  s    

      zCallableMixin.__init__c                O   s   d S r/   r   r@   r   r   r   rH   /  s    zCallableMixin._mock_check_sigc                O   s$   | j || | j|| | j||S r/   )rH   _increment_mock_call
_mock_callr@   r   r   r   r9   4  s    zCallableMixin.__call__c                O   s   | j ||S r/   )_execute_mock_callr@   r   r   r   rB  <  s    zCallableMixin._mock_callc                O   s   d| _ |  jd7  _t||fdd}|| _| j| | jd k	}| j}| j}|dk}| j	td||f | j
}|d k	r|r|jt|||f |jd k	}|r|jd | }t|||f}	|j	|	 |jr|rd}
nd}
|jdk}|j|
 | }|j
}qpd S )NTr   twor   r   r   )ry   rz   _Callr{   r|   r   r   r   r   rt   r   rs   )rA   rB   rC   r  Zdo_method_callsZmethod_call_nameZmock_call_nameZ	is_a_callr   Zthis_mock_callr   r   r   r   rA  ?  s4    


z"CallableMixin._increment_mock_callc                O   s|   | j }|d k	rPt|r|n(t|s:t|}t|rD|n
|||}|tk	rP|S | jtk	r`| jS | jd k	rv| j||S | jS r/   )r}   r3   rX   r   r   r   rv   r   )rA   rB   rC   effectrf   r   r   r   rC  m  s     


z CallableMixin._execute_mock_call)
rM   rP   r   r   r8   rH   r9   rB  rA  rC  r   r   r   r   r<  !  s        
.r<  c                   @   s   e Zd ZdZdS )r   a	  
    Create a new `Mock` object. `Mock` takes several optional arguments
    that specify the behaviour of the Mock object:

    * `spec`: This can be either a list of strings or an existing object (a
      class or instance) that acts as the specification for the mock object. If
      you pass in an object then a list of strings is formed by calling dir on
      the object (excluding unsupported magic attributes and methods). Accessing
      any attribute not in this list will raise an `AttributeError`.

      If `spec` is an object (rather than a list of strings) then
      `mock.__class__` returns the class of the spec object. This allows mocks
      to pass `isinstance` tests.

    * `spec_set`: A stricter variant of `spec`. If used, attempting to *set*
      or get an attribute on the mock that isn't on the object passed as
      `spec_set` will raise an `AttributeError`.

    * `side_effect`: A function to be called whenever the Mock is called. See
      the `side_effect` attribute. Useful for raising exceptions or
      dynamically changing return values. The function is called with the same
      arguments as the mock, and unless it returns `DEFAULT`, the return
      value of this function is used as the return value.

      If `side_effect` is an iterable then each call to the mock will return
      the next value from the iterable. If any of the members of the iterable
      are exceptions they will be raised instead of returned.

    * `return_value`: The value returned when the mock is called. By default
      this is a new Mock (created on first access). See the
      `return_value` attribute.

    * `wraps`: Item for the mock object to wrap. If `wraps` is not None then
      calling the Mock will pass the call through to the wrapped object
      (returning the real result). Attribute access on the mock will return a
      Mock object that wraps the corresponding attribute of the wrapped object
      (so attempting to access an attribute that doesn't exist will raise an
      `AttributeError`).

      If the mock has an explicit `return_value` set then calls are not passed
      to the wrapped object and the `return_value` is returned instead.

    * `name`: If the mock has a name then it will be used in the repr of the
      mock. This can be useful for debugging. The name is propagated to child
      mocks.

    Mocks can also be called with arbitrary keyword arguments. These will be
    used to set attributes on the mock after it is created.
    NrM   rP   r   rN   r   r   r   r   r     s   r   c                 C   s8   zt | |W S  tk
r2   t| t | | Y S X d S r/   )r$   r:   
__import__)thingcompimport_pathr   r   r   _dot_lookup  s
    rM  c                 C   sB   |  d}|d}t|}|D ]}|d| 7 }t|||}q |S )Nr   r   z.%s)r   r   rI  rM  )targetZ
componentsrL  rJ  rK  r   r   r   	_importer  s    

rO  c                   @   sz   e Zd ZdZg Zdd Zdd Zdd Zdd	 Ze	j
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S )_patchNc
           
      C   sn   |d k	r(|t k	rtd|d k	r(td|| _|| _|| _|| _|| _|| _d| _|| _	|| _
|	| _g | _d S )Nz,Cannot use 'new' and 'new_callable' togetherz1Cannot use 'autospec' and 'new_callable' togetherF)r   r<   getterrU   r   new_callabler   createZ	has_localr   autospecrC   additional_patchers)
rA   rQ  rU   r   r   rS  r   rT  rR  rC   r   r   r   r8     s(    z_patch.__init__c              
   C   sH   t | j| j| j| j| j| j| j| j| j		}| j
|_
dd | jD |_|S )Nc                 S   s   g | ]}|  qS r   )copy)r   pr   r   r   r     s    z_patch.copy.<locals>.<listcomp>)rP  rQ  rU   r   r   rS  r   rT  rR  rC   attribute_namerU  )rA   patcherr   r   r   rV    s           z_patch.copyc                 C   s2   t |tr| |S t|r(| |S | |S r/   )r"   r1   decorate_classr'   r&   decorate_async_callabledecorate_callablerA   r-   r   r   r   r9     s
    



z_patch.__call__c                 C   sN   t |D ]@}|tjsqt||}t|ds0q|  }t|||| q|S Nr9   )r   r   r   TEST_PREFIXr$   r#   rV  rS   )rA   r>  r   
attr_valuerY  r   r   r   rZ    s    

z_patch.decorate_classc              	   c   sr   g }t  \}|jD ]8}||}|jd k	r8|| q|jtkr|| q|t	|7 }||fV  W 5 Q R X d S r/   )

contextlib	ExitStack	patchingsenter_contextrX  updater   r   r   rZ   )rA   patchedrB   keywargs
extra_args
exit_stackpatchingr   r   r   r   decoration_helper  s    




z_patch.decoration_helperc                    s>   t  dr j  S t  fddg_S )Nrc  c               
      s4    | |\}} ||W  5 Q R  S Q R X d S r/   rk  rB   rg  ZnewargsZnewkeywargsr-   rf  rA   r   r   rf  (  s    z)_patch.decorate_callable.<locals>.patchedr#   rc  r   r   r]  r   rn  r   r\  "  s    
z_patch.decorate_callablec                    s>   t  dr j  S t  fddg_S )Nrc  c               
      s:    | |"\}} ||I d H W  5 Q R  S Q R X d S r/   rl  rm  rn  r   r   rf  9  s    z/_patch.decorate_async_callable.<locals>.patchedro  r]  r   rn  r   r[  3  s    
z_patch.decorate_async_callablec              	   C   s   |   }| j}t}d}z|j| }W n$ ttfk
rH   t||t}Y nX d}|tkrft|t	rfd| _
| j
s|tkrtd||f ||fS )NFTz!%s does not have the attribute %r)rQ  rU   r   r]   r:   KeyErrorr$   	_builtinsr"   r   rS  )rA   rN  r   re   localr   r   r   get_originalD  s     
z_patch.get_originalc                 C   s  | j | j| j  }}}| j| j }}| j}|  | _|dkr@d}|dkrLd}|dkrXd}|dk	rp|dk	rptd|dk	s|dk	r|dkrtd| 	 \}}|t
kr||dkr|d}	|dkr|}|dkr|}d}n&|dk	r|dkr|}d}n|dkr|}|dk	s|dk	r.|t
krtdt|tr.d}	|dkrHt|rHt}
nt}
i }|dk	r`|}
n^|dk	st|dk	r|}|dk	r|}t|rd|k}n
t| }t|rt}
n
|rt}
|dk	r||d	< |dk	r||d
< t|
trt|
tr| jr| j|d< || |
f |}|	rt|r|}|dk	rB|}t|sZt|sZt}
|d |
f |dd||_nl|dk	r|t
k	rtd|t
krtdt|}|dkr|}t|f|| jd|}n|rtd|}|| _|| _t  | _!zrt"| j| j| | j#dk	rpi }| j t
kr:||| j#< | j$D ](}| j!%|}|j t
kr@|| q@|W S |W S    | j&t'(  s Y nX dS )zPerform the patch.FNzCan't specify spec and autospec)TNz6Can't provide explicit spec_set *and* spec or autospecTz!Can't use 'spec' with create=Truer9   r   r   r   r   r   zBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=True)r   _namez.Can't pass kwargs to a mock we aren't creating))r   r   r   rT  rC   rR  rQ  rN  r  rs  r   r"   r1   r*   r	   r   r[   r   r   r0   r   rU   re  r!   r`   r   rv   boolr   temp_originalis_localra  rb  _exit_stackrS   rX  rU  rd  __exit__sysexc_info)rA   r   r   r   rT  rC   rR  re   rr  ZinheritKlass_kwargsZ	this_specZnot_callableZnew_attrrh  rj  r   r   r   r   	__enter__\  s    























z_patch.__enter__c                 G   s   | j r$| jtk	r$t| j| j| j n>t| j| j | jsbt| j| jrP| jdkrbt| j| j| j | `| ` | `| j	}| `	|j
| S )zUndo the patch.)rN   rP   rQ   __annotations__rR   )rw  rv  r   rS   rN  rU   r  rS  r#   rx  ry  )rA   r{  ri  r   r   r   ry    s    z_patch.__exit__c                 C   s   |   }| j|  |S )z-Activate a patch, returning any created mock.)r~  _active_patchesr   )rA   rf   r   r   r   start  s    z_patch.startc                 C   s6   z| j |  W n tk
r&   Y dS X | dddS )zStop an active patch.N)r  r3  r<   ry  r   r   r   r   stop  s
    z_patch.stop)rM   rP   r   rX  r  r8   rV  r9   rZ  ra  contextmanagerrk  r\  r[  rs  r~  ry  r  r  r   r   r   r   rP    s    
 rP  c              	      sP   z  dd\ }W n& ttfk
r:   td f Y nX  fdd}||fS )Nr   r   z.Need a valid target to patch. You supplied: %rc                      s   t  S r/   rO  r   rN  r   r   r     r   z_get_target.<locals>.<lambda>)rsplitr  r<   )rN  rU   rQ  r   r  r   _get_target
  s    r  c           
   
      s>   t  tkrt d fdd}	t|	||||||||	S )a  
    patch the named member (`attribute`) on an object (`target`) with a mock
    object.

    `patch.object` can be used as a decorator, class decorator or a context
    manager. Arguments `new`, `spec`, `create`, `spec_set`,
    `autospec` and `new_callable` have the same meaning as for `patch`. Like
    `patch`, `patch.object` takes arbitrary keyword arguments for configuring
    the mock object it creates.

    When used as a class decorator `patch.object` honours `patch.TEST_PREFIX`
    for choosing which methods to wrap.
    z3 must be the actual object to be patched, not a strc                      s    S r/   r   r   r  r   r   r   *  r   z_patch_object.<locals>.<lambda>)r1   strr  rP  )
rN  rU   r   r   rS  r   rT  rR  rC   rQ  r   r  r   _patch_object  s            r  c                    s   t  tkr fdd}n fdd}|s2tdt| }|d \}	}
t||	|
|||||i 	}|	|_|dd D ]2\}	}
t||	|
|||||i 	}|	|_|j| qt|S )a  Perform multiple patches in a single call. It takes the object to be
    patched (either as an object or a string to fetch the object by importing)
    and keyword arguments for the patches::

        with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'):
            ...

    Use `DEFAULT` as the value if you want `patch.multiple` to create
    mocks for you. In this case the created mocks are passed into a decorated
    function by keyword, and a dictionary is returned when `patch.multiple` is
    used as a context manager.

    `patch.multiple` can be used as a decorator, class decorator or a context
    manager. The arguments `spec`, `spec_set`, `create`,
    `autospec` and `new_callable` have the same meaning as for `patch`. These
    arguments will be applied to *all* patches done by `patch.multiple`.

    When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX`
    for choosing which methods to wrap.
    c                      s   t  S r/   r  r   r  r   r   r   H  r   z!_patch_multiple.<locals>.<lambda>c                      s    S r/   r   r   r  r   r   r   J  r   z=Must supply at least one keyword argument with patch.multipler   r   N)	r1   r  r<   rY   r   rP  rX  rU  r   )rN  r   rS  r   rT  rR  rC   rQ  r   rU   r   rY  Zthis_patcherr   r  r   _patch_multiple1  sH                  r  c           
   
   K   s$   t | \}}	t||	|||||||	S )a7  
    `patch` acts as a function decorator, class decorator or a context
    manager. Inside the body of the function or with statement, the `target`
    is patched with a `new` object. When the function/with statement exits
    the patch is undone.

    If `new` is omitted, then the target is replaced with an
    `AsyncMock if the patched object is an async function or a
    `MagicMock` otherwise. If `patch` is used as a decorator and `new` is
    omitted, the created mock is passed in as an extra argument to the
    decorated function. If `patch` is used as a context manager the created
    mock is returned by the context manager.

    `target` should be a string in the form `'package.module.ClassName'`. The
    `target` is imported and the specified object replaced with the `new`
    object, so the `target` must be importable from the environment you are
    calling `patch` from. The target is imported when the decorated function
    is executed, not at decoration time.

    The `spec` and `spec_set` keyword arguments are passed to the `MagicMock`
    if patch is creating one for you.

    In addition you can pass `spec=True` or `spec_set=True`, which causes
    patch to pass in the object being mocked as the spec/spec_set object.

    `new_callable` allows you to specify a different class, or callable object,
    that will be called to create the `new` object. By default `AsyncMock` is
    used for async functions and `MagicMock` for the rest.

    A more powerful form of `spec` is `autospec`. If you set `autospec=True`
    then the mock will be created with a spec from the object being replaced.
    All attributes of the mock will also have the spec of the corresponding
    attribute of the object being replaced. Methods and functions being
    mocked will have their arguments checked and will raise a `TypeError` if
    they are called with the wrong signature. For mocks replacing a class,
    their return value (the 'instance') will have the same spec as the class.

    Instead of `autospec=True` you can pass `autospec=some_object` to use an
    arbitrary object as the spec instead of the one being replaced.

    By default `patch` will fail to replace attributes that don't exist. If
    you pass in `create=True`, and the attribute doesn't exist, patch will
    create the attribute for you when the patched function is called, and
    delete it again afterwards. This is useful for writing tests against
    attributes that your production code creates at runtime. It is off by
    default because it can be dangerous. With it switched on you can write
    passing tests against APIs that don't actually exist!

    Patch can be used as a `TestCase` class decorator. It works by
    decorating each test method in the class. This reduces the boilerplate
    code when your test methods share a common patchings set. `patch` finds
    tests by looking for method names that start with `patch.TEST_PREFIX`.
    By default this is `test`, which matches the way `unittest` finds tests.
    You can specify an alternative prefix by setting `patch.TEST_PREFIX`.

    Patch can be used as a context manager, with the with statement. Here the
    patching applies to the indented block after the with statement. If you
    use "as" then the patched object will be bound to the name after the
    "as"; very useful if `patch` is creating a mock object for you.

    `patch` takes arbitrary keyword arguments. These will be passed to
    the `Mock` (or `new_callable`) on construction.

    `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are
    available for alternate use-cases.
    )r  rP  )
rN  r   r   rS  r   rT  rR  rC   rQ  rU   r   r   r   r   b  s    F       r   c                   @   sR   e Zd ZdZdddZdd Zdd	 Zd
d Zdd Zdd Z	dd Z
eZe
ZdS )_patch_dicta#  
    Patch a dictionary, or dictionary like object, and restore the dictionary
    to its original state after the test.

    `in_dict` can be a dictionary or a mapping like container. If it is a
    mapping then it must at least support getting, setting and deleting items
    plus iterating over keys.

    `in_dict` can also be a string specifying the name of the dictionary, which
    will then be fetched by importing it.

    `values` can be a dictionary of values to set in the dictionary. `values`
    can also be an iterable of `(key, value)` pairs.

    If `clear` is True then the dictionary will be cleared before the new
    values are set.

    `patch.dict` can also be called with arbitrary keyword arguments to set
    values in the dictionary::

        with patch.dict('sys.modules', mymodule=Mock(), other_module=Mock()):
            ...

    `patch.dict` can be used as a context manager, decorator or class
    decorator. When used as a class decorator `patch.dict` honours
    `patch.TEST_PREFIX` for choosing which methods to wrap.
    r   Fc                 K   s,   || _ t|| _| j| || _d | _d S r/   )in_dictdictr   re  clear	_original)rA   r  r   r  rC   r   r   r   r8     s
    
z_patch_dict.__init__c                    s.   t  tr S t  fdd}|S )Nc                     s&      z | |W S   X d S r/   )r  _unpatch_dictr  frA   r   r   _inner  s    z$_patch_dict.__call__.<locals>._inner)r"   r1   rZ  r   )rA   r  r  r   r  r   r9     s
    

z_patch_dict.__call__c                 C   sX   t |D ]J}t||}|tjrt|drt| j| j| j	}||}t
||| q|S r^  )r   r$   r   r   r_  r#   r  r  r   r  rS   )rA   r>  r   r`  Z	decoratorZ	decoratedr   r   r   rZ    s    
z_patch_dict.decorate_classc                 C   s   |    | jS )zPatch the dict.)r  r  r   r   r   r   r~    s    z_patch_dict.__enter__c                 C   s   | j }t| jtrt| j| _| j}| j}z| }W n. tk
rd   i }|D ]}|| ||< qNY nX || _|rxt	| z|
| W n* tk
r   |D ]}|| ||< qY nX d S r/   )r   r"   r  r  rO  r  rV  r:   r  _clear_dictre  )rA   r   r  r  re   r   r   r   r   r    s&    z_patch_dict._patch_dictc                 C   sR   | j }| j}t| z|| W n* tk
rL   |D ]}|| ||< q6Y nX d S r/   )r  r  r  re  r:   )rA   r  re   r   r   r   r   r    s    z_patch_dict._unpatch_dictc                 G   s   |    dS )zUnpatch the dict.F)r  )rA   rB   r   r   r   ry    s    z_patch_dict.__exit__N)r   F)rM   rP   r   rN   r8   r9   rZ  r~  r  r  ry  r  r  r   r   r   r   r    s   
	r  c                 C   s>   z|    W n, tk
r8   t| }|D ]
}| |= q(Y nX d S r/   )r  r:   rY   )r  r   r   r   r   r   r  &  s    r  c                  C   s   t tjD ]} |   q
dS )z7Stop all active patches. LIFO to unroll nested patches.N)r   rP  r  r  )r   r   r   r   _patch_stopall/  s    r  Ztestzlt le gt ge eq ne getitem setitem delitem len contains iter hash str sizeof enter exit divmod rdivmod neg pos abs invert complex int float index round trunc floor ceil bool next fspath aiter zHadd sub mul matmul div floordiv mod lshift rshift and xor or pow truediv c                 c   s   | ]}d | V  qdS )zi%sNr   r   nr   r   r   r.  N  s     r.  c                 c   s   | ]}d | V  qdS )zr%sNr   r  r   r   r   r.  O  s     __get____set__
__delete____reversed____missing__r   __reduce_ex__Z__getinitargs____getnewargs____getstate____setstate____getformat__Z__setformat__r   r  __subclasses__
__format____getnewargs_ex__c                    s    fdd}| |_ |S )z:Turns a callable object (like a mock) into a real functionc                   s    | f||S r/   r   rA   rB   r   r,   r   r   method`  s    z_get_method.<locals>.method)rM   )r   r-   r  r   r,   r   r	  ^  s    r	  c                 C   s   h | ]}d | qS )r   r   )r   r  r   r   r   r   f  s    
__aenter__	__aexit__	__anext__	__aiter__r   r  r8   r   __prepare____instancecheck____subclasscheck____del__c                 C   s
   t | S r/   )r  __hash__r   r   r   r   r   |  r   r   c                 C   s
   t | S r/   )r  __str__r   r   r   r   r   }  r   c                 C   s
   t | S r/   )r  
__sizeof__r   r   r   r   r   ~  r   c                 C   s"   t | j d|   dt|  S )N/)r1   rM   r   r   r   r   r   r   r     r   )r  r  r  
__fspath__r   y              ?g      ?)__lt____gt____le____ge____int__r   __len__ry  __complex__	__float____bool__	__index__r  c                    s    fdd}|S )Nc                    s$    j j}|tk	r|S  | kr dS tS NT)__eq__r   r   NotImplemented)otherret_valr   r   r   r    s    z_get_eq.<locals>.__eq__r   )rA   r  r   r   r   _get_eq  s    r  c                    s    fdd}|S )Nc                    s     j jtk	rtS  | krdS tS NF)__ne__r   r   r  )r  r   r   r   r    s
    z_get_ne.<locals>.__ne__r   )rA   r  r   r   r   _get_ne  s    r  c                    s    fdd}|S )Nc                     s     j j} | tkrtg S t| S r/   )__iter__r   r   r   r  r   r   r   r    s    z_get_iter.<locals>.__iter__r   )rA   r  r   r   r   	_get_iter  s    r  c                    s    fdd}|S )Nc                     s(    j j} | tkrttg S tt| S r/   )r  r   r   _AsyncIteratorr   r  r   r   r   r    s    z"_get_async_iter.<locals>.__aiter__r   )rA   r  r   r   r   _get_async_iter  s    r  )r  r  r  r  c                 C   sb   t |t}|tk	r||_d S t|}|d k	rB|| }||_d S t|}|d k	r^|| |_d S r/   )_return_valuesr^   r   rv   _calculate_return_value_side_effect_methodsr}   )r5   r  r   ZfixedZreturn_calculatorrv   Zside_effectorr   r   r   _set_return_value  s    

r  c                   @   s   e Zd Zdd Zdd ZdS )
MagicMixinc                O   s&   |    tt| j|| |    d S r/   )_mock_set_magicsr   r  r8   r  r   r   r   r8     s    zMagicMixin.__init__c                 C   s   t tB }|}t| dd d k	rX|| j}t }|| }|D ]}|t| jkr:t| | q:|tt| j }t| }|D ]}t	||t
||  qvd S )Nr   )_magicsr:  r$   intersectionr   r  r1   r]   r  rS   
MagicProxy)rA   Zorig_magicsZthese_magicsZremove_magicsr   r=  r   r   r   r    s    zMagicMixin._mock_set_magicsN)rM   rP   r   r8   r  r   r   r   r   r    s   r  c                   @   s   e Zd ZdZdddZdS )r   z-A version of `MagicMock` that isn't callable.Fc                 C   s   |  || |   dS r   r   r  r   r   r   r   r     s    z"NonCallableMagicMock.mock_add_specN)FrM   rP   r   rN   r   r   r   r   r   r     s   r   c                   @   s   e Zd Zdd ZdS )AsyncMagicMixinc                O   s&   |    tt| j|| |    d S r/   )r  r   r  r8   r  r   r   r   r8     s    zAsyncMagicMixin.__init__NrM   rP   r   r8   r   r   r   r   r    s   r  c                   @   s   e Zd ZdZdddZdS )r   a  
    MagicMock is a subclass of Mock with default implementations
    of most of the magic methods. You can use MagicMock without having to
    configure the magic methods yourself.

    If you use the `spec` or `spec_set` arguments then *only* magic
    methods that exist in the spec will be created.

    Attributes and the return value of a `MagicMock` will also be `MagicMocks`.
    Fc                 C   s   |  || |   dS r   r  r   r   r   r   r     s    zMagicMock.mock_add_specN)Fr  r   r   r   r   r     s   
r   c                   @   s&   e Zd Zdd Zdd ZdddZdS )	r  c                 C   s   || _ || _d S r/   r   r   )rA   r   r   r   r   r   r8     s    zMagicProxy.__init__c                 C   s8   | j }| j}|j|||d}t||| t||| |S )N)r   r   r   )r   r   r   rS   r  )rA   r   r   mr   r   r   create_mock  s    zMagicProxy.create_mockNc                 C   s   |   S r/   )r  )rA   r)   r=  r   r   r   r  (  s    zMagicProxy.__get__)N)rM   rP   r   r8   r  r  r   r   r   r   r    s   	r  c                       s   e Zd ZedZedZedZ fddZdd Zdd	 Z	d
d Z
dd Zdd Zdd ZdddZdd Z fddZ  ZS )r   r   r   r   c                   s\   t  j|| tjj| jd< d| jd< d | jd< t | jd< ttd}t	j
|_|| jd< d S )Nr   r   Z_mock_await_countZ_mock_await_argsZ_mock_await_args_listr   r+   )superr8   r%   r   r   r]   rr   r   r   r'   ZCO_COROUTINEco_flags)rA   rB   rC   	code_mockr   r   r   r8   1  s    


zAsyncMockMixin.__init__c                   s  t ||fdd}|  jd7  _|| _| j| | j}|d k	rt|rL|nbt|szt|}W n t	k
rx   t
Y nX t|r|n&t|r|||I d H }n
|||}|tk	r|S | jtk	r| jS | jd k	rt| jr| j||I d H S | j||S | jS )NTrD  r   )rF  r   r   r   r   r}   r3   rX   r   StopIterationStopAsyncIterationr%   r&   r   r   rv   r   )rA   rB   rC   r  rG  rf   r   r   r   rC  A  s6    




z!AsyncMockMixin._execute_mock_callc                 C   s(   | j dkr$d| jpd d}t|dS )zA
        Assert that the mock was awaited at least once.
        r   	Expected r5   z to have been awaited.Nr   r   r  r   r   r   r   r   i  s    
zAsyncMockMixin.assert_awaitedc                 C   s0   | j dks,d| jpd d| j  d}t|dS )z@
        Assert that the mock was awaited exactly once.
        r   r  r5   $ to have been awaited once. Awaited  times.Nr  r   r   r   r   r   q  s    
z"AsyncMockMixin.assert_awaited_oncec                   sz   j dkr& }td| d fdd} f}j }||krvt|trf|nd}t| |dS )zN
        Assert that the last await was with the specified arguments.
        NzExpected await: z
Not awaitedc                     s   j  dd} | S )Nawait)r  r!  r"  r#  r   r   r$    s    z:AsyncMockMixin.assert_awaited_with.<locals>._error_message)r   r  r  r  r"   r%  )rA   rB   rC   r&  r$  r'  r(  r   r#  r   r   z  s    
z"AsyncMockMixin.assert_awaited_withc                O   s8   | j dks,d| jpd d| j  d}t|| j||S )zi
        Assert that the mock was awaited exactly once and with the specified
        arguments.
        r   r  r5   r  r  )r   r   r  r   r)  r   r   r   r     s    
z'AsyncMockMixin.assert_awaited_once_withc                   sZ     ||f} fdd jD }||krVt|tr8|nd} ||}td| |dS )zU
        Assert the mock has ever been awaited with the specified arguments.
        c                    s   g | ]}  |qS r   r*  r+  r   r   r   r     s     z3AsyncMockMixin.assert_any_await.<locals>.<listcomp>Nz%s await not found)r  r   r"   r%  r  r  r9  r   r   r   r     s    zAsyncMockMixin.assert_any_awaitFc           	   	      s    fdd|D }t dd |D d}t fdd jD }|s||kr|dkrXd}ndd	d |D }t| d
t| d j |dS t|}g }|D ]2}z|| W q tk
r   || Y qX q|rtdt	|f |dS )a  
        Assert the mock has been awaited with the specified calls.
        The :attr:`await_args_list` list is checked for the awaits.

        If `any_order` is False (the default) then the awaits must be
        sequential. There can be extra calls before or after the
        specified awaits.

        If `any_order` is True then the awaits can be in any order, but
        they must all appear in :attr:`await_args_list`.
        c                    s   g | ]}  |qS r   r*  r+  r   r   r   r     s     z4AsyncMockMixin.assert_has_awaits.<locals>.<listcomp>c                 s   s   | ]}t |tr|V  qd S r/   r-  r   r   r   r   r.    s     
 z3AsyncMockMixin.assert_has_awaits.<locals>.<genexpr>Nc                 3   s   | ]}  |V  qd S r/   r*  r+  r   r   r   r.    s     zAwaits not found.z,Error processing expected awaits.
Errors: {}c                 S   s   g | ]}t |tr|nd qS r/   r-  r   r   r   r   r     s   r/  z	
Actual: z%r not all found in await list)
r   rr   r   r1  r  rY   r3  r<   r   rZ   )	rA   r4  r5  r&  r(  Z
all_awaitsr6  r7  r8  r   r   r   r     s>    z AsyncMockMixin.assert_has_awaitsc                 C   s0   | j dkr,d| jpd d| j  d}t|dS )z9
        Assert that the mock was never awaited.
        r   r  r5   z# to not have been awaited. Awaited r  Nr  r   r   r   r   r     s    
z!AsyncMockMixin.assert_not_awaitedc                   s&   t  j|| d| _d| _t | _dS )z0
        See :func:`.Mock.reset_mock()`
        r   N)r  ru   r   r   rr   r   r@   r  r   r   ru     s    zAsyncMockMixin.reset_mock)F)rM   rP   r   r   r   r   r   r8   rC  r   r   r   r   r   r   r   ru   __classcell__r   r   r  r   r   ,  s   (	
,	r   c                   @   s   e Zd ZdZdS )r	   aa  
    Enhance :class:`Mock` with features allowing to mock
    an async function.

    The :class:`AsyncMock` object will behave so the object is
    recognized as an async function, and the result of a call is an awaitable:

    >>> mock = AsyncMock()
    >>> asyncio.iscoroutinefunction(mock)
    True
    >>> inspect.isawaitable(mock())
    True


    The result of ``mock()`` is an async function which will have the outcome
    of ``side_effect`` or ``return_value``:

    - if ``side_effect`` is a function, the async function will return the
      result of that function,
    - if ``side_effect`` is an exception, the async function will raise the
      exception,
    - if ``side_effect`` is an iterable, the async function will return the
      next value of the iterable, however, if the sequence of result is
      exhausted, ``StopIteration`` is raised immediately,
    - if ``side_effect`` is not defined, the async function will return the
      value defined by ``return_value``, hence, by default, the async function
      returns a new :class:`AsyncMock` object.

    If the outcome of ``side_effect`` or ``return_value`` is an async function,
    the mock async function obtained when the mock object is called will be this
    async function itself (and not an async function returning an async
    function).

    The test author can also specify a wrapped object with ``wraps``. In this
    case, the :class:`Mock` object behavior is the same as with an
    :class:`.Mock` object: the wrapped object may have methods
    defined as async function functions.

    Based on Martin Richard's asynctest project.
    NrH  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S )	_ANYz2A helper object that compares equal to everything.c                 C   s   dS r  r   rA   r  r   r   r   r  	  s    z_ANY.__eq__c                 C   s   dS r  r   r  r   r   r   r  	  s    z_ANY.__ne__c                 C   s   dS )Nz<ANY>r   r   r   r   r   r   	  s    z_ANY.__repr__N)rM   rP   r   rN   r  r  r   r   r   r   r   r  	  s   r  c                 C   s`   d|  }d}d dd |D }d dd | D }|r@|}|rX|rP|d7 }||7 }|| S )Nz%s(%%s)r   z, c                 S   s   g | ]}t |qS r   )reprr   r   r   r   r   !	  s     z*_format_call_signature.<locals>.<listcomp>c                 S   s   g | ]\}}d ||f qS )z%s=%rr   )r   r   r   r   r   r   r   "	  s    )r   r   )r   rB   rC   r  Zformatted_argsZargs_stringZkwargs_stringr   r   r   r  	  s    
r  c                   @   s   e Zd ZdZd!ddZd"d	d
Zdd ZejZdd Z	dd Z
dd Zdd Zdd Zdd Zedd Zedd Zdd Zdd  ZdS )#rF  a  
    A tuple for holding the results of a call to a mock, either in the form
    `(args, kwargs)` or `(name, args, kwargs)`.

    If args or kwargs are empty then a call tuple will compare equal to
    a tuple without those values. This makes comparisons less verbose::

        _Call(('name', (), {})) == ('name',)
        _Call(('name', (1,), {})) == ('name', (1,))
        _Call(((), {'a': 'b'})) == ({'a': 'b'},)

    The `_Call` object provides a useful shortcut for comparing with call::

        _Call(((1, 2), {'a': 3})) == call(1, 2, a=3)
        _Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3)

    If the _Call has no name then it will match any name.
    r   r   NFTc                 C   s   d}i }t |}|dkr$|\}}}nr|dkrd|\}	}
t|	trX|	}t|
trR|
}qb|
}q|	|
 }}n2|dkr|\}t|tr|}nt|tr|}n|}|rt| ||fS t| |||fS )Nr      r   r   )r   r"   r  rZ   r   )r   r   r   r   rE  	from_kallrB   rC   _lenfirstsecondr   r   r   r   C	  s.    



z_Call.__new__c                 C   s   || _ || _|| _d S r/   )r   r   _mock_from_kall)rA   r   r   r   rE  r  r   r   r   r8   c	  s    z_Call.__init__c                 C   sh  |t krdS zt|}W n tk
r.   Y dS X d}t| dkrJ| \}}n
| \}}}t| dd r|t|dd r|| j|jkr|dS d}|dkrdi  }}n|dkr|\}}}n|d	kr|\}	t|	tr|	}i }n"t|	tr|	}di  }}nd}|	}nV|dkr@|\}
}t|
tr4|
}t|tr(|i  }}n
d| }}n
|
| }}ndS |rX||krXdS ||f||fkS )
NTFr   r   r   r   r   r  r   )r   r   r  r$   r   r"   rZ   r  )rA   r  Z	len_otherZ	self_nameZ	self_argsZself_kwargsZ
other_nameZ
other_argsZother_kwargsr   r  r  r   r   r   r  j	  sR    





z_Call.__eq__c                O   s<   | j d krtd||fddS | j d }t| j ||f|| dS )Nr   r   r   r  r   rF  r  r   r   r   r9   	  s    

z_Call.__call__c                 C   s2   | j d krt|ddS d| j |f }t|| ddS )NF)r   r  z%s.%s)r   r   r  r  )rA   r   r   r   r   r   r   	  s    
z_Call.__getattr__c                 C   s   |t jkrtt | |S r/   )rZ   r]   r:   __getattribute__)rA   r   r   r   r   r  	  s    
z_Call.__getattribute__c                O   s   |  d||S )Nr   r   r@   r   r   r   r   	  s    z_Call.countc                O   s   |  d||S )Nindexr  r@   r   r   r   r  	  s    z_Call.indexc                 C   s(   t | dkr| \}}n
| \}}}||fS )Nr   )r   r  r   r   r   _get_call_arguments	  s    

z_Call._get_call_argumentsc                 C   s   |   d S Nr   r  r   r   r   r   rB   	  s    z
_Call.argsc                 C   s   |   d S )Nr   r  r   r   r   r   rC   	  s    z_Call.kwargsc                 C   s|   | j s&| jpd}|dr"d| }|S t| dkr@d}| \}}n0| \}}}|sTd}n|dshd| }nd| }t|||S )Nr   r   zcall%sr   zcall.%s)r  r   r   r   r  )rA   r   rB   rC   r   r   r   r   	  s    





z_Call.__repr__c                 C   s4   g }| }|dk	r(|j r || |j}qtt|S )zFor a call object that represents multiple calls, `call_list`
        returns a list of all the intermediate calls as well as the
        final call.N)r  r   r   rr   r   )rA   ZvalsrJ  r   r   r   	call_list	  s    
z_Call.call_list)r   r   NFT)r   NNFT)rM   rP   r   rN   r   r8   r  r  r  r9   r   r  r   r  r  r   rB   rC   r   r  r   r   r   r   rF  0	  s*     
   
7

rF  )r  c              	   K   sl  t | rt| } t| t}t| }d| i}|r8d| i}n| dkrDi }|rT|rTd|d< || t}	t| rri }n8|r|rtdt	}	n"t
| st}	n|r|rt| st}	|d|}|}
|dkrd}
|	f |||
|d	|}t| trt|| }|rt| nt| ||| |dk	r,|s,||j|< |rV|sVd
|krVt| |dd|d|_t| D ]}t|rrq^zt| |}W n tk
r   Y q^Y nX d|i}|rd|i}t|tst|||||}||j|< np|}t| tr|j}t| ||}||d< t|rt	}nt}|f ||||d|}||j|< t|||d t|tr^t||| q^|S )aI  Create a mock object using another object as a spec. Attributes on the
    mock will use the corresponding attribute on the `spec` object as their
    spec.

    Functions or methods being mocked will have their arguments checked
    to check that they are called with the correct signature.

    If `spec_set` is True then attempting to set attributes that don't exist
    on the spec object will raise an `AttributeError`.

    If a class is used as a spec then the return value of the mock (the
    instance of the class) will have the same spec. You can use a class as the
    spec for an instance object by passing `instance=True`. The returned mock
    will only be callable if instances of the mock are callable.

    `create_autospec` also takes arbitrary keyword arguments that are passed to
    the constructor of the created mock.r   r   NTr   zJInstance can not be True when create_autospec is mocking an async functionr   r   )r   r   r   r   rv   r   )rK   rt  r   r   )r   r   r   r   )rJ   )r[   r1   r"   r.   re  r   r'   ZisdatadescriptorRuntimeErrorr	   rX   r   r`   r   r6   ri   r   rL   r~   r   rv   r   r   r$   r:   r   r5   
_must_skipr%   r&   rS   )r   r   rK   r   rt  rC   is_typeZis_async_funcr}  r|  r   r5   r   re   r   r   rJ   Zchild_klassr   r   r   r   	  s    







 


r   c                 C   sx   t | ts$|t| di krdS | j} | jD ]H}|j|t}|tkrFq*t |tt	frZ dS t |t
rl|  S  dS q*|S )z[
    Return whether we should skip the first argument on spec's `entry`
    attribute.
    r]   F)r"   r1   r$   r   r\   r]   r^   r   rV   rW   r6   )r   r   r  r>  rf   r   r   r   r  w
  s    


r  c                   @   s   e Zd ZdddZdS )r   FNc                 C   s(   || _ || _|| _|| _|| _|| _d S r/   )r   idsr   r   rK   r   )rA   r   r   r   r   r  rK   r   r   r   r8   
  s    z_SpecState.__init__)FNNNFr  r   r   r   r   r   
  s
         r   c                 C   s"   t | trt| S t| S d S r/   )r"   bytesioBytesIOStringIO)	read_datar   r   r   
_to_stream
  s    

r  r   c                    s&  t }|dgfdd}fdd} fddfdd	 fd
d}tdkrddl}ttt|jtt|ja| dkrt	dt
d} t	tdj_dj_dj_dj_dj_|j_ d< d j_|j_ j_|j_fdd}|| _| _| S )a  
    A helper function to create a mock to replace the use of `open`. It works
    for `open` called directly or used as a context manager.

    The `mock` argument is the mock object to configure. If `None` (the
    default) then a `MagicMock` will be created for you, with the API limited
    to methods or attributes available on standard file handles.

    `read_data` is a string for the `read`, `readline` and `readlines` of the
    file handle to return.  This is an empty string by default.
    Nc                     s$   j jd k	rj jS  d j | |S r  )	readlinesrv   ra   _statehandler   r   _readlines_side_effect
  s    z)mock_open.<locals>._readlines_side_effectc                     s$   j jd k	rj jS  d j | |S r  )readrv   ra   r  r   r   _read_side_effect
  s    z$mock_open.<locals>._read_side_effectc                  ?   s$     E d H  d j | |V  qd S r  )readlinera   )_iter_side_effectr  r   r   _readline_side_effect
  s    z(mock_open.<locals>._readline_side_effectc                  3   s0   j jd k	rj jV  q d D ]
} | V  q d S r  )r  rv   )liner  r   r   r  
  s    z$mock_open.<locals>._iter_side_effectc                      s    j jd k	rj jS t d S r  )r  rv   r   r   r  r   r   _next_side_effect
  s    z$mock_open.<locals>._next_side_effectr   open)r   r   r   r   c                     s6   t d< jjd kr2  d< d j_tS )Nr   r   )r  r  r}   r   ra   )r  r  r  r  r   r   
reset_data
  s
    
zmock_open.<locals>.reset_data)r  	file_spec_iorY   r  r   TextIOWrapperunionr  r   r  r~  rv   writer
  r  r  r}   r  r   )r5   r  Z
_read_datar	  r  r  r  r  r   )r  r  r  r  r  r   r   
  s8    "

r   c                   @   s*   e Zd ZdZdd Zd	ddZdd ZdS )
r   aW  
    A mock intended to be used as a property, or other descriptor, on a class.
    `PropertyMock` provides `__get__` and `__set__` methods so you can specify
    a return value when it is fetched.

    Fetching a `PropertyMock` instance from an object calls the mock, with
    no args. Setting it calls the mock with the value being set.
    c                K   s
   t f |S r/   )r   )rA   rC   r   r   r   r     s    zPropertyMock._get_child_mockNc                 C   s   |  S r/   r   )rA   r)   Zobj_typer   r   r   r    s    zPropertyMock.__get__c                 C   s   | | d S r/   r   )rA   r)   r   r   r   r   r    s    zPropertyMock.__set__)N)rM   rP   r   rN   r   r  r  r   r   r   r   r   
  s   
r   c              	   C   s^   d| _ t| D ]J}zt| |}W n tk
r8   Y qY nX t|tsFq|j| krt| qdS )a  Disable the automatic generation of child mocks.

    Given an input Mock, seals it to ensure no further mocks will be generated
    when accessing an attribute that was not already defined.

    The operation recursively seals the mock passed in, meaning that
    the mock itself, any mocks generated by accessing one of its attributes,
    and all assigned mocks without a name or spec will be sealed.
    TN)r   r   r$   r:   r"   r   r   r   )r5   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S )	r  z8
    Wraps an iterator in an asynchronous iterator.
    c                 C   s&   || _ ttd}tj|_|| jd< d S )Nr  r+   )iteratorr   r   r'   ZCO_ITERABLE_COROUTINEr  r]   )rA   r  r  r   r   r   r8   +  s    
z_AsyncIterator.__init__c                 C   s   | S r/   r   r   r   r   r   r  1  s    z_AsyncIterator.__aiter__c                    s*   zt | jW S  tk
r    Y nX td S r/   )r   r  r  r  r   r   r   r   r  4  s
    z_AsyncIterator.__anext__N)rM   rP   r   rN   r8   r  r  r   r   r   r   r  '  s   r  )F)F)NFNNN)FFNN)Nr   )y__all____version__r%   ra  r   r'   r   rz  builtinstypesr   r   r   Zunittest.utilr   	functoolsr   r   r   rq  r
   r  r   r*   r.   r!   r3   r7   r=   rL   rG   rX   r[   r`   ri   rd   r   r   r  r   r   r   r   MISSINGr  ZDELETEDr   r   r   rY   rr   r   r   r   r   r   r<  r   rM  rO  rP  r  r  r  r   r  r  r  r  ZmultipleZstopallr_  Zmagic_methodsZnumericsr   r   ZinplacerightZ_non_defaultsr	  r  r:  Z_sync_async_magicsZ_async_magicsr;  r   r  r  r  r  r  r  r  r  r  r  r  r   r  r   r  r   r	   r  r   r  rZ   rF  r   r   r  r   r1   r  r6   r  r  r   r   r   r  r   r   r   r   <module>   s~  	


1          	h4  <   
    
2    
Mw	             	
    
	
		 8+ B
  
 
N                                                                                                                                                                                                                                                                                                                                                                                                                                                                        runner.cpython-38.opt-1.pyc                                                                         0000644                 00000015552 15175327600 0011462 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5dW                     @   sn   d Z ddlZddlZddlZddlmZ ddlmZ dZG dd de	Z
G d	d
 d
ejZG dd de	ZdS )zRunning tests    N   )result)registerResultTc                   @   s*   e Zd ZdZdd Zdd Zd	ddZdS )
_WritelnDecoratorz@Used to decorate file-like objects with a handy 'writeln' methodc                 C   s
   || _ d S N)stream)selfr    r	   '/usr/lib64/python3.8/unittest/runner.py__init__   s    z_WritelnDecorator.__init__c                 C   s   |dkrt |t| j|S )N)r   __getstate__)AttributeErrorgetattrr   )r   attrr	   r	   r
   __getattr__   s    z_WritelnDecorator.__getattr__Nc                 C   s   |r|  | |  d d S N
)write)r   argr	   r	   r
   writeln   s    
z_WritelnDecorator.writeln)N)__name__
__module____qualname____doc__r   r   r   r	   r	   r	   r
   r      s   r   c                       s   e Zd ZdZdZdZ fddZdd Z fdd	Z fd
dZ	 fddZ
 fddZ fddZ fddZ fddZdd Zdd Z  ZS )TextTestResultzhA test result class that can print formatted text results to a stream.

    Used by TextTestRunner.
    zF======================================================================zF----------------------------------------------------------------------c                    s8   t t| ||| || _|dk| _|dk| _|| _d S )Nr   )superr   r   r   showAlldotsdescriptions)r   r   r   	verbosity	__class__r	   r
   r   %   s
    

zTextTestResult.__init__c                 C   s0   |  }| jr$|r$dt||fS t|S d S r   )ZshortDescriptionr   joinstr)r   testZdoc_first_liner	   r	   r
   getDescription,   s    
zTextTestResult.getDescriptionc                    sB   t t| | | jr>| j| | | jd | j  d S )Nz ... )r   r   	startTestr   r   r   r%   flushr   r$   r    r	   r
   r&   3   s
    zTextTestResult.startTestc                    sD   t t| | | jr$| jd n| jr@| jd | j  d S )Nok.)	r   r   
addSuccessr   r   r   r   r   r'   r(   r    r	   r
   r+   :   s    zTextTestResult.addSuccessc                    sF   t t| || | jr&| jd n| jrB| jd | j  d S )NERRORE)	r   r   addErrorr   r   r   r   r   r'   r   r$   errr    r	   r
   r.   B   s    zTextTestResult.addErrorc                    sF   t t| || | jr&| jd n| jrB| jd | j  d S )NFAILF)	r   r   
addFailurer   r   r   r   r   r'   r/   r    r	   r
   r3   J   s    zTextTestResult.addFailurec                    sL   t t| || | jr,| jd| n| jrH| jd | j	  d S )Nzskipped {0!r}s)
r   r   addSkipr   r   r   formatr   r   r'   )r   r$   reasonr    r	   r
   r5   R   s    zTextTestResult.addSkipc                    sF   t t| || | jr&| jd n| jrB| jd | j  d S )Nzexpected failurex)	r   r   addExpectedFailurer   r   r   r   r   r'   r/   r    r	   r
   r9   Z   s    z!TextTestResult.addExpectedFailurec                    sD   t t| | | jr$| jd n| jr@| jd | j  d S )Nzunexpected successu)	r   r   addUnexpectedSuccessr   r   r   r   r   r'   r(   r    r	   r
   r;   b   s    z#TextTestResult.addUnexpectedSuccessc                 C   s6   | j s| jr| j  | d| j | d| j d S )Nr,   r1   )r   r   r   r   printErrorListerrorsfailuresr   r	   r	   r
   printErrorsj   s    
zTextTestResult.printErrorsc                 C   sX   |D ]N\}}| j | j | j d|| |f  | j | j | j d|  qd S )Nz%s: %sz%s)r   r   
separator1r%   
separator2)r   Zflavourr=   r$   r0   r	   r	   r
   r<   p   s
    zTextTestResult.printErrorList)r   r   r   r   rA   rB   r   r%   r&   r+   r.   r3   r5   r9   r;   r@   r<   __classcell__r	   r	   r    r
   r      s   r   c                   @   s4   e Zd ZdZeZdddddZd	d
 Zdd ZdS )TextTestRunnerzA test runner class that displays results in textual form.

    It prints out the names of tests as they are run, errors as they
    occur, and a summary of the results at the end of the test run.
    NTr   F)	tb_localsc          	      C   sN   |dkrt j}t|| _|| _|| _|| _|| _|| _|| _	|dk	rJ|| _
dS )zConstruct a TextTestRunner.

        Subclasses should accept **kwargs to ensure compatibility as the
        interface changes.
        N)sysstderrr   r   r   r   failfastbufferrE   warningsresultclass)	r   r   r   r   rH   rI   rK   rJ   rE   r	   r	   r
   r      s    
zTextTestRunner.__init__c                 C   s   |  | j| j| jS r   )rK   r   r   r   r?   r	   r	   r
   _makeResult   s    zTextTestRunner._makeResultc                 C   s2  |   }t| | j|_| j|_| j|_t  | jr^t| j | jdkr^tjdt	dd t
 }t|dd}|dk	r|  z|| W 5 t|dd}|dk	r|  X t
 }W 5 Q R X || }|  t|dr| j|j |j}| jd	||d
kodpd|f  | j  d }	 }
}ztt|j|j|jf}W n tk
rT   Y nX |\}	}
}g }| s| jd t|jt|j }}|r|d|  |r|d|  n| jd |r|d|  |	r|d|	  |
r|d|
  |r"| jdd|f  n| jd |S )z&Run the given test case or test suite.)defaultalwaysmodulezPlease use assert\w+ instead.)categorymessagestartTestRunNstopTestRunrB   zRan %d test%s in %.3fsr   r4    r   ZFAILEDzfailures=%dz	errors=%dZOKz
skipped=%dzexpected failures=%dzunexpected successes=%dz (%s)z, r   )rL   r   rH   rI   rE   rJ   catch_warningssimplefilterfilterwarningsDeprecationWarningtimeperf_counterr   r@   hasattrr   r   rB   ZtestsRunmaplenZexpectedFailuresunexpectedSuccessesskippedr   ZwasSuccessfulr   r>   r=   appendr"   )r   r$   r   Z	startTimerR   rS   ZstopTimeZ	timeTakenrunZexpectedFailsr^   r_   ZresultsZinfosZfailedZerroredr	   r	   r
   ra      sx    






zTextTestRunner.run)NTr   FFNN)	r   r   r   r   r   rK   r   rL   ra   r	   r	   r	   r
   rD   x   s           rD   )r   rF   rY   rJ   rT   r   Zsignalsr   Z
__unittestobjectr   Z
TestResultr   rD   r	   r	   r	   r
   <module>   s   [                                                                                                                                                      async_case.cpython-38.opt-2.pyc                                                                     0000644                 00000010005 15175327600 0012246 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   s0   d dl Z d dlZddlmZ G dd deZdS )    N   )TestCasec                       s   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dd Zdd Zdd Zd  fdd	Z  ZS )!IsolatedAsyncioTestCaserunTestc                    s   t  | d | _d | _d S N)super__init___asyncioTestLoop_asyncioCallsQueue)selfZ
methodName	__class__ +/usr/lib64/python3.8/unittest/async_case.pyr   "   s    z IsolatedAsyncioTestCase.__init__c                    s   d S r   r   r   r   r   r   
asyncSetUp'   s    z"IsolatedAsyncioTestCase.asyncSetUpc                    s   d S r   r   r   r   r   r   asyncTearDown*   s    z%IsolatedAsyncioTestCase.asyncTearDownc                O   s   | j |f|| d S r   )Z
addCleanup)r   funcargskwargsr   r   r   addAsyncCleanup-   s    z'IsolatedAsyncioTestCase.addAsyncCleanupc                 C   s   |    | | j d S r   )ZsetUp
_callAsyncr   r   r   r   r   
_callSetUp<   s    z"IsolatedAsyncioTestCase._callSetUpc                 C   s   |  | d S r   _callMaybeAsync)r   methodr   r   r   _callTestMethod@   s    z'IsolatedAsyncioTestCase._callTestMethodc                 C   s   |  | j |   d S r   )r   r   ZtearDownr   r   r   r   _callTearDownC   s    z%IsolatedAsyncioTestCase._callTearDownc                 O   s   | j |f|| d S r   r   )r   Zfunctionr   r   r   r   r   _callCleanupG   s    z$IsolatedAsyncioTestCase._callCleanupc                O   s0   |||}| j  }| j||f | j |S r   )r	   create_futurer
   
put_nowaitrun_until_completer   r   r   r   retfutr   r   r   r   J   s    

z"IsolatedAsyncioTestCase._callAsyncc                O   sB   |||}t |r:| j }| j||f | j|S |S d S r   )inspectZisawaitabler	   r   r
   r    r!   r"   r   r   r   r   R   s    


z'IsolatedAsyncioTestCase._callMaybeAsyncc              
      s   t   | _}|d  | I d H }|  |d kr:d S |\}}z |I d H }| s`|| W q ttfk
r|    Y q t	t j
fk
r } z| s|| W 5 d }~X Y qX qd S r   )asyncioZQueuer
   Z
set_resultgetZ	task_done	cancelled
SystemExitKeyboardInterruptBaseExceptionZCancelledErrorZset_exception)r   r$   ZqueueZqueryZ	awaitabler#   Zexr   r   r   _asyncioLoopRunner\   s     

z*IsolatedAsyncioTestCase._asyncioLoopRunnerc                 C   sJ   t  }t | |d || _| }|| || _|	| d S )NT)
r&   Znew_event_loopset_event_loopZ	set_debugr	   r   Zcreate_taskr,   Z_asyncioCallsTaskr!   )r   loopr$   r   r   r   _setupAsyncioLoopo   s    

z)IsolatedAsyncioTestCase._setupAsyncioLoopc              	   C   s   | j }d | _ | jd  || j  zt|}|s@W vd S |D ]}|	  qD|tj
||dd |D ]0}| r|qn| d k	rn|d| |d qn||  W 5 td  |  X d S )NT)r.   Zreturn_exceptionsz(unhandled exception during test shutdown)message	exceptiontask)r	   r
   r    r!   joinr&   r-   closeZ	all_tasksZcancelZgatherr(   r1   Zcall_exception_handlerZshutdown_asyncgens)r   r.   Z	to_cancelr2   r   r   r   _tearDownAsyncioLoopy   s2    



z,IsolatedAsyncioTestCase._tearDownAsyncioLoopNc                    s(   |    zt |W S |   X d S r   )r/   r5   r   run)r   resultr   r   r   r6      s    zIsolatedAsyncioTestCase.run)r   )N)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   r   r,   r/   r5   r6   __classcell__r   r   r   r   r      s   

"r   )r&   r%   Zcaser   r   r   r   r   r   <module>   s                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              async_case.cpython-38.pyc                                                                           0000644                 00000010131 15175327600 0011306 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                     @   s0   d dl Z d dlZddlmZ G dd deZdS )    N   )TestCasec                       s   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dd Zdd Zdd Zd  fdd	Z  ZS )!IsolatedAsyncioTestCaserunTestc                    s   t  | d | _d | _d S N)super__init___asyncioTestLoop_asyncioCallsQueue)selfZ
methodName	__class__ +/usr/lib64/python3.8/unittest/async_case.pyr   "   s    z IsolatedAsyncioTestCase.__init__c                    s   d S r   r   r   r   r   r   
asyncSetUp'   s    z"IsolatedAsyncioTestCase.asyncSetUpc                    s   d S r   r   r   r   r   r   asyncTearDown*   s    z%IsolatedAsyncioTestCase.asyncTearDownc                O   s   | j |f|| d S r   )Z
addCleanup)r   funcargskwargsr   r   r   addAsyncCleanup-   s    z'IsolatedAsyncioTestCase.addAsyncCleanupc                 C   s   |    | | j d S r   )ZsetUp
_callAsyncr   r   r   r   r   
_callSetUp<   s    z"IsolatedAsyncioTestCase._callSetUpc                 C   s   |  | d S r   _callMaybeAsync)r   methodr   r   r   _callTestMethod@   s    z'IsolatedAsyncioTestCase._callTestMethodc                 C   s   |  | j |   d S r   )r   r   ZtearDownr   r   r   r   _callTearDownC   s    z%IsolatedAsyncioTestCase._callTearDownc                 O   s   | j |f|| d S r   r   )r   Zfunctionr   r   r   r   r   _callCleanupG   s    z$IsolatedAsyncioTestCase._callCleanupc                O   sL   | j d k	st|||}t|s&t| j  }| j||f | j |S r   r	   AssertionErrorinspectZisawaitablecreate_futurer
   
put_nowaitrun_until_completer   r   r   r   retfutr   r   r   r   J   s    

z"IsolatedAsyncioTestCase._callAsyncc                O   sP   | j d k	st|||}t|rH| j  }| j||f | j |S |S d S r   r   r%   r   r   r   r   R   s    


z'IsolatedAsyncioTestCase._callMaybeAsyncc              
      s   t   | _}|d  | I d H }|  |d kr:d S |\}}z |I d H }| s`|| W q ttfk
r|    Y q t	t j
fk
r } z| s|| W 5 d }~X Y qX qd S r   )asyncioZQueuer
   Z
set_resultgetZ	task_done	cancelled
SystemExitKeyboardInterruptBaseExceptionZCancelledErrorZset_exception)r   r'   ZqueueZqueryZ	awaitabler&   Zexr   r   r   _asyncioLoopRunner\   s     

z*IsolatedAsyncioTestCase._asyncioLoopRunnerc                 C   sX   | j d kstt }t| |d || _ | }|| || _	|
| d S )NT)r	   r    r(   Znew_event_loopset_event_loopZ	set_debugr"   Zcreate_taskr.   Z_asyncioCallsTaskr$   )r   loopr'   r   r   r   _setupAsyncioLoopo   s    

z)IsolatedAsyncioTestCase._setupAsyncioLoopc              	   C   s   | j d k	st| j }d | _ | jd  || j  zt	|}|sNW vd S |D ]}|
  qR|tj||dd |D ]0}| rq|| d k	r||d| |d q|||  W 5 td  |  X d S )NT)r0   Zreturn_exceptionsz(unhandled exception during test shutdown)message	exceptiontask)r	   r    r
   r#   r$   joinr(   r/   closeZ	all_tasksZcancelZgatherr*   r3   Zcall_exception_handlerZshutdown_asyncgens)r   r0   Z	to_cancelr4   r   r   r   _tearDownAsyncioLoopy   s4    



z,IsolatedAsyncioTestCase._tearDownAsyncioLoopNc                    s(   |    zt |W S |   X d S r   )r1   r7   r   run)r   resultr   r   r   r8      s    zIsolatedAsyncioTestCase.run)r   )N)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   r   r.   r1   r7   r8   __classcell__r   r   r   r   r      s   

"r   )r(   r!   Zcaser   r   r   r   r   r   <module>   s                                                                                                                                                                                                                                                                                                                                                                                                                                          main.cpython-38.opt-1.pyc                                                                           0000644                 00000016560 15175327600 0011075 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d+                     @   st   d Z ddlZddlZddlZddlmZmZ ddlmZ dZ	dZ
dZd	d
 Zdd Zdd ZG dd deZeZdS )zUnittest main program    N   )loaderrunner)installHandlerTa  Examples:
  %(prog)s test_module               - run tests from test_module
  %(prog)s module.TestClass          - run tests from module.TestClass
  %(prog)s module.Class.test_method  - run specified test method
  %(prog)s path/to/test_file.py      - run tests from test_file.py
aF  Examples:
  %(prog)s                           - run default set of tests
  %(prog)s MyTestSuite               - run suite 'MyTestSuite'
  %(prog)s MyTestCase.testSomething  - run MyTestCase.testSomething
  %(prog)s MyTestCase                - run all 'test*' test methods
                                       in MyTestCase
c                 C   sx   t j| rt|  drtt j| rXt j| t  }t j|sP|t j	rT| S |} | d d 
dd
ddS | S )Nz.py\./)ospathisfilelowerendswithisabsrelpathgetcwd
startswithpardirreplace)nameZrel_path r   %/usr/lib64/python3.8/unittest/main.py_convert_name   s    r   c                 C   s   dd | D S )Nc                 S   s   g | ]}t |qS r   )r   ).0r   r   r   r   
<listcomp>.   s     z"_convert_names.<locals>.<listcomp>r   )namesr   r   r   _convert_names-   s    r   c                 C   s   d| krd|  } | S )N*z*%s*r   )patternr   r   r   _convert_select_pattern1   s    r   c                   @   s   e Zd ZdZdZdZd Z Z Z Z	 Z
ZdZddddejddddddfdddd	Zdd
dZdd Zdd ZdddZdd Zdd Zdd Zdd Zd ddZdd ZdS )!TestProgramzA command-line program that runs a set of tests; this is primarily
       for making test modules conveniently executable.
    Nr   __main__TF)	tb_localsc                C   s   t |tr<t|| _|ddd  D ]}t| j|| _q&n|| _|d krPtj}|| _|| _	|	| _
|| _|
| _|| _|d krtjsd| _n|| _|| _|| _|| _tj|d | _| | |   d S )Nr   r   defaultr   )
isinstancestr
__import__modulesplitgetattrsysargvexitfailfast
catchbreak	verbositybufferr"   warnoptionswarningsdefaultTest
testRunner
testLoaderr
   r   basenameprogName	parseArgsrunTests)selfr'   r3   r+   r4   r5   r,   r/   r-   r.   r0   r2   r"   partr   r   r   __init__A   s,    


zTestProgram.__init__c                 C   s4   |rt | | jd kr|   |   td d S )N   )print_discovery_parser_initArgParsers_print_helpr*   r,   )r:   msgr   r   r   	usageExitg   s    
zTestProgram.usageExitc                 O   sZ   | j d kr6t| j  ttd| ji  | j  n t| j  ttd| ji  d S )Nprog)	r'   r>   _main_parserZformat_helpMAIN_EXAMPLESr7   r?   
print_helpMODULE_EXAMPLES)r:   argskwargsr   r   r   rA   o   s    
zTestProgram._print_helpc                 C   s   |    | jd krpt|dkrD|d  dkrD| |dd   d S | j|dd  |  | js| g  d S n| j|dd  |  | jrt| j| _	t
dkrd | _n6| jd krd | _	n$t| jtr| jf| _	nt| j| _	|   d S )Nr   discoverr=   r!   )r@   r'   lenr   _do_discoveryrE   
parse_argstestsr   	testNames__name__r3   r$   r%   listcreateTests)r:   r+   r   r   r   r8   x   s(    


zTestProgram.parseArgsc                 C   st   | j r| j | j_ |r@|d kr"| jn| }|| j| j| j| _n0| jd kr\| j| j	| _n| j
| j| j	| _d S N)testNamePatternsr5   rK   startr   toptestrP   ZloadTestsFromModuler'   ZloadTestsFromNames)r:   from_discoveryLoaderr   r   r   r   rS      s    


zTestProgram.createTestsc                 C   s$   |   }| || _| || _d S rT   )_getParentArgParser_getMainArgParserrE   _getDiscoveryArgParserr?   )r:   Zparent_parserr   r   r   r@      s    zTestProgram._initArgParsersc                 C   s   t jdd}|jddddddd	 |jd
dddddd	 |jddddd | jd krn|jdddddd d| _| jd kr|jdddddd d| _| jd kr|jdddddd d| _| jd kr|jdd d!td"d# g | _|S )$NF)Zadd_helpz-vz	--verboser/   Zstore_constr=   zVerbose output)destactionZconsthelpz-qz--quietr   zQuiet outputz--localsr"   
store_truez"Show local variables in tracebacks)r^   r_   r`   z-fz
--failfastr-   zStop on first fail or errorz-cz--catchr.   z'Catch Ctrl-C and display results so farz-bz--bufferr0   z%Buffer stdout and stderr during testsz-krU   appendz.Only run tests which match the given substring)r^   r_   typer`   )argparseArgumentParseradd_argumentr-   r.   r0   rU   r   )r:   parserr   r   r   r[      sR    
 
 






 zTestProgram._getParentArgParserc                 C   s2   t j|gd}| j|_| j|_|jdddd |S )NparentsrO   r   z?a list of any number of test modules, classes and test methods.)nargsr`   )rd   re   r7   rD   rA   rG   rf   )r:   parentrg   r   r   r   r\      s    zTestProgram._getMainArgParserc                 C   sz   t j|gd}d| j |_d|_|jddddd |jd	d
ddd |jddddd dD ]}|j|dt jt jd qZ|S )Nrh   z%s discoverzcFor test discovery all test modules must be importable from the top level directory of the project.z-sz--start-directoryrV   z*Directory to start discovery ('.' default))r^   r`   z-pz	--patternr   z+Pattern to match tests ('test*.py' default)z-tz--top-level-directoryrW   z<Top level directory of project (defaults to start directory))rV   r   rW   ?)rj   r#   r`   )rd   re   r7   rD   Zepilogrf   ZSUPPRESS)r:   rk   rg   argr   r   r   r]      s$    


z"TestProgram._getDiscoveryArgParserc                 C   sL   d| _ d| _d | _|d k	r:| jd kr,|   | j||  | jd|d d S )Nr   ztest*.pyT)rY   rZ   )rV   r   rW   r?   r@   rN   rS   )r:   r+   rZ   r   r   r   rM      s    
zTestProgram._do_discoveryc              	   C   s   | j rt  | jd krtj| _t| jtrzVz"| j| j| j| j	| j
| jd}W n. tk
r|   | j| j| j| j	| j
d}Y nX W q tk
r   |  }Y qX n| j}|| j| _| jrt| j   d S )N)r/   r-   r0   r2   r"   )r/   r-   r0   r2   )r.   r   r4   r   ZTextTestRunnerr$   rc   r/   r-   r0   r2   r"   	TypeErrorrunrX   resultr,   r*   ZwasSuccessful)r:   r4   r   r   r   r9      s2    

zTestProgram.runTests)N)FN)N)rQ   
__module____qualname____doc__r'   r/   r-   r.   r0   r7   r2   rU   r?   r   ZdefaultTestLoaderr<   rC   rA   r8   rS   r@   r[   r\   r]   rM   r9   r   r   r   r   r    7   s6        &
	
#
r    )rs   r*   rd   r
    r   r   Zsignalsr   Z
__unittestrF   rH   r   r   r   objectr    mainr   r   r   r   <module>   s   	 ]                                                                                                                                                mock.cpython-38.opt-2.pyc                                                                           0000644                 00000161575 15175327600 0011112 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                    @   s  d Z d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
mZmZ ddlmZ ddlmZmZ dd eeD Zd	ZeZd
d Zdd Zdd Zdd Zdd Zdd ZdddZdd Zdd Zdd Z dd  Z!dd!d"Z"d#d$ Z#d%d& Z$d'd( Z%G d)d* d*e&Z'G d+d, d,e&Z(e( Z)e)j*Z*e)j+Z,e)j-Z.d-d.d/d0d1d2d3d4hZ/d5d6 Z0G d7d8 d8e1Z2d9d: Z3G d;d< d<e&Z4G d=d> d>e&Z5G d?d@ d@e5Z6dAdB Z7G dCdD dDe5Z8G dEdF dFe8e6Z9dGdH Z:dIdJ Z;G dKdL dLe&Z<dMdN Z=e*dddddfdOdPZ>ddQdRZ?e*dddddfdSdTZ@G dUdV dVe&ZAdWdX ZBdYdZ ZCe>e@_&eAe@_De?e@_EeCe@_Fd[e@_Gd\ZHd]ZId^Jd_d` eIK D ZLd^Jdad` eIK D ZMdbdcdddedfdgdhdidjdkdldmdndodpdqdrdshZNdtdu ZOdvd d^JeHeIeLeMgK D ZPdwdxdyhZQdzhZReQeRB ZSePeNB ZTeTeSB ZUd{d|d}d~ddddhZVdd dd dd dd dZWeXeXeXeXddddddd	dddZYdd ZZdd Z[dd Z\dd Z]eZe[e\e]dZ^dd Z_G dd de5Z`G dd de`e6ZaG dd de`ZbG dd de`e9ZcG dd de5ZdG dd de5ZeG dd deeebe9ZfG dd de&Zgeg Zhdd ZiG dd dejZkekddZldddZmdd ZnG dd de&ZoepemepehjqfZrdasdd ZtdddZuG dd de9Zvdd ZwG dd dZxdS ))Mock	MagicMockpatchsentinelDEFAULTANYcallcreate_autospec	AsyncMock
FILTER_DIRNonCallableMockNonCallableMagicMock	mock_openPropertyMocksealz1.0    N)CodeType
ModuleType
MethodType)	safe_repr)wrapspartialc                 C   s   h | ]}| d s|qS _
startswith).0name r   %/usr/lib64/python3.8/unittest/mock.py	<setcomp>(   s     
 r   Tc                 C   s>   t | rt| tsdS t| dr*t| d} t| p<t| S )NF__func__)	_is_instance_mock
isinstancer	   hasattrgetattrasyncioiscoroutinefunctioninspectZisawaitableobjr   r   r   _is_async_obj0   s
    

r*   c                 C   s   t | dd rt| S dS d S )N__code__F)r$   r%   r&   funcr   r   r   _is_async_func8   s    
r.   c                 C   s   t t| tS N)
issubclasstyper   r(   r   r   r   r!   ?   s    r!   c                 C   s   t | tpt | tot| tS r/   )r"   BaseExceptionr1   r0   r(   r   r   r   _is_exceptionE   s    
r3   c                 C   s"   t | trt| dr| jS | S d S Nmock)r"   FunctionTypesr#   r5   r(   r   r   r   _extract_mockL   s    r7   c                 C   s   t | tr|s| j} d}n,t | tsFz
| j} W n tk
rD   Y d S X |rVt| d }n| }z| t|fW S  t	k
r   Y d S X d S NT)
r"   r1   __init__r6   __call__AttributeErrorr   r'   	signature
ValueError)r-   Zas_instanceZeat_selfZsig_funcr   r   r   _get_signature_objectU   s    

r>   Fc                    sN   t | ||  d krd S  \}   fdd}t| | |t|_ t|_d S )Nc                   s    j || d S r/   bindselfargskwargssigr   r   checksigw   s    z"_check_signature.<locals>.checksig)r>   _copy_func_detailsr1   _mock_check_sig__signature__)r-   r5   	skipfirstinstancerG   r   rE   r   _check_signaturer   s    

rM   c              	   C   s:   dD ]0}zt ||t| | W q tk
r2   Y qX qd S )N)__name____doc____text_signature__
__module____defaults____kwdefaults__)setattrr$   r;   )r-   funcopy	attributer   r   r   rH   ~   s
    rH   c                 C   s@   t | trdS t | tttfr(t| jS t| dd d k	r<dS dS )NTr:   F)r"   r1   staticmethodclassmethodr   	_callabler    r$   r(   r   r   r   rY      s    

rY   c                 C   s   t | ttfkS r/   )r1   listtupler(   r   r   r   _is_list   s    r\   c                 C   sF   t | tst| dd d k	S | f| j D ]}|jdd k	r& dS q&dS )Nr:   TF)r"   r1   r$   __mro____dict__get)r)   baser   r   r   _instance_callable   s    
ra   c                    s   t |t}t|||}|d kr"| S |\}  fdd}t|| |j}| sRd}|| d}d| }	t|	| || }
t|
|   |
S )Nc                     s    j | | d S r/   r?   rC   rD   rE   r   r   rG      s    z _set_signature.<locals>.checksigrU   )Z
_checksig_r5   zYdef %s(*args, **kwargs):
    _checksig_(*args, **kwargs)
    return mock(*args, **kwargs))r"   r1   r>   rH   rN   isidentifierexec_setup_func)r5   originalrL   rK   resultr-   rG   r   contextsrcrU   r   rE   r   _set_signature   s$    



rj   c                    s    _ fdd}fdd}fdd}fdd}fd	d
}fdd}fdd}	 fdd}
d _d _d  _t  _t  _t  _j _j	 _	j
 _
| _| _| _|	 _|
 _| _| _| _| _ _d S )Nc                     s    j | |S r/   )assert_called_withrb   r5   r   r   rk      s    z'_setup_func.<locals>.assert_called_withc                     s    j | |S r/   )assert_calledrb   rl   r   r   rm      s    z"_setup_func.<locals>.assert_calledc                     s    j | |S r/   )assert_not_calledrb   rl   r   r   rn      s    z&_setup_func.<locals>.assert_not_calledc                     s    j | |S r/   )assert_called_oncerb   rl   r   r   ro      s    z'_setup_func.<locals>.assert_called_oncec                     s    j | |S r/   )assert_called_once_withrb   rl   r   r   rp      s    z,_setup_func.<locals>.assert_called_once_withc                     s    j | |S r/   )assert_has_callsrb   rl   r   r   rq      s    z%_setup_func.<locals>.assert_has_callsc                     s    j | |S r/   )assert_any_callrb   rl   r   r   rr      s    z$_setup_func.<locals>.assert_any_callc                     s:   t   _t   _   j} t| r6| k	r6|   d S r/   )	_CallListmethod_calls
mock_calls
reset_mockreturn_valuer!   )retrU   r5   r   r   rv      s    z_setup_func.<locals>.reset_mockFr   )r5   called
call_count	call_argsrs   call_args_listrt   ru   rw   side_effect_mock_childrenrk   rp   rq   rr   rv   rm   rn   ro   rJ   _mock_delegate)rU   r5   rF   rk   rm   rn   ro   rp   rq   rr   rv   r   ry   r   re      s8    re   c                    sJ   t jj _d _d  _t  _ fdd}dD ]}t |t|| q.d S )Nr   c                   s   t  j| ||S r/   )r$   r5   )attrrC   rD   rl   r   r   wrapper   s    z"_setup_async_mock.<locals>.wrapper)assert_awaitedassert_awaited_onceassert_awaited_withassert_awaited_once_withassert_any_awaitassert_has_awaitsassert_not_awaited)	r%   
coroutines_is_coroutineawait_count
await_argsrs   await_args_listrT   r   )r5   r   rV   r   rl   r   _setup_async_mock   s    
r   c                 C   s   d| dd  | kS )N__%s__   r   r   r   r   r   	_is_magic  s    r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )_SentinelObjectc                 C   s
   || _ d S r/   r   rB   r   r   r   r   r9     s    z_SentinelObject.__init__c                 C   s
   d| j  S Nzsentinel.%sr   rB   r   r   r   __repr__  s    z_SentinelObject.__repr__c                 C   s
   d| j  S r   r   r   r   r   r   
__reduce__  s    z_SentinelObject.__reduce__N)rN   rQ   __qualname__r9   r   r   r   r   r   r   r     s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )	_Sentinelc                 C   s
   i | _ d S r/   )
_sentinelsr   r   r   r   r9   #  s    z_Sentinel.__init__c                 C   s   |dkrt | j|t|S )N	__bases__)r;   r   
setdefaultr   r   r   r   r   __getattr__&  s    z_Sentinel.__getattr__c                 C   s   dS )Nr   r   r   r   r   r   r   ,  s    z_Sentinel.__reduce__N)rN   rQ   r   r9   r   r   r   r   r   r   r   !  s   r   rw   _mock_return_valuer~   _mock_side_effect_mock_parent_mock_new_parent
_mock_name_mock_new_namec                 C   s8   t |  d|  }| |fdd}| |fdd}t||S )NZ_mock_c                 S   s"   | j }|d krt| |S t||S r/   )r   r$   )rB   r   	_the_namerF   r   r   r   _getA  s    
z"_delegating_property.<locals>._getc                 S   s*   | j }|d kr|| j|< nt||| d S r/   )r   r^   rT   )rB   valuer   r   rF   r   r   r   _setF  s    z"_delegating_property.<locals>._set)_allowed_namesaddproperty)r   r   r   r   r   r   r   _delegating_property>  s
    
r   c                   @   s   e Zd Zdd Zdd ZdS )rs   c                 C   sl   t |tst| |S t|}t| }||kr2dS td|| d D ]"}| |||  }||krD dS qDdS )NFr      T)r"   rZ   __contains__lenrange)rB   r   Z	len_valueZlen_selfiZsub_listr   r   r   r   S  s    
z_CallList.__contains__c                 C   s   t t| S r/   )pprintZpformatrZ   r   r   r   r   r   a  s    z_CallList.__repr__N)rN   rQ   r   r   r   r   r   r   r   rs   Q  s   rs   c                 C   s|   t |}t|sdS |js4|js4|jd k	s4|jd k	r8dS | }|d k	rX||krPdS |j}q<|rh| |_||_|rx| |_||_dS )NFT)r7   r!   r   r   r   r   )parentr   r   new_name_parentr   r   r   _check_and_set_parente  s*    r   c                   @   s   e Zd Zdd Zdd ZdS )	_MockIterc                 C   s   t || _d S r/   )iterr)   )rB   r)   r   r   r   r9     s    z_MockIter.__init__c                 C   s
   t | jS r/   )nextr)   r   r   r   r   __next__  s    z_MockIter.__next__N)rN   rQ   r   r9   r   r   r   r   r   r     s   r   c                   @   s   e Zd ZeZdZdd ZdS )BaseNc                O   s   d S r/   r   rA   r   r   r   r9     s    zBase.__init__)rN   rQ   r   r   r   r   r9   r   r   r   r   r     s   r   c                   @   s`  e Zd Zdd ZdKddZdd	 ZdLd
dZdMddZdd Zdd Z	dZ
eee	e
Zedd ZedZedZedZedZedZdd Zdd ZeeeZdNddd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/d0 ZdOd2d3Z d4d5 Z!d6d7 Z"d8d9 Z#d:d; Z$d<d= Z%d>d? Z&d@dA Z'dPdBdCZ(dDdE Z)dFdG Z*dQdIdJZ+dS )Rr   c          	      O   s   | f}t | ts^ttj}|j| f||j}dd | D }|r^t	||d  r^t
| f}t| j|d| ji}tt| |}|S )Nc                 S   s   g | ]}| d r|qS specr   r   argr   r   r   
<listcomp>  s   
z+NonCallableMock.__new__.<locals>.<listcomp>r   rO   )r0   r	   r'   r<   r   r9   Zbind_partialZ	argumentskeysr*   AsyncMockMixinr1   rN   rO   _safe_super__new__)	clsrC   kwbasesrF   Z
bound_argsZspec_argnewrL   r   r   r   r     s    
zNonCallableMock.__new__N Fc                 K   s   |d kr|}| j }||d< ||d< ||d< ||d< d|d< |d k	rJ|}d}|
d krZ|d k	}
| |||	|
 i |d< ||d	< d |d
< d|d< d |d< d|d< t |d< t |d< t |d< ||d< |r| jf | tt| |||||| d S )Nr   r   r   r   F_mock_sealedTr   _mock_wrapsr   Z_mock_calledZ_mock_call_argsr   Z_mock_call_countZ_mock_call_args_listZ_mock_mock_callsrt   _mock_unsafe)r^   _mock_add_specrs   configure_mockr   r   r9   )rB   r   r   r   spec_setr   _spec_state	_new_name_new_parent_spec_as_instance	_eat_selfZunsaferD   r^   r   r   r   r9     sD    



    zNonCallableMock.__init__c                 C   s0   t |}d |_d |_d|_d |_t| || d S )Nr   )r7   r   r   r   r   rT   )rB   r5   rV   Z
inner_mockr   r   r   attach_mock  s    zNonCallableMock.attach_mockc                 C   s   |  || d S r/   )r   rB   r   r   r   r   r   mock_add_spec  s    zNonCallableMock.mock_add_specc                 C   s   d }d }g }t |D ] }tt||d r|| q|d k	r~t|s~t|trV|}nt|}t|||}	|	ot|	d }t |}| j	}
||
d< ||
d< ||
d< ||
d< ||
d< d S )Nr   _spec_class	_spec_set_spec_signature_mock_methods_spec_asyncs)
dirr%   r&   r$   appendr\   r"   r1   r>   r^   )rB   r   r   r   r   r   r   r   r   resr^   r   r   r   r     s,    
 zNonCallableMock._mock_add_specc                 C   s8   | j }| jd k	r| jj}|tkr4| j| dd}|| _|S )N()r   r   )r   r   rw   r   _get_child_mock)rB   rx   r   r   r   Z__get_return_value  s    
 z"NonCallableMock.__get_return_valuec                 C   s,   | j d k	r|| j _n|| _t| |d d d S )Nr   )r   rw   r   r   )rB   r   r   r   r   Z__set_return_value  s    

z"NonCallableMock.__set_return_valuez1The value to be returned when the mock is called.c                 C   s   | j d krt| S | j S r/   )r   r1   r   r   r   r   	__class__!  s    
zNonCallableMock.__class__rz   r{   r|   r}   ru   c                 C   sN   | j }|d kr| jS |j}|d k	rJt|sJt|tsJt|sJt|}||_|S r/   )r   r   r~   callabler"   r   r3   )rB   	delegatedZsfr   r   r   Z__get_side_effect.  s    z!NonCallableMock.__get_side_effectc                 C   s(   t |}| j}|d kr|| _n||_d S r/   )	_try_iterr   r   r~   )rB   r   r   r   r   r   Z__set_side_effect9  s
    z!NonCallableMock.__set_side_effect)rw   r~   c                C   s   |d krg }t | |krd S |t |  d| _d | _d| _t | _t | _t | _|r^t	| _
|rhd | _| j D ]"}t|tsr|tkrqr|| qr| j
}t|r|| k	r|| d S )NFr   )idr   rz   r|   r{   rs   ru   r}   rt   r   r   r   r   valuesr"   
_SpecState_deletedrv   r!   )rB   Zvisitedrw   r~   childrx   r   r   r   rv   D  s,    zNonCallableMock.reset_mockc                K   sX   t | dd dD ]>\}}|d}| }| }|D ]}t||}q6t||| qd S )Nc                 S   s   | d  dS )Nr   .)count)entryr   r   r   <lambda>o      z0NonCallableMock.configure_mock.<locals>.<lambda>)keyr   )sorteditemssplitpopr$   rT   )rB   rD   r   valrC   finalr)   r   r   r   r   r   b  s    	
zNonCallableMock.configure_mockc                 C   s   |dkrt |n:| jd k	r<|| jks.|tkrLt d| nt|rLt || jsd|drdt d| j|}|tkrt |np|d krd }| j	d k	rt
| j	|}| j| |||| d}|| j|< n.t|trt|j|j|j|j|j}|| j|< |S )N>   r   r   zMock object has no attribute %r)assertZassretz1Attributes cannot start with 'assert' or 'assret')r   r   r   r   r   )r;   r   _all_magicsr   r   r   r   r_   r   r   r$   r   r"   r   r   r   r   rL   r   r   )rB   r   rg   r   r   r   r   r   x  sF    




   
   
zNonCallableMock.__getattr__c                 C   s   | j g}| j}| }d}|dgkr$d}|d k	rZ|}||j |  d}|j dkrRd}|j}q$tt|}|jpnd}t|dkr|d dkr|d7 }||d< d|S )Nr   r   r   r5   r   )r   z().r   )r   r   r   rZ   reversedr   r   join)rB   Z
_name_listr   ZlastdotZ_firstr   r   r   _extract_mock_name  s(    


z"NonCallableMock._extract_mock_namec                 C   s^   |   }d}|dkrd| }d}| jd k	rDd}| jr8d}|| jj }dt| j||t| f S )Nr   )r5   zmock.z name=%rz spec=%rz spec_set=%rz<%s%s%s id='%s'>)r   r   r   rN   r1   r   )rB   r   Zname_stringZspec_stringr   r   r   r     s     
zNonCallableMock.__repr__c                 C   sv   t st| S | jpg }tt| }t| j}dd | j	 D }dd |D }dd |D }t
t|| | | S )Nc                 S   s   g | ]\}}|t k	r|qS r   )r   )r   Zm_nameZm_valuer   r   r   r     s   z+NonCallableMock.__dir__.<locals>.<listcomp>c                 S   s   g | ]}| d s|qS r   r   r   er   r   r   r     s     
 c                 S   s"   g | ]}| d rt|r|qS r   )r   r   r   r   r   r   r     s     
)r
   object__dir__r   r   r1   rZ   r^   r   r   r   set)rB   ZextrasZ	from_typeZ	from_dictZfrom_child_mocksr   r   r   r    s    


zNonCallableMock.__dir__c                    sT  |t krt||S jrHjd k	rH|jkrH|jkrHtd| n|tkrbd| }t|n|tkrjd k	r|jkrtd| t	|st
t|t|| |  fdd}n(t|d | t
t|| |j|< n,|dkr|_d S t|||r|j|< jrFt|sF  d| }td| t||S )Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.c                     s    f| |S r/   r   rC   r   rf   rB   r   r   r     r   z-NonCallableMock.__setattr__.<locals>.<lambda>r   r   zCannot set )r   r  __setattr__r   r   r^   r;   _unsupported_magicsr   r!   rT   r1   _get_methodr   r   r   r   r#   r   )rB   r   r   msg	mock_namer   r  r   r    s<    

zNonCallableMock.__setattr__c                 C   s   |t kr2|t| jkr2tt| | || jkr2d S | j|t}|| jkr\tt| 	| n|t
krlt||tk	r|| j|= t
| j|< d S r/   )r   r1   r^   delattrr   r_   _missingr   r   __delattr__r   r;   )rB   r   r)   r   r   r   r    s    

zNonCallableMock.__delattr__c                 C   s   | j pd}t|||S r4   )r   _format_call_signaturerB   rC   rD   r   r   r   r   _format_mock_call_signature  s    
z+NonCallableMock._format_mock_call_signaturer   c                 C   s.   d}|  ||}| j}| j | }||||f S )Nz.expected %s not found.
Expected: %s
Actual: %s)r  r|   )rB   rC   rD   actionmessageexpected_stringr|   Zactual_stringr   r   r   _format_mock_failure_message  s
    
z,NonCallableMock._format_mock_failure_messagec                 C   sj   |s
| j S d }|ddd}| j}|D ]:}||}|d ksJt|trP qfq*t|}|j}|j }q*|S )Nr   r   r   )r   replacer   r   r_   r"   r   r7   )rB   r   rF   namesZchildrenr   r   r   r   _get_call_signature_from_name'  s    
z-NonCallableMock._get_call_signature_from_namec              
   C   s   t |tr&t|dkr&| |d }n| j}|d k	rt|dkrNd}|\}}n
|\}}}z||j||fW S  tk
r } z|d  W Y S d }~X Y qX n|S d S )Nr   r   r   )r"   r[   r   r  r   r@   	TypeErrorwith_traceback)rB   _callrF   r   rC   rD   r  r   r   r   _call_matcherH  s    

"zNonCallableMock._call_matcherc                 C   s0   | j dkr,d| jpd| j |  f }t|d S )Nr   z9Expected '%s' to not have been called. Called %s times.%sr5   r{   r   _calls_reprAssertionErrorrB   r
  r   r   r   rn   b  s    
z!NonCallableMock.assert_not_calledc                 C   s$   | j dkr d| jpd }t|d S )Nr   z"Expected '%s' to have been called.r5   )r{   r   r  r   r   r   r   rm   l  s
    
zNonCallableMock.assert_calledc                 C   s0   | j dks,d| jpd| j |  f }t|d S )Nr   z:Expected '%s' to have been called once. Called %s times.%sr5   r  r   r   r   r   ro   t  s    
z"NonCallableMock.assert_called_oncec                   s   j d kr. }d}d||f }t| fdd} f}j }||kr~t|trn|nd }t| |d S )Nznot called.z0expected call not found.
Expected: %s
Actual: %sc                     s     } | S r/   r  r
  rC   rD   rB   r   r   _error_message  s    z:NonCallableMock.assert_called_with.<locals>._error_message)r|   r  r  r  r"   	Exception)rB   rC   rD   expectedactualZerror_messager$  causer   r#  r   rk   ~  s    
z"NonCallableMock.assert_called_withc                O   s8   | j dks,d| jpd| j |  f }t|| j||S )Nr   z3Expected '%s' to be called once. Called %s times.%sr5   )r{   r   r  r  rk   rB   rC   rD   r
  r   r   r   rp     s    
z'NonCallableMock.assert_called_once_withc           	   	      s   fdd|D }t dd |D d }t fdd jD }|s||kr|d krXd}nddd |D }t| d	t|  jd
dd |d S t|}g }|D ]2}z|| W q t	k
r   |
| Y qX q|rtd jpdt||f |d S )Nc                    s   g | ]}  |qS r   r  r   cr   r   r   r     s     z4NonCallableMock.assert_has_calls.<locals>.<listcomp>c                 s   s   | ]}t |tr|V  qd S r/   r"   r%  r   r   r   r   	<genexpr>  s     
 z3NonCallableMock.assert_has_calls.<locals>.<genexpr>c                 3   s   | ]}  |V  qd S r/   r*  r+  r   r   r   r.    s     zCalls not found.z+Error processing expected calls.
Errors: {}c                 S   s   g | ]}t |tr|nd qS r/   r-  r   r   r   r   r     s   
Expected: ZActual)prefixr   z@%r does not contain all of %r in its call list, found %r insteadr5   )r   rs   ru   formatr  r  rstriprZ   remover=   r   r   r[   )	rB   calls	any_orderr&  r(  Z	all_callsproblem	not_foundkallr   r   r   rq     sH    
" z NonCallableMock.assert_has_callsc                   sZ     ||f} fdd jD }||krVt|tr8|nd } ||}td| |d S )Nc                    s   g | ]}  |qS r   r*  r+  r   r   r   r     s     z3NonCallableMock.assert_any_call.<locals>.<listcomp>z%s call not found)r  r}   r"   r%  r  r  rB   rC   rD   r&  r'  r(  r  r   r   r   rr     s    zNonCallableMock.assert_any_callc                K   s   | d}|| jd kr"tf |S t| }t|trB|tkrBt}nbt|trp|tksd| j	rj|| j	krjt}qt}n4t|t
st|trt}qt|trt}n
|jd }| jrd|krd|d  nd}|  | }t||f |S )Nr   r   r   r   r   r   )r_   r^   r	   r1   r0   r   _async_method_magicsr   _all_sync_magicsr   CallableMixinr   r   r   r]   r   r   r;   )rB   r   r   _typeklassrV   r  r   r   r   r     s2    






zNonCallableMock._get_child_mockCallsc                 C   s"   | j s
dS d| dt| j  dS )Nr   
z: r   )ru   r   )rB   r0  r   r   r   r    s    zNonCallableMock._calls_repr)NNNNNNr   NFNF)F)FF)N)r   )F)r?  ),rN   rQ   r   r   r9   r   r   r   Z"_NonCallableMock__get_return_valueZ"_NonCallableMock__set_return_valueZ"_NonCallableMock__return_value_docr   rw   r   r   rz   r{   r|   r}   ru   Z!_NonCallableMock__get_side_effectZ!_NonCallableMock__set_side_effectr~   rv   r   r   r   r   r  r  r  r  r  r  r  rn   rm   ro   rk   rp   rq   rr   r   r  r   r   r   r   r     sn                      
-
	  


''
!


-'r   c                 C   sL   | d kr| S t | r| S t| r$| S z
t| W S  tk
rF   |  Y S X d S r/   )r3   rY   r   r  r(   r   r   r   r     s    
r   c                
   @   sR   e Zd Zddedddddddf
ddZdd Zdd Zd	d
 Zdd Zdd Z	dS )r<  Nr   c              	   K   s6   || j d< tt| j|||||||	|
f| || _d S )Nr   )r^   r   r<  r9   r~   )rB   r   r~   rw   r   r   r   r   r   r   r   rD   r   r   r   r9   #  s    

      zCallableMixin.__init__c                O   s   d S r/   r   rA   r   r   r   rI   /  s    zCallableMixin._mock_check_sigc                O   s$   | j || | j|| | j||S r/   )rI   _increment_mock_call
_mock_callrA   r   r   r   r:   4  s    zCallableMixin.__call__c                O   s   | j ||S r/   )_execute_mock_callrA   r   r   r   rB  <  s    zCallableMixin._mock_callc                O   s   d| _ |  jd7  _t||fdd}|| _| j| | jd k	}| j}| j}|dk}| j	td||f | j
}|d k	r|r|jt|||f |jd k	}|r|jd | }t|||f}	|j	|	 |jr|rd}
nd}
|jdk}|j|
 | }|j
}qpd S )NTr   twor   r   r   )rz   r{   _Callr|   r}   r   r   r   r   ru   r   rt   )rB   rC   rD   r  Zdo_method_callsZmethod_call_nameZmock_call_nameZ	is_a_callr   Zthis_mock_callr   r   r   r   rA  ?  s4    


z"CallableMixin._increment_mock_callc                O   s|   | j }|d k	rPt|r|n(t|s:t|}t|rD|n
|||}|tk	rP|S | jtk	r`| jS | jd k	rv| j||S | jS r/   )r~   r3   rY   r   r   r   rw   r   )rB   rC   rD   effectrg   r   r   r   rC  m  s     


z CallableMixin._execute_mock_call)
rN   rQ   r   r   r9   rI   r:   rB  rA  rC  r   r   r   r   r<  !  s        
.r<  c                   @   s   e Zd ZdS )r   NrN   rQ   r   r   r   r   r   r     s   r   c                 C   s8   zt | |W S  tk
r2   t| t | | Y S X d S r/   )r$   r;   
__import__)thingcompimport_pathr   r   r   _dot_lookup  s
    rM  c                 C   sB   |  d}|d}t|}|D ]}|d| 7 }t|||}q |S )Nr   r   z.%s)r   r   rI  rM  )targetZ
componentsrL  rJ  rK  r   r   r   	_importer  s    

rO  c                   @   sz   e Zd ZdZg Zdd Zdd Zdd Zdd	 Ze	j
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S )_patchNc
           
      C   sn   |d k	r(|t k	rtd|d k	r(td|| _|| _|| _|| _|| _|| _d| _|| _	|| _
|	| _g | _d S )Nz,Cannot use 'new' and 'new_callable' togetherz1Cannot use 'autospec' and 'new_callable' togetherF)r   r=   getterrV   r   new_callabler   createZ	has_localr   autospecrD   additional_patchers)
rB   rQ  rV   r   r   rS  r   rT  rR  rD   r   r   r   r9     s(    z_patch.__init__c              
   C   sH   t | j| j| j| j| j| j| j| j| j		}| j
|_
dd | jD |_|S )Nc                 S   s   g | ]}|  qS r   )copy)r   pr   r   r   r     s    z_patch.copy.<locals>.<listcomp>)rP  rQ  rV   r   r   rS  r   rT  rR  rD   attribute_namerU  )rB   patcherr   r   r   rV    s           z_patch.copyc                 C   s2   t |tr| |S t|r(| |S | |S r/   )r"   r1   decorate_classr'   r&   decorate_async_callabledecorate_callablerB   r-   r   r   r   r:     s
    



z_patch.__call__c                 C   sN   t |D ]@}|tjsqt||}t|ds0q|  }t|||| q|S Nr:   )r   r   r   TEST_PREFIXr$   r#   rV  rT   )rB   r>  r   
attr_valuerY  r   r   r   rZ    s    

z_patch.decorate_classc              	   c   sr   g }t  \}|jD ]8}||}|jd k	r8|| q|jtkr|| q|t	|7 }||fV  W 5 Q R X d S r/   )

contextlib	ExitStack	patchingsenter_contextrX  updater   r   r   r[   )rB   patchedrC   keywargs
extra_args
exit_stackpatchingr   r   r   r   decoration_helper  s    




z_patch.decoration_helperc                    s>   t  dr j  S t  fddg_S )Nrc  c               
      s4    | |\}} ||W  5 Q R  S Q R X d S r/   rk  rC   rg  ZnewargsZnewkeywargsr-   rf  rB   r   r   rf  (  s    z)_patch.decorate_callable.<locals>.patchedr#   rc  r   r   r]  r   rn  r   r\  "  s    
z_patch.decorate_callablec                    s>   t  dr j  S t  fddg_S )Nrc  c               
      s:    | |"\}} ||I d H W  5 Q R  S Q R X d S r/   rl  rm  rn  r   r   rf  9  s    z/_patch.decorate_async_callable.<locals>.patchedro  r]  r   rn  r   r[  3  s    
z_patch.decorate_async_callablec              	   C   s   |   }| j}t}d}z|j| }W n$ ttfk
rH   t||t}Y nX d}|tkrft|t	rfd| _
| j
s|tkrtd||f ||fS )NFTz!%s does not have the attribute %r)rQ  rV   r   r^   r;   KeyErrorr$   	_builtinsr"   r   rS  )rB   rN  r   rf   localr   r   r   get_originalD  s     
z_patch.get_originalc                 C   s  | j | j| j  }}}| j| j }}| j}|  | _|dkr@d }|dkrLd }|dkrXd }|d k	rp|d k	rptd|d k	s|d k	r|dkrtd| 	 \}}|t
kr||d kr|d}	|dkr|}|dkr|}d }n&|d k	r|dkr|}d }n|dkr|}|d k	s|d k	r.|t
krtdt|tr.d}	|d krHt|rHt}
nt}
i }|d k	r`|}
n^|d k	st|d k	r|}|d k	r|}t|rd|k}n
t| }t|rt}
n
|rt}
|d k	r||d< |d k	r||d	< t|
trt|
tr| jr| j|d
< || |
f |}|	rt|r|}|d k	rB|}t|sZt|sZt}
|d
 |
f |dd||_nl|d k	r|t
k	rtd|t
krtdt|}|dkr|}t|f|| jd|}n|rtd|}|| _|| _t  | _!zrt"| j| j| | j#d k	rpi }| j t
kr:||| j#< | j$D ](}| j!%|}|j t
kr@|| q@|W S |W S    | j&t'(  s Y nX d S )NFzCan't specify spec and autospec)TNz6Can't provide explicit spec_set *and* spec or autospecTz!Can't use 'spec' with create=Truer:   r   r   r   r   r   zBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=True)r   _namez.Can't pass kwargs to a mock we aren't creating))r   r   r   rT  rD   rR  rQ  rN  r  rs  r   r"   r1   r*   r	   r   r\   r   r   r0   r   rV   re  r!   ra   r   rw   boolr   temp_originalis_localra  rb  _exit_stackrT   rX  rU  rd  __exit__sysexc_info)rB   r   r   r   rT  rD   rR  rf   rr  ZinheritKlass_kwargsZ	this_specZnot_callableZnew_attrrh  rj  r   r   r   r   	__enter__\  s    























z_patch.__enter__c                 G   s   | j r$| jtk	r$t| j| j| j n>t| j| j | jsbt| j| jrP| jdkrbt| j| j| j | `| ` | `| j	}| `	|j
| S )N)rO   rQ   rR   __annotations__rS   )rw  rv  r   rT   rN  rV   r  rS  r#   rx  ry  )rB   r{  ri  r   r   r   ry    s    z_patch.__exit__c                 C   s   |   }| j|  |S r/   )r~  _active_patchesr   )rB   rg   r   r   r   start  s    z_patch.startc                 C   s6   z| j |  W n tk
r&   Y d S X | d d d S r/   )r  r3  r=   ry  r   r   r   r   stop  s
    z_patch.stop)rN   rQ   r   rX  r  r9   rV  r:   rZ  ra  contextmanagerrk  r\  r[  rs  r~  ry  r  r  r   r   r   r   rP    s    
 rP  c              	      sP   z  dd\ }W n& ttfk
r:   td f Y nX  fdd}||fS )Nr   r   z.Need a valid target to patch. You supplied: %rc                      s   t  S r/   rO  r   rN  r   r   r     r   z_get_target.<locals>.<lambda>)rsplitr  r=   )rN  rV   rQ  r   r  r   _get_target
  s    r  c           
   
      s>   t  tkrt d fdd}	t|	||||||||	S )Nz3 must be the actual object to be patched, not a strc                      s    S r/   r   r   r  r   r   r   *  r   z_patch_object.<locals>.<lambda>)r1   strr  rP  )
rN  rV   r   r   rS  r   rT  rR  rD   rQ  r   r  r   _patch_object  s            r  c                    s   t  tkr fdd}n fdd}|s2tdt| }|d \}	}
t||	|
|||||i 	}|	|_|dd  D ]2\}	}
t||	|
|||||i 	}|	|_|j| qt|S )Nc                      s   t  S r/   r  r   r  r   r   r   H  r   z!_patch_multiple.<locals>.<lambda>c                      s    S r/   r   r   r  r   r   r   J  r   z=Must supply at least one keyword argument with patch.multipler   r   )	r1   r  r=   rZ   r   rP  rX  rU  r   )rN  r   rS  r   rT  rR  rD   rQ  r   rV   r   rY  Zthis_patcherr   r  r   _patch_multiple1  sH                  r  c           
   
   K   s$   t | \}}	t||	|||||||	S r/   )r  rP  )
rN  r   r   rS  r   rT  rR  rD   rQ  rV   r   r   r   r   b  s    F       r   c                   @   sN   e Zd ZdddZdd Zdd Zd	d
 Zdd Zdd Zdd Z	eZ
e	ZdS )_patch_dictr   Fc                 K   s,   || _ t|| _| j| || _d | _d S r/   )in_dictdictr   re  clear	_original)rB   r  r   r  rD   r   r   r   r9     s
    
z_patch_dict.__init__c                    s.   t  tr S t  fdd}|S )Nc                     s&      z | |W S   X d S r/   )r  _unpatch_dictr  frB   r   r   _inner  s    z$_patch_dict.__call__.<locals>._inner)r"   r1   rZ  r   )rB   r  r  r   r  r   r:     s
    

z_patch_dict.__call__c                 C   sX   t |D ]J}t||}|tjrt|drt| j| j| j	}||}t
||| q|S r^  )r   r$   r   r   r_  r#   r  r  r   r  rT   )rB   r>  r   r`  Z	decoratorZ	decoratedr   r   r   rZ    s    
z_patch_dict.decorate_classc                 C   s   |    | jS r/   )r  r  r   r   r   r   r~    s    z_patch_dict.__enter__c                 C   s   | j }t| jtrt| j| _| j}| j}z| }W n. tk
rd   i }|D ]}|| ||< qNY nX || _|rxt	| z|
| W n* tk
r   |D ]}|| ||< qY nX d S r/   )r   r"   r  r  rO  r  rV  r;   r  _clear_dictre  )rB   r   r  r  rf   r   r   r   r   r    s&    z_patch_dict._patch_dictc                 C   sR   | j }| j}t| z|| W n* tk
rL   |D ]}|| ||< q6Y nX d S r/   )r  r  r  re  r;   )rB   r  rf   r   r   r   r   r    s    z_patch_dict._unpatch_dictc                 G   s   |    dS NF)r  )rB   rC   r   r   r   ry    s    z_patch_dict.__exit__N)r   F)rN   rQ   r   r9   r:   rZ  r~  r  r  ry  r  r  r   r   r   r   r    s   
	r  c                 C   s>   z|    W n, tk
r8   t| }|D ]
}| |= q(Y nX d S r/   )r  r;   rZ   )r  r   r   r   r   r   r  &  s    r  c                  C   s   t tjD ]} |   q
d S r/   )r   rP  r  r  )r   r   r   r   _patch_stopall/  s    r  Ztestzlt le gt ge eq ne getitem setitem delitem len contains iter hash str sizeof enter exit divmod rdivmod neg pos abs invert complex int float index round trunc floor ceil bool next fspath aiter zHadd sub mul matmul div floordiv mod lshift rshift and xor or pow truediv c                 c   s   | ]}d | V  qdS )zi%sNr   r   nr   r   r   r.  N  s     r.  c                 c   s   | ]}d | V  qdS )zr%sNr   r  r   r   r   r.  O  s     __get____set__
__delete____reversed____missing__r   __reduce_ex__Z__getinitargs____getnewargs____getstate____setstate____getformat__Z__setformat__r   r  __subclasses__
__format____getnewargs_ex__c                    s    fdd}| |_ |S )Nc                   s    | f||S r/   r   rB   rC   r   r,   r   r   method`  s    z_get_method.<locals>.method)rN   )r   r-   r  r   r,   r   r	  ^  s    r	  c                 C   s   h | ]}d | qS )r   r   )r   r  r   r   r   r   f  s    
__aenter__	__aexit__	__anext__	__aiter__r   r  r9   r   __prepare____instancecheck____subclasscheck____del__c                 C   s
   t | S r/   )r  __hash__r   r   r   r   r   |  r   r   c                 C   s
   t | S r/   )r  __str__r   r   r   r   r   }  r   c                 C   s
   t | S r/   )r  
__sizeof__r   r   r   r   r   ~  r   c                 C   s"   t | j d|   dt|  S )N/)r1   rN   r   r   r   r   r   r   r     r   )r  r  r  
__fspath__r   y              ?g      ?)__lt____gt____le____ge____int__r   __len__ry  __complex__	__float____bool__	__index__r  c                    s    fdd}|S )Nc                    s$    j j}|tk	r|S  | kr dS tS r8   )__eq__r   r   NotImplemented)otherret_valr   r   r   r    s    z_get_eq.<locals>.__eq__r   )rB   r  r   r   r   _get_eq  s    r  c                    s    fdd}|S )Nc                    s     j jtk	rtS  | krdS tS r  )__ne__r   r   r  )r  r   r   r   r    s
    z_get_ne.<locals>.__ne__r   )rB   r  r   r   r   _get_ne  s    r  c                    s    fdd}|S )Nc                     s     j j} | tkrtg S t| S r/   )__iter__r   r   r   r  r   r   r   r    s    z_get_iter.<locals>.__iter__r   )rB   r  r   r   r   	_get_iter  s    r  c                    s    fdd}|S )Nc                     s(    j j} | tkrttg S tt| S r/   )r  r   r   _AsyncIteratorr   r  r   r   r   r    s    z"_get_async_iter.<locals>.__aiter__r   )rB   r  r   r   r   _get_async_iter  s    r  )r  r  r  r  c                 C   sb   t |t}|tk	r||_d S t|}|d k	rB|| }||_d S t|}|d k	r^|| |_d S r/   )_return_valuesr_   r   rw   _calculate_return_value_side_effect_methodsr~   )r5   r  r   ZfixedZreturn_calculatorrw   Zside_effectorr   r   r   _set_return_value  s    

r  c                   @   s   e Zd Zdd Zdd ZdS )
MagicMixinc                O   s&   |    tt| j|| |    d S r/   )_mock_set_magicsr   r  r9   r  r   r   r   r9     s    zMagicMixin.__init__c                 C   s   t tB }|}t| dd d k	rX|| j}t }|| }|D ]}|t| jkr:t| | q:|tt| j }t| }|D ]}t	||t
||  qvd S )Nr   )_magicsr:  r$   intersectionr   r  r1   r^   r  rT   
MagicProxy)rB   Zorig_magicsZthese_magicsZremove_magicsr   r=  r   r   r   r    s    zMagicMixin._mock_set_magicsN)rN   rQ   r   r9   r  r   r   r   r   r    s   r  c                   @   s   e Zd ZdddZdS )r   Fc                 C   s   |  || |   d S r/   r   r  r   r   r   r   r     s    z"NonCallableMagicMock.mock_add_specN)FrN   rQ   r   r   r   r   r   r   r     s   r   c                   @   s   e Zd Zdd ZdS )AsyncMagicMixinc                O   s&   |    tt| j|| |    d S r/   )r  r   r  r9   r  r   r   r   r9     s    zAsyncMagicMixin.__init__NrN   rQ   r   r9   r   r   r   r   r    s   r  c                   @   s   e Zd ZdddZdS )r   Fc                 C   s   |  || |   d S r/   r  r   r   r   r   r     s    zMagicMock.mock_add_specN)Fr  r   r   r   r   r     s   r   c                   @   s&   e Zd Zdd Zdd ZdddZdS )	r  c                 C   s   || _ || _d S r/   r   r   )rB   r   r   r   r   r   r9     s    zMagicProxy.__init__c                 C   s8   | j }| j}|j|||d}t||| t||| |S )N)r   r   r   )r   r   r   rT   r  )rB   r   r   mr   r   r   create_mock  s    zMagicProxy.create_mockNc                 C   s   |   S r/   )r  )rB   r)   r=  r   r   r   r  (  s    zMagicProxy.__get__)N)rN   rQ   r   r9   r  r  r   r   r   r   r    s   	r  c                       s   e Zd ZedZedZedZ fddZdd Zdd	 Z	d
d Z
dd Zdd Zdd ZdddZdd Z fddZ  ZS )r   r   r   r   c                   s\   t  j|| tjj| jd< d| jd< d | jd< t | jd< ttd}t	j
|_|| jd< d S )Nr   r   Z_mock_await_countZ_mock_await_argsZ_mock_await_args_listr   r+   )superr9   r%   r   r   r^   rs   r   r   r'   ZCO_COROUTINEco_flags)rB   rC   rD   	code_mockr   r   r   r9   1  s    


zAsyncMockMixin.__init__c                   s  t ||fdd}|  jd7  _|| _| j| | j}|d k	rt|rL|nbt|szt|}W n t	k
rx   t
Y nX t|r|n&t|r|||I d H }n
|||}|tk	r|S | jtk	r| jS | jd k	rt| jr| j||I d H S | j||S | jS )NTrD  r   )rF  r   r   r   r   r~   r3   rY   r   StopIterationStopAsyncIterationr%   r&   r   r   rw   r   )rB   rC   rD   r  rG  rg   r   r   r   rC  A  s6    




z!AsyncMockMixin._execute_mock_callc                 C   s(   | j dkr$d| jpd d}t|d S )Nr   	Expected r5   z to have been awaited.r   r   r  r   r   r   r   r   i  s    
zAsyncMockMixin.assert_awaitedc                 C   s0   | j dks,d| jpd d| j  d}t|d S Nr   r  r5   z$ to have been awaited once. Awaited  times.r  r   r   r   r   r   q  s    
z"AsyncMockMixin.assert_awaited_oncec                   sz   j d kr& }td| d fdd} f}j }||krvt|trf|nd }t| |d S )NzExpected await: z
Not awaitedc                     s   j  dd} | S )Nawait)r  r!  r"  r#  r   r   r$    s    z:AsyncMockMixin.assert_awaited_with.<locals>._error_message)r   r  r  r  r"   r%  )rB   rC   rD   r&  r$  r'  r(  r   r#  r   r   z  s    
z"AsyncMockMixin.assert_awaited_withc                O   s8   | j dks,d| jpd d| j  d}t|| j||S r  )r   r   r  r   r)  r   r   r   r     s    
z'AsyncMockMixin.assert_awaited_once_withc                   sZ     ||f} fdd jD }||krVt|tr8|nd } ||}td| |d S )Nc                    s   g | ]}  |qS r   r*  r+  r   r   r   r     s     z3AsyncMockMixin.assert_any_await.<locals>.<listcomp>z%s await not found)r  r   r"   r%  r  r  r9  r   r   r   r     s    zAsyncMockMixin.assert_any_awaitFc           	   	      s    fdd|D }t dd |D d }t fdd jD }|s||kr|d krXd}nddd |D }t| d	t| d
 j |d S t|}g }|D ]2}z|| W q tk
r   || Y qX q|rtdt	|f |d S )Nc                    s   g | ]}  |qS r   r*  r+  r   r   r   r     s     z4AsyncMockMixin.assert_has_awaits.<locals>.<listcomp>c                 s   s   | ]}t |tr|V  qd S r/   r-  r   r   r   r   r.    s     
 z3AsyncMockMixin.assert_has_awaits.<locals>.<genexpr>c                 3   s   | ]}  |V  qd S r/   r*  r+  r   r   r   r.    s     zAwaits not found.z,Error processing expected awaits.
Errors: {}c                 S   s   g | ]}t |tr|nd qS r/   r-  r   r   r   r   r     s   r/  z	
Actual: z%r not all found in await list)
r   rs   r   r1  r  rZ   r3  r=   r   r[   )	rB   r4  r5  r&  r(  Z
all_awaitsr6  r7  r8  r   r   r   r     s>    z AsyncMockMixin.assert_has_awaitsc                 C   s0   | j dkr,d| jpd d| j  d}t|d S )Nr   r  r5   z# to not have been awaited. Awaited r  r  r   r   r   r   r     s    
z!AsyncMockMixin.assert_not_awaitedc                   s&   t  j|| d| _d | _t | _d S Nr   )r  rv   r   r   rs   r   rA   r  r   r   rv     s    zAsyncMockMixin.reset_mock)F)rN   rQ   r   r   r   r   r   r9   rC  r   r   r   r   r   r   r   rv   __classcell__r   r   r  r   r   ,  s   (	
,	r   c                   @   s   e Zd ZdS )r	   NrH  r   r   r   r   r	     s   r	   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )_ANYc                 C   s   dS r8   r   rB   r  r   r   r   r  	  s    z_ANY.__eq__c                 C   s   dS r  r   r  r   r   r   r  	  s    z_ANY.__ne__c                 C   s   dS )Nz<ANY>r   r   r   r   r   r   	  s    z_ANY.__repr__N)rN   rQ   r   r  r  r   r   r   r   r   r  	  s   r  c                 C   s`   d|  }d}d dd |D }d dd | D }|r@|}|rX|rP|d7 }||7 }|| S )Nz%s(%%s)r   z, c                 S   s   g | ]}t |qS r   )reprr   r   r   r   r   !	  s     z*_format_call_signature.<locals>.<listcomp>c                 S   s   g | ]\}}d ||f qS )z%s=%rr   )r   r   r   r   r   r   r   "	  s    )r   r   )r   rC   rD   r  Zformatted_argsZargs_stringZkwargs_stringr   r   r   r  	  s    
r  c                   @   s   e Zd Zd ddZd!dd	Zd
d ZejZdd Zdd Z	dd Z
dd Zdd Zdd Zedd Zedd Zdd Zdd ZdS )"rF  r   r   NFTc                 C   s   d}i }t |}|dkr$|\}}}nr|dkrd|\}	}
t|	trX|	}t|
trR|
}qb|
}q|	|
 }}n2|dkr|\}t|tr|}nt|tr|}n|}|rt| ||fS t| |||fS )Nr      r   r   )r   r"   r  r[   r   )r   r   r   r   rE  	from_kallrC   rD   _lenfirstsecondr   r   r   r   C	  s.    



z_Call.__new__c                 C   s   || _ || _|| _d S r/   )r   r   _mock_from_kall)rB   r   r   r   rE  r  r   r   r   r9   c	  s    z_Call.__init__c                 C   sh  |t krdS zt|}W n tk
r.   Y dS X d}t| dkrJ| \}}n
| \}}}t| dd r|t|dd r|| j|jkr|dS d}|dkrdi  }}n|dkr|\}}}n|d	kr|\}	t|	tr|	}i }n"t|	tr|	}di  }}nd}|	}nV|dkr@|\}
}t|
tr4|
}t|tr(|i  }}n
d| }}n
|
| }}ndS |rX||krXdS ||f||fkS )
NTFr   r   r   r   r   r  r   )r   r   r  r$   r   r"   r[   r  )rB   r  Z	len_otherZ	self_nameZ	self_argsZself_kwargsZ
other_nameZ
other_argsZother_kwargsr   r  r  r   r   r   r  j	  sR    





z_Call.__eq__c                O   s<   | j d krtd||fddS | j d }t| j ||f|| dS )Nr   r   r   r  r   rF  r  r   r   r   r:   	  s    

z_Call.__call__c                 C   s2   | j d krt|ddS d| j |f }t|| ddS )NF)r   r  z%s.%s)r   r   r  r  )rB   r   r   r   r   r   r   	  s    
z_Call.__getattr__c                 C   s   |t jkrtt | |S r/   )r[   r^   r;   __getattribute__)rB   r   r   r   r   r  	  s    
z_Call.__getattribute__c                O   s   |  d||S )Nr   r   rA   r   r   r   r   	  s    z_Call.countc                O   s   |  d||S )Nindexr  rA   r   r   r   r  	  s    z_Call.indexc                 C   s(   t | dkr| \}}n
| \}}}||fS )Nr   )r   r  r   r   r   _get_call_arguments	  s    

z_Call._get_call_argumentsc                 C   s   |   d S r  r  r   r   r   r   rC   	  s    z
_Call.argsc                 C   s   |   d S )Nr   r  r   r   r   r   rD   	  s    z_Call.kwargsc                 C   s|   | j s&| jpd}|dr"d| }|S t| dkr@d}| \}}n0| \}}}|sTd}n|dshd| }nd| }t|||S )Nr   r   zcall%sr   zcall.%s)r  r   r   r   r  )rB   r   rC   rD   r   r   r   r   	  s    





z_Call.__repr__c                 C   s4   g }| }|d k	r(|j r || |j}qtt|S r/   )r  r   r   rs   r   )rB   ZvalsrJ  r   r   r   	call_list	  s    
z_Call.call_list)r   r   NFT)r   NNFT)rN   rQ   r   r   r9   r  r  r  r:   r   r  r   r  r  r   rC   rD   r   r  r   r   r   r   rF  0	  s(     
   
7

rF  )r  c              	   K   sl  t | rt| } t| t}t| }d| i}|r8d| i}n| d krDi }|rT|rTd|d< || t}	t| rri }n8|r|rtdt	}	n"t
| st}	n|r|rt| st}	|d|}|}
|d krd}
|	f |||
|d|}t| trt|| }|rt| nt| ||| |d k	r,|s,||j|< |rV|sVd	|krVt| |dd
|d|_t| D ]}t|rrq^zt| |}W n tk
r   Y q^Y nX d|i}|rd|i}t|tst|||||}||j|< np|}t| tr|j}t| ||}||d< t|rt	}nt}|f ||||d|}||j|< t|||d t|tr^t||| q^|S )Nr   r   Tr   zJInstance can not be True when create_autospec is mocking an async functionr   r   )r   r   r   r   rw   r   )rL   rt  r   r   )r   r   r   r   )rK   )r\   r1   r"   r.   re  r   r'   ZisdatadescriptorRuntimeErrorr	   rY   r   ra   r   r6   rj   r   rM   r   r   rw   r   r   r$   r;   r   r5   
_must_skipr%   r&   rT   )r   r   rL   r   rt  rD   is_typeZis_async_funcr}  r|  r   r5   r   rf   r   r   rK   Zchild_klassr   r   r   r   	  s    







 


r   c                 C   sx   t | ts$|t| di krdS | j} | jD ]H}|j|t}|tkrFq*t |tt	frZ dS t |t
rl|  S  dS q*|S )Nr^   F)r"   r1   r$   r   r]   r^   r_   r   rW   rX   r6   )r   r   r  r>  rg   r   r   r   r  w
  s    


r  c                   @   s   e Zd ZdddZdS )r   FNc                 C   s(   || _ || _|| _|| _|| _|| _d S r/   )r   idsr   r   rL   r   )rB   r   r   r   r   r  rL   r   r   r   r9   
  s    z_SpecState.__init__)FNNNFr  r   r   r   r   r   
  s
         r   c                 C   s"   t | trt| S t| S d S r/   )r"   bytesioBytesIOStringIO)	read_datar   r   r   
_to_stream
  s    

r  r   c                    s&  t }|d gfdd}fdd} fddfdd fd	d
}td krdd l}ttt|jtt|ja| d krt	dt
d} t	tdj_d j_d j_d j_d j_|j_ d< d j_|j_ j_|j_fdd}|| _| _| S )Nc                     s$   j jd k	rj jS  d j | |S r  )	readlinesrw   rb   _statehandler   r   _readlines_side_effect
  s    z)mock_open.<locals>._readlines_side_effectc                     s$   j jd k	rj jS  d j | |S r  )readrw   rb   r  r   r   _read_side_effect
  s    z$mock_open.<locals>._read_side_effectc                  ?   s$     E d H  d j | |V  qd S r  )readlinerb   )_iter_side_effectr  r   r   _readline_side_effect
  s    z(mock_open.<locals>._readline_side_effectc                  3   s0   j jd k	rj jV  q d D ]
} | V  q d S r  )r  rw   )liner  r   r   r  
  s    z$mock_open.<locals>._iter_side_effectc                      s    j jd k	rj jS t d S r  )r  rw   r   r   r  r   r   _next_side_effect
  s    z$mock_open.<locals>._next_side_effectr   open)r   r   r   r   c                     s6   t d< jjd kr2  d< d j_tS )Nr   r   )r  r  r~   r   rb   )r  r  r  r  r   r   
reset_data
  s
    
zmock_open.<locals>.reset_data)r  	file_spec_iorZ   r  r   TextIOWrapperunionr   r   r  r~  rw   writer	  r  r  r~   r  r   )r5   r  Z
_read_datar  r
  r  r  r  r   )r  r  r  r  r  r   r   
  s8    "

r   c                   @   s&   e Zd Zdd ZdddZdd ZdS )	r   c                K   s
   t f |S r/   )r   )rB   rD   r   r   r   r     s    zPropertyMock._get_child_mockNc                 C   s   |  S r/   r   )rB   r)   Zobj_typer   r   r   r    s    zPropertyMock.__get__c                 C   s   | | d S r/   r   )rB   r)   r   r   r   r   r    s    zPropertyMock.__set__)N)rN   rQ   r   r   r  r  r   r   r   r   r   
  s   	
r   c              	   C   s^   d| _ t| D ]J}zt| |}W n tk
r8   Y qY nX t|tsFq|j| krt| qd S r8   )r   r   r$   r;   r"   r   r   r   )r5   r   r  r   r   r   r     s    



r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )r  c                 C   s&   || _ ttd}tj|_|| jd< d S )Nr  r+   )iteratorr   r   r'   ZCO_ITERABLE_COROUTINEr  r^   )rB   r  r  r   r   r   r9   +  s    
z_AsyncIterator.__init__c                 C   s   | S r/   r   r   r   r   r   r  1  s    z_AsyncIterator.__aiter__c                    s*   zt | jW S  tk
r    Y nX td S r/   )r   r  r  r  r   r   r   r   r  4  s
    z_AsyncIterator.__anext__N)rN   rQ   r   r9   r  r  r   r   r   r   r  '  s   r  )F)F)NFNNN)FFNN)Nr   )y__all____version__r%   ra  r  r'   r   rz  builtinstypesr   r   r   Zunittest.utilr   	functoolsr   r   r   rq  r
   r  r   r*   r.   r!   r3   r7   r>   rM   rH   rY   r\   ra   rj   re   r   r   r  r   r   r   r   MISSINGr  ZDELETEDr   r   r   rZ   rs   r   r   r   r   r   r<  r   rM  rO  rP  r  r  r  r   r  r  r  r  ZmultipleZstopallr_  Zmagic_methodsZnumericsr   r   ZinplacerightZ_non_defaultsr	  r  r:  Z_sync_async_magicsZ_async_magicsr;  r   r  r  r  r  r  r  r  r  r  r  r  r   r  r   r  r   r	   r  r   r  r[   rF  r   r   r  r   r1   r  r6   r  r  r   r   r   r  r   r   r   r   <module>   s~  	


1          	h4  <   
    
2    
Mw	             	
    
	
		 8+ B
  
 
N                                                                                                                                   mock.cpython-38.opt-1.pyc                                                                           0000644                 00000227070 15175327600 0011102 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       U
    e5d                    @   s  d Z d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
mZmZ ddlmZ ddlmZmZ dd eeD Zd	ZeZd
d Zdd Zdd Zdd Zdd Zdd ZdddZdd Zdd Zdd Z dd  Z!dd!d"Z"d#d$ Z#d%d& Z$d'd( Z%G d)d* d*e&Z'G d+d, d,e&Z(e( Z)e)j*Z*e)j+Z,e)j-Z.d-d.d/d0d1d2d3d4hZ/d5d6 Z0G d7d8 d8e1Z2d9d: Z3G d;d< d<e&Z4G d=d> d>e&Z5G d?d@ d@e5Z6dAdB Z7G dCdD dDe5Z8G dEdF dFe8e6Z9dGdH Z:dIdJ Z;G dKdL dLe&Z<dMdN Z=e*dddddfdOdPZ>ddQdRZ?e*dddddfdSdTZ@G dUdV dVe&ZAdWdX ZBdYdZ ZCe>e@_&eAe@_De?e@_EeCe@_Fd[e@_Gd\ZHd]ZId^Jd_d` eIK D ZLd^Jdad` eIK D ZMdbdcdddedfdgdhdidjdkdldmdndodpdqdrdshZNdtdu ZOdvd d^JeHeIeLeMgK D ZPdwdxdyhZQdzhZReQeRB ZSePeNB ZTeTeSB ZUd{d|d}d~ddddhZVdd dd dd dd dZWeXeXeXeXddddddd	dddZYdd ZZdd Z[dd Z\dd Z]eZe[e\e]dZ^dd Z_G dd de5Z`G dd de`e6ZaG dd de`ZbG dd de`e9ZcG dd de5ZdG dd de5ZeG dd deeebe9ZfG dd de&Zgeg Zhdd ZiG dd dejZkekddZldddZmdd ZnG dd de&ZoepemepehjqfZrdasdd ZtdddZuG dd de9Zvdd ZwG dd dZxdS ))Mock	MagicMockpatchsentinelDEFAULTANYcallcreate_autospec	AsyncMock
FILTER_DIRNonCallableMockNonCallableMagicMock	mock_openPropertyMocksealz1.0    N)CodeType
ModuleType
MethodType)	safe_repr)wrapspartialc                 C   s   h | ]}| d s|qS _
startswith).0name r   %/usr/lib64/python3.8/unittest/mock.py	<setcomp>(   s     
 r   Tc                 C   s>   t | rt| tsdS t| dr*t| d} t| p<t| S )NF__func__)	_is_instance_mock
isinstancer	   hasattrgetattrasyncioiscoroutinefunctioninspectZisawaitableobjr   r   r   _is_async_obj0   s
    

r*   c                 C   s   t | dd rt| S dS d S )N__code__F)r$   r%   r&   funcr   r   r   _is_async_func8   s    
r.   c                 C   s   t t| tS N)
issubclasstyper   r(   r   r   r   r!   ?   s    r!   c                 C   s   t | tpt | tot| tS r/   )r"   BaseExceptionr1   r0   r(   r   r   r   _is_exceptionE   s    
r3   c                 C   s"   t | trt| dr| jS | S d S Nmock)r"   FunctionTypesr#   r5   r(   r   r   r   _extract_mockL   s    r7   c                 C   s   t | tr|s| j} d}n,t | tsFz
| j} W n tk
rD   Y dS X |rVt| d}n| }z| t|fW S  t	k
r   Y dS X dS )z
    Given an arbitrary, possibly callable object, try to create a suitable
    signature object.
    Return a (reduced func, signature) tuple, or None.
    TN)
r"   r1   __init__r6   __call__AttributeErrorr   r'   	signature
ValueError)r-   Zas_instanceZeat_selfZsig_funcr   r   r   _get_signature_objectU   s    

r=   Fc                    sN   t | ||  d krd S  \}   fdd}t| | |t|_ t|_d S )Nc                   s    j || d S r/   bindselfargskwargssigr   r   checksigw   s    z"_check_signature.<locals>.checksig)r=   _copy_func_detailsr1   _mock_check_sig__signature__)r-   r5   	skipfirstinstancerF   r   rD   r   _check_signaturer   s    

rL   c              	   C   s:   dD ]0}zt ||t| | W q tk
r2   Y qX qd S )N)__name____doc____text_signature__
__module____defaults____kwdefaults__)setattrr$   r:   )r-   funcopy	attributer   r   r   rG   ~   s
    rG   c                 C   s@   t | trdS t | tttfr(t| jS t| dd d k	r<dS dS )NTr9   F)r"   r1   staticmethodclassmethodr   	_callabler    r$   r(   r   r   r   rX      s    

rX   c                 C   s   t | ttfkS r/   )r1   listtupler(   r   r   r   _is_list   s    r[   c                 C   sF   t | tst| dddk	S | f| j D ]}|jddk	r& dS q&dS )ztGiven an object, return True if the object is callable.
    For classes, return True if instances would be callable.r9   NTF)r"   r1   r$   __mro____dict__get)r)   baser   r   r   _instance_callable   s    
r`   c                    s   t |t}t|||}|d kr"| S |\}  fdd}t|| |j}| sRd}|| d}d| }	t|	| || }
t|
|   |
S )Nc                     s    j | | d S r/   r>   rB   rC   rD   r   r   rF      s    z _set_signature.<locals>.checksigrT   )Z
_checksig_r5   zYdef %s(*args, **kwargs):
    _checksig_(*args, **kwargs)
    return mock(*args, **kwargs))r"   r1   r=   rG   rM   isidentifierexec_setup_func)r5   originalrK   rJ   resultr-   rF   r   contextsrcrT   r   rD   r   _set_signature   s$    



ri   c                    s    _ fdd}fdd}fdd}fdd}fd	d
}fdd}fdd}	 fdd}
d _d _d  _t  _t  _t  _j _j	 _	j
 _
| _| _| _|	 _|
 _| _| _| _| _ _d S )Nc                     s    j | |S r/   )assert_called_withra   r5   r   r   rj      s    z'_setup_func.<locals>.assert_called_withc                     s    j | |S r/   )assert_calledra   rk   r   r   rl      s    z"_setup_func.<locals>.assert_calledc                     s    j | |S r/   )assert_not_calledra   rk   r   r   rm      s    z&_setup_func.<locals>.assert_not_calledc                     s    j | |S r/   )assert_called_oncera   rk   r   r   rn      s    z'_setup_func.<locals>.assert_called_oncec                     s    j | |S r/   )assert_called_once_withra   rk   r   r   ro      s    z,_setup_func.<locals>.assert_called_once_withc                     s    j | |S r/   )assert_has_callsra   rk   r   r   rp      s    z%_setup_func.<locals>.assert_has_callsc                     s    j | |S r/   )assert_any_callra   rk   r   r   rq      s    z$_setup_func.<locals>.assert_any_callc                     s:   t   _t   _   j} t| r6| k	r6|   d S r/   )	_CallListmethod_calls
mock_calls
reset_mockreturn_valuer!   )retrT   r5   r   r   ru      s    z_setup_func.<locals>.reset_mockFr   )r5   called
call_count	call_argsrr   call_args_listrs   rt   rv   side_effect_mock_childrenrj   ro   rp   rq   ru   rl   rm   rn   rI   _mock_delegate)rT   r5   rE   rj   rl   rm   rn   ro   rp   rq   ru   r   rx   r   rd      s8    rd   c                    sJ   t jj _d _d  _t  _ fdd}dD ]}t |t|| q.d S )Nr   c                   s   t  j| ||S r/   )r$   r5   )attrrB   rC   rk   r   r   wrapper   s    z"_setup_async_mock.<locals>.wrapper)assert_awaitedassert_awaited_onceassert_awaited_withassert_awaited_once_withassert_any_awaitassert_has_awaitsassert_not_awaited)	r%   
coroutines_is_coroutineawait_count
await_argsrr   await_args_listrS   r   )r5   r   rU   r   rk   r   _setup_async_mock   s    
r   c                 C   s   d| dd  | kS )N__%s__   r   r   r   r   r   	_is_magic  s    r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_SentinelObjectz!A unique, named, sentinel object.c                 C   s
   || _ d S r/   r   rA   r   r   r   r   r8     s    z_SentinelObject.__init__c                 C   s
   d| j  S Nzsentinel.%sr   rA   r   r   r   __repr__  s    z_SentinelObject.__repr__c                 C   s
   d| j  S r   r   r   r   r   r   
__reduce__  s    z_SentinelObject.__reduce__N)rM   rP   __qualname__rN   r8   r   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S )		_SentinelzAAccess attributes to return a named object, usable as a sentinel.c                 C   s
   i | _ d S r/   )
_sentinelsr   r   r   r   r8   #  s    z_Sentinel.__init__c                 C   s   |dkrt | j|t|S )N	__bases__)r:   r   
setdefaultr   r   r   r   r   __getattr__&  s    z_Sentinel.__getattr__c                 C   s   dS )Nr   r   r   r   r   r   r   ,  s    z_Sentinel.__reduce__N)rM   rP   r   rN   r8   r   r   r   r   r   r   r   !  s   r   rv   _mock_return_valuer}   _mock_side_effect_mock_parent_mock_new_parent
_mock_name_mock_new_namec                 C   s8   t |  d|  }| |fdd}| |fdd}t||S )NZ_mock_c                 S   s"   | j }|d krt| |S t||S r/   )r   r$   )rA   r   	_the_namerE   r   r   r   _getA  s    
z"_delegating_property.<locals>._getc                 S   s*   | j }|d kr|| j|< nt||| d S r/   )r   r]   rS   )rA   valuer   r   rE   r   r   r   _setF  s    z"_delegating_property.<locals>._set)_allowed_namesaddproperty)r   r   r   r   r   r   r   _delegating_property>  s
    
r   c                   @   s   e Zd Zdd Zdd ZdS )rr   c                 C   sl   t |tst| |S t|}t| }||kr2dS td|| d D ]"}| |||  }||krD dS qDdS )NFr      T)r"   rY   __contains__lenrange)rA   r   Z	len_valueZlen_selfiZsub_listr   r   r   r   S  s    
z_CallList.__contains__c                 C   s   t t| S r/   )pprintZpformatrY   r   r   r   r   r   a  s    z_CallList.__repr__N)rM   rP   r   r   r   r   r   r   r   rr   Q  s   rr   c                 C   s|   t |}t|sdS |js4|js4|jd k	s4|jd k	r8dS | }|d k	rX||krPdS |j}q<|rh| |_||_|rx| |_||_dS )NFT)r7   r!   r   r   r   r   )parentr   r   new_name_parentr   r   r   _check_and_set_parente  s*    r   c                   @   s   e Zd Zdd Zdd ZdS )	_MockIterc                 C   s   t || _d S r/   )iterr)   )rA   r)   r   r   r   r8     s    z_MockIter.__init__c                 C   s
   t | jS r/   )nextr)   r   r   r   r   __next__  s    z_MockIter.__next__N)rM   rP   r   r8   r   r   r   r   r   r     s   r   c                   @   s   e Zd ZeZdZdd ZdS )BaseNc                O   s   d S r/   r   r@   r   r   r   r8     s    zBase.__init__)rM   rP   r   r   r   r   r8   r   r   r   r   r     s   r   c                   @   sd  e Zd ZdZdd ZdLddZd	d
 ZdMddZdNddZdd Z	dd Z
dZee	e
eZedd ZedZedZedZedZedZdd Zdd ZeeeZdOdddd d!Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Z dPd3d4Z!d5d6 Z"d7d8 Z#d9d: Z$d;d< Z%d=d> Z&d?d@ Z'dAdB Z(dQdCdDZ)dEdF Z*dGdH Z+dRdJdKZ,dS )Sr   z A non-callable version of `Mock`c          	      O   s   | f}t | ts^ttj}|j| f||j}dd | D }|r^t	||d  r^t
| f}t| j|d| ji}tt| |}|S )Nc                 S   s   g | ]}| d r|qS specr   r   argr   r   r   
<listcomp>  s   
z+NonCallableMock.__new__.<locals>.<listcomp>r   rN   )r0   r	   r'   r;   r   r8   Zbind_partialZ	argumentskeysr*   AsyncMockMixinr1   rM   rN   _safe_super__new__)	clsrB   kwbasesrE   Z
bound_argsZspec_argnewrK   r   r   r   r     s    
zNonCallableMock.__new__N Fc                 K   s   |d kr|}| j }||d< ||d< ||d< ||d< d|d< |d k	rJ|}d}|
d krZ|d k	}
| |||	|
 i |d< ||d	< d |d
< d|d< d |d< d|d< t |d< t |d< t |d< ||d< |r| jf | tt| |||||| d S )Nr   r   r   r   F_mock_sealedTr~   _mock_wrapsr   Z_mock_calledZ_mock_call_argsr   Z_mock_call_countZ_mock_call_args_listZ_mock_mock_callsrs   _mock_unsafe)r]   _mock_add_specrr   configure_mockr   r   r8   )rA   r   r   r   spec_setr   _spec_state	_new_name_new_parent_spec_as_instance	_eat_selfZunsaferC   r]   r   r   r   r8     sD    



    zNonCallableMock.__init__c                 C   s0   t |}d|_d|_d|_d|_t| || dS )z
        Attach a mock as an attribute of this one, replacing its name and
        parent. Calls to the attached mock will be recorded in the
        `method_calls` and `mock_calls` attributes of this one.Nr   )r7   r   r   r   r   rS   )rA   r5   rU   Z
inner_mockr   r   r   attach_mock  s    zNonCallableMock.attach_mockc                 C   s   |  || dS zAdd a spec to a mock. `spec` can either be an object or a
        list of strings. Only attributes on the `spec` can be fetched as
        attributes from the mock.

        If `spec_set` is True then only attributes on the spec can be set.N)r   rA   r   r   r   r   r   mock_add_spec  s    zNonCallableMock.mock_add_specc                 C   s   d }d }g }t |D ] }tt||d r|| q|d k	r~t|s~t|trV|}nt|}t|||}	|	ot|	d }t |}| j	}
||
d< ||
d< ||
d< ||
d< ||
d< d S )Nr   _spec_class	_spec_set_spec_signature_mock_methods_spec_asyncs)
dirr%   r&   r$   appendr[   r"   r1   r=   r]   )rA   r   r   r   r   r   r   r   r   resr]   r   r   r   r     s,    
 zNonCallableMock._mock_add_specc                 C   s8   | j }| jd k	r| jj}|tkr4| j| dd}|| _|S )N()r   r   )r   r   rv   r   _get_child_mock)rA   rw   r   r   r   Z__get_return_value  s    
 z"NonCallableMock.__get_return_valuec                 C   s,   | j d k	r|| j _n|| _t| |d d d S )Nr   )r   rv   r   r   )rA   r   r   r   r   Z__set_return_value  s    

z"NonCallableMock.__set_return_valuez1The value to be returned when the mock is called.c                 C   s   | j d krt| S | j S r/   )r   r1   r   r   r   r   	__class__!  s    
zNonCallableMock.__class__ry   rz   r{   r|   rt   c                 C   sN   | j }|d kr| jS |j}|d k	rJt|sJt|tsJt|sJt|}||_|S r/   )r   r   r}   callabler"   r   r3   )rA   	delegatedZsfr   r   r   Z__get_side_effect.  s    z!NonCallableMock.__get_side_effectc                 C   s(   t |}| j}|d kr|| _n||_d S r/   )	_try_iterr   r   r}   )rA   r   r   r   r   r   Z__set_side_effect9  s
    z!NonCallableMock.__set_side_effect)rv   r}   c                C   s   |dkrg }t | |krdS |t |  d| _d| _d| _t | _t | _t | _|r^t	| _
|rhd| _| j D ]"}t|tsr|tkrqr|| qr| j
}t|r|| k	r|| dS )z-Restore the mock object to its initial state.NFr   )idr   ry   r{   rz   rr   rt   r|   rs   r   r   r   r~   valuesr"   
_SpecState_deletedru   r!   )rA   Zvisitedrv   r}   childrw   r   r   r   ru   D  s,    zNonCallableMock.reset_mockc                K   sX   t | dd dD ]>\}}|d}| }| }|D ]}t||}q6t||| qdS )aZ  Set attributes on the mock through keyword arguments.

        Attributes plus return values and side effects can be set on child
        mocks using standard dot notation and unpacking a dictionary in the
        method call:

        >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
        >>> mock.configure_mock(**attrs)c                 S   s   | d  dS )Nr   .)count)entryr   r   r   <lambda>o      z0NonCallableMock.configure_mock.<locals>.<lambda>)keyr   N)sorteditemssplitpopr$   rS   )rA   rC   r   valrB   finalr)   r   r   r   r   r   b  s    	
zNonCallableMock.configure_mockc                 C   s   |dkrt |n:| jd k	r<|| jks.|tkrLt d| nt|rLt || jsd|drdt d| j|}|tkrt |np|d krd }| j	d k	rt
| j	|}| j| |||| d}|| j|< n.t|trt|j|j|j|j|j}|| j|< |S )N>   r   r   zMock object has no attribute %r)assertZassretz1Attributes cannot start with 'assert' or 'assret')r   r   r   r   r   )r:   r   _all_magicsr   r   r   r~   r^   r   r   r$   r   r"   r   r   r   r   rK   r   r   )rA   r   rf   r   r   r   r   r   x  sF    




   
   
zNonCallableMock.__getattr__c                 C   s   | j g}| j}| }d}|dgkr$d}|d k	rZ|}||j |  d}|j dkrRd}|j}q$tt|}|jpnd}t|dkr|d dkr|d7 }||d< d|S )Nr   r   r   r5   r   )r   z().r   )r   r   r   rY   reversedr   r   join)rA   Z
_name_listr   ZlastdotZ_firstr   r   r   _extract_mock_name  s(    


z"NonCallableMock._extract_mock_namec                 C   s^   |   }d}|dkrd| }d}| jd k	rDd}| jr8d}|| jj }dt| j||t| f S )Nr   )r5   zmock.z name=%rz spec=%rz spec_set=%rz<%s%s%s id='%s'>)r   r   r   rM   r1   r   )rA   r   Zname_stringZspec_stringr   r   r   r     s     
zNonCallableMock.__repr__c                 C   sv   t st| S | jpg }tt| }t| j}dd | j	 D }dd |D }dd |D }t
t|| | | S )z8Filter the output of `dir(mock)` to only useful members.c                 S   s   g | ]\}}|t k	r|qS r   )r   )r   Zm_nameZm_valuer   r   r   r     s   z+NonCallableMock.__dir__.<locals>.<listcomp>c                 S   s   g | ]}| d s|qS r   r   r   er   r   r   r     s     
 c                 S   s"   g | ]}| d rt|r|qS r   )r   r   r   r   r   r   r     s     
)r
   object__dir__r   r   r1   rY   r]   r~   r   r   set)rA   ZextrasZ	from_typeZ	from_dictZfrom_child_mocksr   r   r   r    s    


zNonCallableMock.__dir__c                    sT  |t krt||S jrHjd k	rH|jkrH|jkrHtd| n|tkrbd| }t|n|tkrjd k	r|jkrtd| t	|st
t|t|| |  fdd}n(t|d | t
t|| |j|< n,|dkr|_d S t|||r|j|< jrFt|sF  d| }td| t||S )Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.c                     s    f| |S r/   r   rB   r   re   rA   r   r   r     r   z-NonCallableMock.__setattr__.<locals>.<lambda>r   r   zCannot set )r   r  __setattr__r   r   r]   r:   _unsupported_magicsr   r!   rS   r1   _get_methodr   r~   r   r   r#   r   )rA   r   r   msg	mock_namer   r  r   r    s<    

zNonCallableMock.__setattr__c                 C   s   |t kr2|t| jkr2tt| | || jkr2d S | j|t}|| jkr\tt| 	| n|t
krlt||tk	r|| j|= t
| j|< d S r/   )r   r1   r]   delattrr~   r^   _missingr   r   __delattr__r   r:   )rA   r   r)   r   r   r   r    s    

zNonCallableMock.__delattr__c                 C   s   | j pd}t|||S r4   )r   _format_call_signaturerA   rB   rC   r   r   r   r   _format_mock_call_signature  s    
z+NonCallableMock._format_mock_call_signaturer   c                 C   s.   d}|  ||}| j}| j | }||||f S )Nz.expected %s not found.
Expected: %s
Actual: %s)r  r{   )rA   rB   rC   actionmessageexpected_stringr{   Zactual_stringr   r   r   _format_mock_failure_message  s
    
z,NonCallableMock._format_mock_failure_messagec                 C   sj   |s
| j S d}|ddd}| j}|D ]:}||}|dksJt|trP qfq*t|}|j}|j }q*|S )aH  
        * If call objects are asserted against a method/function like obj.meth1
        then there could be no name for the call object to lookup. Hence just
        return the spec_signature of the method/function being asserted against.
        * If the name is not empty then remove () and split by '.' to get
        list of names to iterate through the children until a potential
        match is found. A child mock is created only during attribute access
        so if we get a _SpecState then no attributes of the spec were accessed
        and can be safely exited.
        Nr   r   r   )r   replacer   r~   r^   r"   r   r7   )rA   r   rE   namesZchildrenr   r   r   r   _get_call_signature_from_name'  s    
z-NonCallableMock._get_call_signature_from_namec              
   C   s   t |tr&t|dkr&| |d }n| j}|dk	rt|dkrNd}|\}}n
|\}}}z||j||fW S  tk
r } z|d W Y S d}~X Y qX n|S dS )a  
        Given a call (or simply an (args, kwargs) tuple), return a
        comparison key suitable for matching with other calls.
        This is a best effort method which relies on the spec's signature,
        if available, or falls back on the arguments themselves.
        r   r   Nr   )r"   rZ   r   r  r   r?   	TypeErrorwith_traceback)rA   _callrE   r   rB   rC   r  r   r   r   _call_matcherH  s    

"zNonCallableMock._call_matcherc                 C   s0   | j dkr,d| jpd| j |  f }t|dS )z/assert that the mock was never called.
        r   z9Expected '%s' to not have been called. Called %s times.%sr5   Nrz   r   _calls_reprAssertionErrorrA   r
  r   r   r   rm   b  s    
z!NonCallableMock.assert_not_calledc                 C   s$   | j dkr d| jpd }t|dS )z6assert that the mock was called at least once
        r   z"Expected '%s' to have been called.r5   N)rz   r   r  r   r   r   r   rl   l  s
    
zNonCallableMock.assert_calledc                 C   s0   | j dks,d| jpd| j |  f }t|dS )z3assert that the mock was called only once.
        r   z:Expected '%s' to have been called once. Called %s times.%sr5   Nr  r   r   r   r   rn   t  s    
z"NonCallableMock.assert_called_oncec                   s   j dkr. }d}d||f }t| fdd} f}j }||kr~t|trn|nd}t| |dS )zassert that the last call was made with the specified arguments.

        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock.Nznot called.z0expected call not found.
Expected: %s
Actual: %sc                     s     } | S r/   r  r
  rB   rC   rA   r   r   _error_message  s    z:NonCallableMock.assert_called_with.<locals>._error_message)r{   r  r  r  r"   	Exception)rA   rB   rC   expectedactualZerror_messager$  causer   r#  r   rj   ~  s    
z"NonCallableMock.assert_called_withc                O   s8   | j dks,d| jpd| j |  f }t|| j||S )ziassert that the mock was called exactly once and that that call was
        with the specified arguments.r   z3Expected '%s' to be called once. Called %s times.%sr5   )rz   r   r  r  rj   rA   rB   rC   r
  r   r   r   ro     s    
z'NonCallableMock.assert_called_once_withc           	   	      s   fdd|D }t dd |D d}t fdd jD }|s||kr|dkrXd}ndd	d |D }t| d
t|  jddd |dS t|}g }|D ]2}z|| W q t	k
r   |
| Y qX q|rtd jpdt||f |dS )a  assert the mock has been called with the specified calls.
        The `mock_calls` list is checked for the calls.

        If `any_order` is False (the default) then the calls must be
        sequential. There can be extra calls before or after the
        specified calls.

        If `any_order` is True then the calls can be in any order, but
        they must all appear in `mock_calls`.c                    s   g | ]}  |qS r   r  r   cr   r   r   r     s     z4NonCallableMock.assert_has_calls.<locals>.<listcomp>c                 s   s   | ]}t |tr|V  qd S r/   r"   r%  r   r   r   r   	<genexpr>  s     
 z3NonCallableMock.assert_has_calls.<locals>.<genexpr>Nc                 3   s   | ]}  |V  qd S r/   r*  r+  r   r   r   r.    s     zCalls not found.z+Error processing expected calls.
Errors: {}c                 S   s   g | ]}t |tr|nd qS r/   r-  r   r   r   r   r     s   
Expected: ZActual)prefixr   z@%r does not contain all of %r in its call list, found %r insteadr5   )r   rr   rt   formatr  r  rstriprY   remover<   r   r   rZ   )	rA   calls	any_orderr&  r(  Z	all_callsproblem	not_foundkallr   r   r   rp     sH    
" z NonCallableMock.assert_has_callsc                   sZ     ||f} fdd jD }||krVt|tr8|nd} ||}td| |dS )zassert the mock has been called with the specified arguments.

        The assert passes if the mock has *ever* been called, unlike
        `assert_called_with` and `assert_called_once_with` that only pass if
        the call is the most recent one.c                    s   g | ]}  |qS r   r*  r+  r   r   r   r     s     z3NonCallableMock.assert_any_call.<locals>.<listcomp>Nz%s call not found)r  r|   r"   r%  r  r  rA   rB   rC   r&  r'  r(  r  r   r   r   rq     s    zNonCallableMock.assert_any_callc                K   s   | d}|| jd kr"tf |S t| }t|trB|tkrBt}nbt|trp|tksd| j	rj|| j	krjt}qt}n4t|t
st|trt}qt|trt}n
|jd }| jrd|krd|d  nd}|  | }t||f |S )aP  Create the child mocks for attributes and return value.
        By default child mocks will be the same type as the parent.
        Subclasses of Mock may want to override this to customize the way
        child mocks are made.

        For non-callable mocks the callable variant will be used (rather than
        any custom subclass).r   r   r   r   r   r   )r^   r]   r	   r1   r0   r   _async_method_magicsr   _all_sync_magicsr   CallableMixinr   r   r   r\   r   r   r:   )rA   r   r   _typeklassrU   r  r   r   r   r     s2    






zNonCallableMock._get_child_mockCallsc                 C   s"   | j s
dS d| dt| j  dS )zRenders self.mock_calls as a string.

        Example: "
Calls: [call(1), call(2)]."

        If self.mock_calls is empty, an empty string is returned. The
        output will be truncated if very long.
        r   
z: r   )rt   r   )rA   r0  r   r   r   r    s    zNonCallableMock._calls_repr)NNNNNNr   NFNF)F)FF)N)r   )F)r?  )-rM   rP   r   rN   r   r8   r   r   r   Z"_NonCallableMock__get_return_valueZ"_NonCallableMock__set_return_valueZ"_NonCallableMock__return_value_docr   rv   r   r   ry   rz   r{   r|   rt   Z!_NonCallableMock__get_side_effectZ!_NonCallableMock__set_side_effectr}   ru   r   r   r   r   r  r  r  r  r  r  r  rm   rl   rn   rj   ro   rp   rq   r   r  r   r   r   r   r     sp                      
-
	  


''
!


-'r   c                 C   sL   | d kr| S t | r| S t| r$| S z
t| W S  tk
rF   |  Y S X d S r/   )r3   rX   r   r  r(   r   r   r   r     s    
r   c                
   @   sR   e Zd Zddedddddddf
ddZdd Zdd Zd	d
 Zdd Zdd Z	dS )r<  Nr   c              	   K   s6   || j d< tt| j|||||||	|
f| || _d S )Nr   )r]   r   r<  r8   r}   )rA   r   r}   rv   r   r   r   r   r   r   r   rC   r   r   r   r8   #  s    

      zCallableMixin.__init__c                O   s   d S r/   r   r@   r   r   r   rH   /  s    zCallableMixin._mock_check_sigc                O   s$   | j || | j|| | j||S r/   )rH   _increment_mock_call
_mock_callr@   r   r   r   r9   4  s    zCallableMixin.__call__c                O   s   | j ||S r/   )_execute_mock_callr@   r   r   r   rB  <  s    zCallableMixin._mock_callc                O   s   d| _ |  jd7  _t||fdd}|| _| j| | jd k	}| j}| j}|dk}| j	td||f | j
}|d k	r|r|jt|||f |jd k	}|r|jd | }t|||f}	|j	|	 |jr|rd}
nd}
|jdk}|j|
 | }|j
}qpd S )NTr   twor   r   r   )ry   rz   _Callr{   r|   r   r   r   r   rt   r   rs   )rA   rB   rC   r  Zdo_method_callsZmethod_call_nameZmock_call_nameZ	is_a_callr   Zthis_mock_callr   r   r   r   rA  ?  s4    


z"CallableMixin._increment_mock_callc                O   s|   | j }|d k	rPt|r|n(t|s:t|}t|rD|n
|||}|tk	rP|S | jtk	r`| jS | jd k	rv| j||S | jS r/   )r}   r3   rX   r   r   r   rv   r   )rA   rB   rC   effectrf   r   r   r   rC  m  s     


z CallableMixin._execute_mock_call)
rM   rP   r   r   r8   rH   r9   rB  rA  rC  r   r   r   r   r<  !  s        
.r<  c                   @   s   e Zd ZdZdS )r   a	  
    Create a new `Mock` object. `Mock` takes several optional arguments
    that specify the behaviour of the Mock object:

    * `spec`: This can be either a list of strings or an existing object (a
      class or instance) that acts as the specification for the mock object. If
      you pass in an object then a list of strings is formed by calling dir on
      the object (excluding unsupported magic attributes and methods). Accessing
      any attribute not in this list will raise an `AttributeError`.

      If `spec` is an object (rather than a list of strings) then
      `mock.__class__` returns the class of the spec object. This allows mocks
      to pass `isinstance` tests.

    * `spec_set`: A stricter variant of `spec`. If used, attempting to *set*
      or get an attribute on the mock that isn't on the object passed as
      `spec_set` will raise an `AttributeError`.

    * `side_effect`: A function to be called whenever the Mock is called. See
      the `side_effect` attribute. Useful for raising exceptions or
      dynamically changing return values. The function is called with the same
      arguments as the mock, and unless it returns `DEFAULT`, the return
      value of this function is used as the return value.

      If `side_effect` is an iterable then each call to the mock will return
      the next value from the iterable. If any of the members of the iterable
      are exceptions they will be raised instead of returned.

    * `return_value`: The value returned when the mock is called. By default
      this is a new Mock (created on first access). See the
      `return_value` attribute.

    * `wraps`: Item for the mock object to wrap. If `wraps` is not None then
      calling the Mock will pass the call through to the wrapped object
      (returning the real result). Attribute access on the mock will return a
      Mock object that wraps the corresponding attribute of the wrapped object
      (so attempting to access an attribute that doesn't exist will raise an
      `AttributeError`).

      If the mock has an explicit `return_value` set then calls are not passed
      to the wrapped object and the `return_value` is returned instead.

    * `name`: If the mock has a name then it will be used in the repr of the
      mock. This can be useful for debugging. The name is propagated to child
      mocks.

    Mocks can also be called with arbitrary keyword arguments. These will be
    used to set attributes on the mock after it is created.
    NrM   rP   r   rN   r   r   r   r   r     s   r   c                 C   s8   zt | |W S  tk
r2   t| t | | Y S X d S r/   )r$   r:   
__import__)thingcompimport_pathr   r   r   _dot_lookup  s
    rM  c                 C   sB   |  d}|d}t|}|D ]}|d| 7 }t|||}q |S )Nr   r   z.%s)r   r   rI  rM  )targetZ
componentsrL  rJ  rK  r   r   r   	_importer  s    

rO  c                   @   sz   e Zd ZdZg Zdd Zdd Zdd Zdd	 Ze	j
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S )_patchNc
           
      C   sn   |d k	r(|t k	rtd|d k	r(td|| _|| _|| _|| _|| _|| _d| _|| _	|| _
|	| _g | _d S )Nz,Cannot use 'new' and 'new_callable' togetherz1Cannot use 'autospec' and 'new_callable' togetherF)r   r<   getterrU   r   new_callabler   createZ	has_localr   autospecrC   additional_patchers)
rA   rQ  rU   r   r   rS  r   rT  rR  rC   r   r   r   r8     s(    z_patch.__init__c              
   C   sH   t | j| j| j| j| j| j| j| j| j		}| j
|_
dd | jD |_|S )Nc                 S   s   g | ]}|  qS r   )copy)r   pr   r   r   r     s    z_patch.copy.<locals>.<listcomp>)rP  rQ  rU   r   r   rS  r   rT  rR  rC   attribute_namerU  )rA   patcherr   r   r   rV    s           z_patch.copyc                 C   s2   t |tr| |S t|r(| |S | |S r/   )r"   r1   decorate_classr'   r&   decorate_async_callabledecorate_callablerA   r-   r   r   r   r9     s
    



z_patch.__call__c                 C   sN   t |D ]@}|tjsqt||}t|ds0q|  }t|||| q|S Nr9   )r   r   r   TEST_PREFIXr$   r#   rV  rS   )rA   r>  r   
attr_valuerY  r   r   r   rZ    s    

z_patch.decorate_classc              	   c   sr   g }t  \}|jD ]8}||}|jd k	r8|| q|jtkr|| q|t	|7 }||fV  W 5 Q R X d S r/   )

contextlib	ExitStack	patchingsenter_contextrX  updater   r   r   rZ   )rA   patchedrB   keywargs
extra_args
exit_stackpatchingr   r   r   r   decoration_helper  s    




z_patch.decoration_helperc                    s>   t  dr j  S t  fddg_S )Nrc  c               
      s4    | |\}} ||W  5 Q R  S Q R X d S r/   rk  rB   rg  ZnewargsZnewkeywargsr-   rf  rA   r   r   rf  (  s    z)_patch.decorate_callable.<locals>.patchedr#   rc  r   r   r]  r   rn  r   r\  "  s    
z_patch.decorate_callablec                    s>   t  dr j  S t  fddg_S )Nrc  c               
      s:    | |"\}} ||I d H W  5 Q R  S Q R X d S r/   rl  rm  rn  r   r   rf  9  s    z/_patch.decorate_async_callable.<locals>.patchedro  r]  r   rn  r   r[  3  s    
z_patch.decorate_async_callablec              	   C   s   |   }| j}t}d}z|j| }W n$ ttfk
rH   t||t}Y nX d}|tkrft|t	rfd| _
| j
s|tkrtd||f ||fS )NFTz!%s does not have the attribute %r)rQ  rU   r   r]   r:   KeyErrorr$   	_builtinsr"   r   rS  )rA   rN  r   re   localr   r   r   get_originalD  s     
z_patch.get_originalc                 C   s  | j | j| j  }}}| j| j }}| j}|  | _|dkr@d}|dkrLd}|dkrXd}|dk	rp|dk	rptd|dk	s|dk	r|dkrtd| 	 \}}|t
kr||dkr|d}	|dkr|}|dkr|}d}n&|dk	r|dkr|}d}n|dkr|}|dk	s|dk	r.|t
krtdt|tr.d}	|dkrHt|rHt}
nt}
i }|dk	r`|}
n^|dk	st|dk	r|}|dk	r|}t|rd|k}n
t| }t|rt}
n
|rt}
|dk	r||d	< |dk	r||d
< t|
trt|
tr| jr| j|d< || |
f |}|	rt|r|}|dk	rB|}t|sZt|sZt}
|d |
f |dd||_nl|dk	r|t
k	rtd|t
krtdt|}|dkr|}t|f|| jd|}n|rtd|}|| _|| _t  | _!zrt"| j| j| | j#dk	rpi }| j t
kr:||| j#< | j$D ](}| j!%|}|j t
kr@|| q@|W S |W S    | j&t'(  s Y nX dS )zPerform the patch.FNzCan't specify spec and autospec)TNz6Can't provide explicit spec_set *and* spec or autospecTz!Can't use 'spec' with create=Truer9   r   r   r   r   r   zBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=True)r   _namez.Can't pass kwargs to a mock we aren't creating))r   r   r   rT  rC   rR  rQ  rN  r  rs  r   r"   r1   r*   r	   r   r[   r   r   r0   r   rU   re  r!   r`   r   rv   boolr   temp_originalis_localra  rb  _exit_stackrS   rX  rU  rd  __exit__sysexc_info)rA   r   r   r   rT  rC   rR  re   rr  ZinheritKlass_kwargsZ	this_specZnot_callableZnew_attrrh  rj  r   r   r   r   	__enter__\  s    























z_patch.__enter__c                 G   s   | j r$| jtk	r$t| j| j| j n>t| j| j | jsbt| j| jrP| jdkrbt| j| j| j | `| ` | `| j	}| `	|j
| S )zUndo the patch.)rN   rP   rQ   __annotations__rR   )rw  rv  r   rS   rN  rU   r  rS  r#   rx  ry  )rA   r{  ri  r   r   r   ry    s    z_patch.__exit__c                 C   s   |   }| j|  |S )z-Activate a patch, returning any created mock.)r~  _active_patchesr   )rA   rf   r   r   r   start  s    z_patch.startc                 C   s6   z| j |  W n tk
r&   Y dS X | dddS )zStop an active patch.N)r  r3  r<   ry  r   r   r   r   stop  s
    z_patch.stop)rM   rP   r   rX  r  r8   rV  r9   rZ  ra  contextmanagerrk  r\  r[  rs  r~  ry  r  r  r   r   r   r   rP    s    
 rP  c              	      sP   z  dd\ }W n& ttfk
r:   td f Y nX  fdd}||fS )Nr   r   z.Need a valid target to patch. You supplied: %rc                      s   t  S r/   rO  r   rN  r   r   r     r   z_get_target.<locals>.<lambda>)rsplitr  r<   )rN  rU   rQ  r   r  r   _get_target
  s    r  c           
   
      s>   t  tkrt d fdd}	t|	||||||||	S )a  
    patch the named member (`attribute`) on an object (`target`) with a mock
    object.

    `patch.object` can be used as a decorator, class decorator or a context
    manager. Arguments `new`, `spec`, `create`, `spec_set`,
    `autospec` and `new_callable` have the same meaning as for `patch`. Like
    `patch`, `patch.object` takes arbitrary keyword arguments for configuring
    the mock object it creates.

    When used as a class decorator `patch.object` honours `patch.TEST_PREFIX`
    for choosing which methods to wrap.
    z3 must be the actual object to be patched, not a strc                      s    S r/   r   r   r  r   r   r   *  r   z_patch_object.<locals>.<lambda>)r1   strr  rP  )
rN  rU   r   r   rS  r   rT  rR  rC   rQ  r   r  r   _patch_object  s            r  c                    s   t  tkr fdd}n fdd}|s2tdt| }|d \}	}
t||	|
|||||i 	}|	|_|dd D ]2\}	}
t||	|
|||||i 	}|	|_|j| qt|S )a  Perform multiple patches in a single call. It takes the object to be
    patched (either as an object or a string to fetch the object by importing)
    and keyword arguments for the patches::

        with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'):
            ...

    Use `DEFAULT` as the value if you want `patch.multiple` to create
    mocks for you. In this case the created mocks are passed into a decorated
    function by keyword, and a dictionary is returned when `patch.multiple` is
    used as a context manager.

    `patch.multiple` can be used as a decorator, class decorator or a context
    manager. The arguments `spec`, `spec_set`, `create`,
    `autospec` and `new_callable` have the same meaning as for `patch`. These
    arguments will be applied to *all* patches done by `patch.multiple`.

    When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX`
    for choosing which methods to wrap.
    c                      s   t  S r/   r  r   r  r   r   r   H  r   z!_patch_multiple.<locals>.<lambda>c                      s    S r/   r   r   r  r   r   r   J  r   z=Must supply at least one keyword argument with patch.multipler   r   N)	r1   r  r<   rY   r   rP  rX  rU  r   )rN  r   rS  r   rT  rR  rC   rQ  r   rU   r   rY  Zthis_patcherr   r  r   _patch_multiple1  sH                  r  c           
   
   K   s$   t | \}}	t||	|||||||	S )a7  
    `patch` acts as a function decorator, class decorator or a context
    manager. Inside the body of the function or with statement, the `target`
    is patched with a `new` object. When the function/with statement exits
    the patch is undone.

    If `new` is omitted, then the target is replaced with an
    `AsyncMock if the patched object is an async function or a
    `MagicMock` otherwise. If `patch` is used as a decorator and `new` is
    omitted, the created mock is passed in as an extra argument to the
    decorated function. If `patch` is used as a context manager the created
    mock is returned by the context manager.

    `target` should be a string in the form `'package.module.ClassName'`. The
    `target` is imported and the specified object replaced with the `new`
    object, so the `target` must be importable from the environment you are
    calling `patch` from. The target is imported when the decorated function
    is executed, not at decoration time.

    The `spec` and `spec_set` keyword arguments are passed to the `MagicMock`
    if patch is creating one for you.

    In addition you can pass `spec=True` or `spec_set=True`, which causes
    patch to pass in the object being mocked as the spec/spec_set object.

    `new_callable` allows you to specify a different class, or callable object,
    that will be called to create the `new` object. By default `AsyncMock` is
    used for async functions and `MagicMock` for the rest.

    A more powerful form of `spec` is `autospec`. If you set `autospec=True`
    then the mock will be created with a spec from the object being replaced.
    All attributes of the mock will also have the spec of the corresponding
    attribute of the object being replaced. Methods and functions being
    mocked will have their arguments checked and will raise a `TypeError` if
    they are called with the wrong signature. For mocks replacing a class,
    their return value (the 'instance') will have the same spec as the class.

    Instead of `autospec=True` you can pass `autospec=some_object` to use an
    arbitrary object as the spec instead of the one being replaced.

    By default `patch` will fail to replace attributes that don't exist. If
    you pass in `create=True`, and the attribute doesn't exist, patch will
    create the attribute for you when the patched function is called, and
    delete it again afterwards. This is useful for writing tests against
    attributes that your production code creates at runtime. It is off by
    default because it can be dangerous. With it switched on you can write
    passing tests against APIs that don't actually exist!

    Patch can be used as a `TestCase` class decorator. It works by
    decorating each test method in the class. This reduces the boilerplate
    code when your test methods share a common patchings set. `patch` finds
    tests by looking for method names that start with `patch.TEST_PREFIX`.
    By default this is `test`, which matches the way `unittest` finds tests.
    You can specify an alternative prefix by setting `patch.TEST_PREFIX`.

    Patch can be used as a context manager, with the with statement. Here the
    patching applies to the indented block after the with statement. If you
    use "as" then the patched object will be bound to the name after the
    "as"; very useful if `patch` is creating a mock object for you.

    `patch` takes arbitrary keyword arguments. These will be passed to
    the `Mock` (or `new_callable`) on construction.

    `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are
    available for alternate use-cases.
    )r  rP  )
rN  r   r   rS  r   rT  rR  rC   rQ  rU   r   r   r   r   b  s    F       r   c                   @   sR   e Zd ZdZdddZdd Zdd	 Zd
d Zdd Zdd Z	dd Z
eZe
ZdS )_patch_dicta#  
    Patch a dictionary, or dictionary like object, and restore the dictionary
    to its original state after the test.

    `in_dict` can be a dictionary or a mapping like container. If it is a
    mapping then it must at least support getting, setting and deleting items
    plus iterating over keys.

    `in_dict` can also be a string specifying the name of the dictionary, which
    will then be fetched by importing it.

    `values` can be a dictionary of values to set in the dictionary. `values`
    can also be an iterable of `(key, value)` pairs.

    If `clear` is True then the dictionary will be cleared before the new
    values are set.

    `patch.dict` can also be called with arbitrary keyword arguments to set
    values in the dictionary::

        with patch.dict('sys.modules', mymodule=Mock(), other_module=Mock()):
            ...

    `patch.dict` can be used as a context manager, decorator or class
    decorator. When used as a class decorator `patch.dict` honours
    `patch.TEST_PREFIX` for choosing which methods to wrap.
    r   Fc                 K   s,   || _ t|| _| j| || _d | _d S r/   )in_dictdictr   re  clear	_original)rA   r  r   r  rC   r   r   r   r8     s
    
z_patch_dict.__init__c                    s.   t  tr S t  fdd}|S )Nc                     s&      z | |W S   X d S r/   )r  _unpatch_dictr  frA   r   r   _inner  s    z$_patch_dict.__call__.<locals>._inner)r"   r1   rZ  r   )rA   r  r  r   r  r   r9     s
    

z_patch_dict.__call__c                 C   sX   t |D ]J}t||}|tjrt|drt| j| j| j	}||}t
||| q|S r^  )r   r$   r   r   r_  r#   r  r  r   r  rS   )rA   r>  r   r`  Z	decoratorZ	decoratedr   r   r   rZ    s    
z_patch_dict.decorate_classc                 C   s   |    | jS )zPatch the dict.)r  r  r   r   r   r   r~    s    z_patch_dict.__enter__c                 C   s   | j }t| jtrt| j| _| j}| j}z| }W n. tk
rd   i }|D ]}|| ||< qNY nX || _|rxt	| z|
| W n* tk
r   |D ]}|| ||< qY nX d S r/   )r   r"   r  r  rO  r  rV  r:   r  _clear_dictre  )rA   r   r  r  re   r   r   r   r   r    s&    z_patch_dict._patch_dictc                 C   sR   | j }| j}t| z|| W n* tk
rL   |D ]}|| ||< q6Y nX d S r/   )r  r  r  re  r:   )rA   r  re   r   r   r   r   r    s    z_patch_dict._unpatch_dictc                 G   s   |    dS )zUnpatch the dict.F)r  )rA   rB   r   r   r   ry    s    z_patch_dict.__exit__N)r   F)rM   rP   r   rN   r8   r9   rZ  r~  r  r  ry  r  r  r   r   r   r   r    s   
	r  c                 C   s>   z|    W n, tk
r8   t| }|D ]
}| |= q(Y nX d S r/   )r  r:   rY   )r  r   r   r   r   r   r  &  s    r  c                  C   s   t tjD ]} |   q
dS )z7Stop all active patches. LIFO to unroll nested patches.N)r   rP  r  r  )r   r   r   r   _patch_stopall/  s    r  Ztestzlt le gt ge eq ne getitem setitem delitem len contains iter hash str sizeof enter exit divmod rdivmod neg pos abs invert complex int float index round trunc floor ceil bool next fspath aiter zHadd sub mul matmul div floordiv mod lshift rshift and xor or pow truediv c                 c   s   | ]}d | V  qdS )zi%sNr   r   nr   r   r   r.  N  s     r.  c                 c   s   | ]}d | V  qdS )zr%sNr   r  r   r   r   r.  O  s     __get____set__
__delete____reversed____missing__r   __reduce_ex__Z__getinitargs____getnewargs____getstate____setstate____getformat__Z__setformat__r   r  __subclasses__
__format____getnewargs_ex__c                    s    fdd}| |_ |S )z:Turns a callable object (like a mock) into a real functionc                   s    | f||S r/   r   rA   rB   r   r,   r   r   method`  s    z_get_method.<locals>.method)rM   )r   r-   r  r   r,   r   r	  ^  s    r	  c                 C   s   h | ]}d | qS )r   r   )r   r  r   r   r   r   f  s    
__aenter__	__aexit__	__anext__	__aiter__r   r  r8   r   __prepare____instancecheck____subclasscheck____del__c                 C   s
   t | S r/   )r  __hash__r   r   r   r   r   |  r   r   c                 C   s
   t | S r/   )r  __str__r   r   r   r   r   }  r   c                 C   s
   t | S r/   )r  
__sizeof__r   r   r   r   r   ~  r   c                 C   s"   t | j d|   dt|  S )N/)r1   rM   r   r   r   r   r   r   r     r   )r  r  r  
__fspath__r   y              ?g      ?)__lt____gt____le____ge____int__r   __len__ry  __complex__	__float____bool__	__index__r  c                    s    fdd}|S )Nc                    s$    j j}|tk	r|S  | kr dS tS NT)__eq__r   r   NotImplemented)otherret_valr   r   r   r    s    z_get_eq.<locals>.__eq__r   )rA   r  r   r   r   _get_eq  s    r  c                    s    fdd}|S )Nc                    s     j jtk	rtS  | krdS tS NF)__ne__r   r   r  )r  r   r   r   r    s
    z_get_ne.<locals>.__ne__r   )rA   r  r   r   r   _get_ne  s    r  c                    s    fdd}|S )Nc                     s     j j} | tkrtg S t| S r/   )__iter__r   r   r   r  r   r   r   r    s    z_get_iter.<locals>.__iter__r   )rA   r  r   r   r   	_get_iter  s    r  c                    s    fdd}|S )Nc                     s(    j j} | tkrttg S tt| S r/   )r  r   r   _AsyncIteratorr   r  r   r   r   r    s    z"_get_async_iter.<locals>.__aiter__r   )rA   r  r   r   r   _get_async_iter  s    r  )r  r  r  r  c                 C   sb   t |t}|tk	r||_d S t|}|d k	rB|| }||_d S t|}|d k	r^|| |_d S r/   )_return_valuesr^   r   rv   _calculate_return_value_side_effect_methodsr}   )r5   r  r   ZfixedZreturn_calculatorrv   Zside_effectorr   r   r   _set_return_value  s    

r  c                   @   s   e Zd Zdd Zdd ZdS )
MagicMixinc                O   s&   |    tt| j|| |    d S r/   )_mock_set_magicsr   r  r8   r  r   r   r   r8     s    zMagicMixin.__init__c                 C   s   t tB }|}t| dd d k	rX|| j}t }|| }|D ]}|t| jkr:t| | q:|tt| j }t| }|D ]}t	||t
||  qvd S )Nr   )_magicsr:  r$   intersectionr   r  r1   r]   r  rS   
MagicProxy)rA   Zorig_magicsZthese_magicsZremove_magicsr   r=  r   r   r   r    s    zMagicMixin._mock_set_magicsN)rM   rP   r   r8   r  r   r   r   r   r    s   r  c                   @   s   e Zd ZdZdddZdS )r   z-A version of `MagicMock` that isn't callable.Fc                 C   s   |  || |   dS r   r   r  r   r   r   r   r     s    z"NonCallableMagicMock.mock_add_specN)FrM   rP   r   rN   r   r   r   r   r   r     s   r   c                   @   s   e Zd Zdd ZdS )AsyncMagicMixinc                O   s&   |    tt| j|| |    d S r/   )r  r   r  r8   r  r   r   r   r8     s    zAsyncMagicMixin.__init__NrM   rP   r   r8   r   r   r   r   r    s   r  c                   @   s   e Zd ZdZdddZdS )r   a  
    MagicMock is a subclass of Mock with default implementations
    of most of the magic methods. You can use MagicMock without having to
    configure the magic methods yourself.

    If you use the `spec` or `spec_set` arguments then *only* magic
    methods that exist in the spec will be created.

    Attributes and the return value of a `MagicMock` will also be `MagicMocks`.
    Fc                 C   s   |  || |   dS r   r  r   r   r   r   r     s    zMagicMock.mock_add_specN)Fr  r   r   r   r   r     s   
r   c                   @   s&   e Zd Zdd Zdd ZdddZdS )	r  c                 C   s   || _ || _d S r/   r   r   )rA   r   r   r   r   r   r8     s    zMagicProxy.__init__c                 C   s8   | j }| j}|j|||d}t||| t||| |S )N)r   r   r   )r   r   r   rS   r  )rA   r   r   mr   r   r   create_mock  s    zMagicProxy.create_mockNc                 C   s   |   S r/   )r  )rA   r)   r=  r   r   r   r  (  s    zMagicProxy.__get__)N)rM   rP   r   r8   r  r  r   r   r   r   r    s   	r  c                       s   e Zd ZedZedZedZ fddZdd Zdd	 Z	d
d Z
dd Zdd Zdd ZdddZdd Z fddZ  ZS )r   r   r   r   c                   s\   t  j|| tjj| jd< d| jd< d | jd< t | jd< ttd}t	j
|_|| jd< d S )Nr   r   Z_mock_await_countZ_mock_await_argsZ_mock_await_args_listr   r+   )superr8   r%   r   r   r]   rr   r   r   r'   ZCO_COROUTINEco_flags)rA   rB   rC   	code_mockr   r   r   r8   1  s    


zAsyncMockMixin.__init__c                   s  t ||fdd}|  jd7  _|| _| j| | j}|d k	rt|rL|nbt|szt|}W n t	k
rx   t
Y nX t|r|n&t|r|||I d H }n
|||}|tk	r|S | jtk	r| jS | jd k	rt| jr| j||I d H S | j||S | jS )NTrD  r   )rF  r   r   r   r   r}   r3   rX   r   StopIterationStopAsyncIterationr%   r&   r   r   rv   r   )rA   rB   rC   r  rG  rf   r   r   r   rC  A  s6    




z!AsyncMockMixin._execute_mock_callc                 C   s(   | j dkr$d| jpd d}t|dS )zA
        Assert that the mock was awaited at least once.
        r   	Expected r5   z to have been awaited.Nr   r   r  r   r   r   r   r   i  s    
zAsyncMockMixin.assert_awaitedc                 C   s0   | j dks,d| jpd d| j  d}t|dS )z@
        Assert that the mock was awaited exactly once.
        r   r  r5   $ to have been awaited once. Awaited  times.Nr  r   r   r   r   r   q  s    
z"AsyncMockMixin.assert_awaited_oncec                   sz   j dkr& }td| d fdd} f}j }||krvt|trf|nd}t| |dS )zN
        Assert that the last await was with the specified arguments.
        NzExpected await: z
Not awaitedc                     s   j  dd} | S )Nawait)r  r!  r"  r#  r   r   r$    s    z:AsyncMockMixin.assert_awaited_with.<locals>._error_message)r   r  r  r  r"   r%  )rA   rB   rC   r&  r$  r'  r(  r   r#  r   r   z  s    
z"AsyncMockMixin.assert_awaited_withc                O   s8   | j dks,d| jpd d| j  d}t|| j||S )zi
        Assert that the mock was awaited exactly once and with the specified
        arguments.
        r   r  r5   r  r  )r   r   r  r   r)  r   r   r   r     s    
z'AsyncMockMixin.assert_awaited_once_withc                   sZ     ||f} fdd jD }||krVt|tr8|nd} ||}td| |dS )zU
        Assert the mock has ever been awaited with the specified arguments.
        c                    s   g | ]}  |qS r   r*  r+  r   r   r   r     s     z3AsyncMockMixin.assert_any_await.<locals>.<listcomp>Nz%s await not found)r  r   r"   r%  r  r  r9  r   r   r   r     s    zAsyncMockMixin.assert_any_awaitFc           	   	      s    fdd|D }t dd |D d}t fdd jD }|s||kr|dkrXd}ndd	d |D }t| d
t| d j |dS t|}g }|D ]2}z|| W q tk
r   || Y qX q|rtdt	|f |dS )a  
        Assert the mock has been awaited with the specified calls.
        The :attr:`await_args_list` list is checked for the awaits.

        If `any_order` is False (the default) then the awaits must be
        sequential. There can be extra calls before or after the
        specified awaits.

        If `any_order` is True then the awaits can be in any order, but
        they must all appear in :attr:`await_args_list`.
        c                    s   g | ]}  |qS r   r*  r+  r   r   r   r     s     z4AsyncMockMixin.assert_has_awaits.<locals>.<listcomp>c                 s   s   | ]}t |tr|V  qd S r/   r-  r   r   r   r   r.    s     
 z3AsyncMockMixin.assert_has_awaits.<locals>.<genexpr>Nc                 3   s   | ]}  |V  qd S r/   r*  r+  r   r   r   r.    s     zAwaits not found.z,Error processing expected awaits.
Errors: {}c                 S   s   g | ]}t |tr|nd qS r/   r-  r   r   r   r   r     s   r/  z	
Actual: z%r not all found in await list)
r   rr   r   r1  r  rY   r3  r<   r   rZ   )	rA   r4  r5  r&  r(  Z
all_awaitsr6  r7  r8  r   r   r   r     s>    z AsyncMockMixin.assert_has_awaitsc                 C   s0   | j dkr,d| jpd d| j  d}t|dS )z9
        Assert that the mock was never awaited.
        r   r  r5   z# to not have been awaited. Awaited r  Nr  r   r   r   r   r     s    
z!AsyncMockMixin.assert_not_awaitedc                   s&   t  j|| d| _d| _t | _dS )z0
        See :func:`.Mock.reset_mock()`
        r   N)r  ru   r   r   rr   r   r@   r  r   r   ru     s    zAsyncMockMixin.reset_mock)F)rM   rP   r   r   r   r   r   r8   rC  r   r   r   r   r   r   r   ru   __classcell__r   r   r  r   r   ,  s   (	
,	r   c                   @   s   e Zd ZdZdS )r	   aa  
    Enhance :class:`Mock` with features allowing to mock
    an async function.

    The :class:`AsyncMock` object will behave so the object is
    recognized as an async function, and the result of a call is an awaitable:

    >>> mock = AsyncMock()
    >>> asyncio.iscoroutinefunction(mock)
    True
    >>> inspect.isawaitable(mock())
    True


    The result of ``mock()`` is an async function which will have the outcome
    of ``side_effect`` or ``return_value``:

    - if ``side_effect`` is a function, the async function will return the
      result of that function,
    - if ``side_effect`` is an exception, the async function will raise the
      exception,
    - if ``side_effect`` is an iterable, the async function will return the
      next value of the iterable, however, if the sequence of result is
      exhausted, ``StopIteration`` is raised immediately,
    - if ``side_effect`` is not defined, the async function will return the
      value defined by ``return_value``, hence, by default, the async function
      returns a new :class:`AsyncMock` object.

    If the outcome of ``side_effect`` or ``return_value`` is an async function,
    the mock async function obtained when the mock object is called will be this
    async function itself (and not an async function returning an async
    function).

    The test author can also specify a wrapped object with ``wraps``. In this
    case, the :class:`Mock` object behavior is the same as with an
    :class:`.Mock` object: the wrapped object may have methods
    defined as async function functions.

    Based on Martin Richard's asynctest project.
    NrH  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S )	_ANYz2A helper object that compares equal to everything.c                 C   s   dS r  r   rA   r  r   r   r   r  	  s    z_ANY.__eq__c                 C   s   dS r  r   r  r   r   r   r  	  s    z_ANY.__ne__c                 C   s   dS )Nz<ANY>r   r   r   r   r   r   	  s    z_ANY.__repr__N)rM   rP   r   rN   r  r  r   r   r   r   r   r  	  s   r  c                 C   s`   d|  }d}d dd |D }d dd | D }|r@|}|rX|rP|d7 }||7 }|| S )Nz%s(%%s)r   z, c                 S   s   g | ]}t |qS r   )reprr   r   r   r   r   !	  s     z*_format_call_signature.<locals>.<listcomp>c                 S   s   g | ]\}}d ||f qS )z%s=%rr   )r   r   r   r   r   r   r   "	  s    )r   r   )r   rB   rC   r  Zformatted_argsZargs_stringZkwargs_stringr   r   r   r  	  s    
r  c                   @   s   e Zd ZdZd!ddZd"d	d
Zdd ZejZdd Z	dd Z
dd Zdd Zdd Zdd Zedd Zedd Zdd Zdd  ZdS )#rF  a  
    A tuple for holding the results of a call to a mock, either in the form
    `(args, kwargs)` or `(name, args, kwargs)`.

    If args or kwargs are empty then a call tuple will compare equal to
    a tuple without those values. This makes comparisons less verbose::

        _Call(('name', (), {})) == ('name',)
        _Call(('name', (1,), {})) == ('name', (1,))
        _Call(((), {'a': 'b'})) == ({'a': 'b'},)

    The `_Call` object provides a useful shortcut for comparing with call::

        _Call(((1, 2), {'a': 3})) == call(1, 2, a=3)
        _Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3)

    If the _Call has no name then it will match any name.
    r   r   NFTc                 C   s   d}i }t |}|dkr$|\}}}nr|dkrd|\}	}
t|	trX|	}t|
trR|
}qb|
}q|	|
 }}n2|dkr|\}t|tr|}nt|tr|}n|}|rt| ||fS t| |||fS )Nr      r   r   )r   r"   r  rZ   r   )r   r   r   r   rE  	from_kallrB   rC   _lenfirstsecondr   r   r   r   C	  s.    



z_Call.__new__c                 C   s   || _ || _|| _d S r/   )r   r   _mock_from_kall)rA   r   r   r   rE  r  r   r   r   r8   c	  s    z_Call.__init__c                 C   sh  |t krdS zt|}W n tk
r.   Y dS X d}t| dkrJ| \}}n
| \}}}t| dd r|t|dd r|| j|jkr|dS d}|dkrdi  }}n|dkr|\}}}n|d	kr|\}	t|	tr|	}i }n"t|	tr|	}di  }}nd}|	}nV|dkr@|\}
}t|
tr4|
}t|tr(|i  }}n
d| }}n
|
| }}ndS |rX||krXdS ||f||fkS )
NTFr   r   r   r   r   r  r   )r   r   r  r$   r   r"   rZ   r  )rA   r  Z	len_otherZ	self_nameZ	self_argsZself_kwargsZ
other_nameZ
other_argsZother_kwargsr   r  r  r   r   r   r  j	  sR    





z_Call.__eq__c                O   s<   | j d krtd||fddS | j d }t| j ||f|| dS )Nr   r   r   r  r   rF  r  r   r   r   r9   	  s    

z_Call.__call__c                 C   s2   | j d krt|ddS d| j |f }t|| ddS )NF)r   r  z%s.%s)r   r   r  r  )rA   r   r   r   r   r   r   	  s    
z_Call.__getattr__c                 C   s   |t jkrtt | |S r/   )rZ   r]   r:   __getattribute__)rA   r   r   r   r   r  	  s    
z_Call.__getattribute__c                O   s   |  d||S )Nr   r   r@   r   r   r   r   	  s    z_Call.countc                O   s   |  d||S )Nindexr  r@   r   r   r   r  	  s    z_Call.indexc                 C   s(   t | dkr| \}}n
| \}}}||fS )Nr   )r   r  r   r   r   _get_call_arguments	  s    

z_Call._get_call_argumentsc                 C   s   |   d S Nr   r  r   r   r   r   rB   	  s    z
_Call.argsc                 C   s   |   d S )Nr   r  r   r   r   r   rC   	  s    z_Call.kwargsc                 C   s|   | j s&| jpd}|dr"d| }|S t| dkr@d}| \}}n0| \}}}|sTd}n|dshd| }nd| }t|||S )Nr   r   zcall%sr   zcall.%s)r  r   r   r   r  )rA   r   rB   rC   r   r   r   r   	  s    





z_Call.__repr__c                 C   s4   g }| }|dk	r(|j r || |j}qtt|S )zFor a call object that represents multiple calls, `call_list`
        returns a list of all the intermediate calls as well as the
        final call.N)r  r   r   rr   r   )rA   ZvalsrJ  r   r   r   	call_list	  s    
z_Call.call_list)r   r   NFT)r   NNFT)rM   rP   r   rN   r   r8   r  r  r  r9   r   r  r   r  r  r   rB   rC   r   r  r   r   r   r   rF  0	  s*     
   
7

rF  )r  c              	   K   sl  t | rt| } t| t}t| }d| i}|r8d| i}n| dkrDi }|rT|rTd|d< || t}	t| rri }n8|r|rtdt	}	n"t
| st}	n|r|rt| st}	|d|}|}
|dkrd}
|	f |||
|d	|}t| trt|| }|rt| nt| ||| |dk	r,|s,||j|< |rV|sVd
|krVt| |dd|d|_t| D ]}t|rrq^zt| |}W n tk
r   Y q^Y nX d|i}|rd|i}t|tst|||||}||j|< np|}t| tr|j}t| ||}||d< t|rt	}nt}|f ||||d|}||j|< t|||d t|tr^t||| q^|S )aI  Create a mock object using another object as a spec. Attributes on the
    mock will use the corresponding attribute on the `spec` object as their
    spec.

    Functions or methods being mocked will have their arguments checked
    to check that they are called with the correct signature.

    If `spec_set` is True then attempting to set attributes that don't exist
    on the spec object will raise an `AttributeError`.

    If a class is used as a spec then the return value of the mock (the
    instance of the class) will have the same spec. You can use a class as the
    spec for an instance object by passing `instance=True`. The returned mock
    will only be callable if instances of the mock are callable.

    `create_autospec` also takes arbitrary keyword arguments that are passed to
    the constructor of the created mock.r   r   NTr   zJInstance can not be True when create_autospec is mocking an async functionr   r   )r   r   r   r   rv   r   )rK   rt  r   r   )r   r   r   r   )rJ   )r[   r1   r"   r.   re  r   r'   ZisdatadescriptorRuntimeErrorr	   rX   r   r`   r   r6   ri   r   rL   r~   r   rv   r   r   r$   r:   r   r5   
_must_skipr%   r&   rS   )r   r   rK   r   rt  rC   is_typeZis_async_funcr}  r|  r   r5   r   re   r   r   rJ   Zchild_klassr   r   r   r   	  s    







 


r   c                 C   sx   t | ts$|t| di krdS | j} | jD ]H}|j|t}|tkrFq*t |tt	frZ dS t |t
rl|  S  dS q*|S )z[
    Return whether we should skip the first argument on spec's `entry`
    attribute.
    r]   F)r"   r1   r$   r   r\   r]   r^   r   rV   rW   r6   )r   r   r  r>  rf   r   r   r   r  w
  s    


r  c                   @   s   e Zd ZdddZdS )r   FNc                 C   s(   || _ || _|| _|| _|| _|| _d S r/   )r   idsr   r   rK   r   )rA   r   r   r   r   r  rK   r   r   r   r8   
  s    z_SpecState.__init__)FNNNFr  r   r   r   r   r   
  s
         r   c                 C   s"   t | trt| S t| S d S r/   )r"   bytesioBytesIOStringIO)	read_datar   r   r   
_to_stream
  s    

r  r   c                    s&  t }|dgfdd}fdd} fddfdd	 fd
d}tdkrddl}ttt|jtt|ja| dkrt	dt
d} t	tdj_dj_dj_dj_dj_|j_ d< d j_|j_ j_|j_fdd}|| _| _| S )a  
    A helper function to create a mock to replace the use of `open`. It works
    for `open` called directly or used as a context manager.

    The `mock` argument is the mock object to configure. If `None` (the
    default) then a `MagicMock` will be created for you, with the API limited
    to methods or attributes available on standard file handles.

    `read_data` is a string for the `read`, `readline` and `readlines` of the
    file handle to return.  This is an empty string by default.
    Nc                     s$   j jd k	rj jS  d j | |S r  )	readlinesrv   ra   _statehandler   r   _readlines_side_effect
  s    z)mock_open.<locals>._readlines_side_effectc                     s$   j jd k	rj jS  d j | |S r  )readrv   ra   r  r   r   _read_side_effect
  s    z$mock_open.<locals>._read_side_effectc                  ?   s$     E d H  d j | |V  qd S r  )readlinera   )_iter_side_effectr  r   r   _readline_side_effect
  s    z(mock_open.<locals>._readline_side_effectc                  3   s0   j jd k	rj jV  q d D ]
} | V  q d S r  )r  rv   )liner  r   r   r  
  s    z$mock_open.<locals>._iter_side_effectc                      s    j jd k	rj jS t d S r  )r  rv   r   r   r  r   r   _next_side_effect
  s    z$mock_open.<locals>._next_side_effectr   open)r   r   r   r   c                     s6   t d< jjd kr2  d< d j_tS )Nr   r   )r  r  r}   r   ra   )r  r  r  r  r   r   
reset_data
  s
    
zmock_open.<locals>.reset_data)r  	file_spec_iorY   r  r   TextIOWrapperunionr  r   r  r~  rv   writer
  r  r  r}   r  r   )r5   r  Z
_read_datar	  r  r  r  r  r   )r  r  r  r  r  r   r   
  s8    "

r   c                   @   s*   e Zd ZdZdd Zd	ddZdd ZdS )
r   aW  
    A mock intended to be used as a property, or other descriptor, on a class.
    `PropertyMock` provides `__get__` and `__set__` methods so you can specify
    a return value when it is fetched.

    Fetching a `PropertyMock` instance from an object calls the mock, with
    no args. Setting it calls the mock with the value being set.
    c                K   s
   t f |S r/   )r   )rA   rC   r   r   r   r     s    zPropertyMock._get_child_mockNc                 C   s   |  S r/   r   )rA   r)   Zobj_typer   r   r   r    s    zPropertyMock.__get__c                 C   s   | | d S r/   r   )rA   r)   r   r   r   r   r    s    zPropertyMock.__set__)N)rM   rP   r   rN   r   r  r  r   r   r   r   r   
  s   
r   c              	   C   s^   d| _ t| D ]J}zt| |}W n tk
r8   Y qY nX t|tsFq|j| krt| qdS )a  Disable the automatic generation of child mocks.

    Given an input Mock, seals it to ensure no further mocks will be generated
    when accessing an attribute that was not already defined.

    The operation recursively seals the mock passed in, meaning that
    the mock itself, any mocks generated by accessing one of its attributes,
    and all assigned mocks without a name or spec will be sealed.
    TN)r   r   r$   r:   r"   r   r   r   )r5   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S )	r  z8
    Wraps an iterator in an asynchronous iterator.
    c                 C   s&   || _ ttd}tj|_|| jd< d S )Nr  r+   )iteratorr   r   r'   ZCO_ITERABLE_COROUTINEr  r]   )rA   r  r  r   r   r   r8   +  s    
z_AsyncIterator.__init__c                 C   s   | S r/   r   r   r   r   r   r  1  s    z_AsyncIterator.__aiter__c                    s*   zt | jW S  tk
r    Y nX td S r/   )r   r  r  r  r   r   r   r   r  4  s
    z_AsyncIterator.__anext__N)rM   rP   r   rN   r8   r  r  r   r   r   r   r  '  s   r  )F)F)NFNNN)FFNN)Nr   )y__all____version__r%   ra  r   r'   r   rz  builtinstypesr   r   r   Zunittest.utilr   	functoolsr   r   r   rq  r
   r  r   r*   r.   r!   r3   r7   r=   rL   rG   rX   r[   r`   ri   rd   r   r   r  r   r   r   r   MISSINGr  ZDELETEDr   r   r   rY   rr   r   r   r   r   r   r<  r   rM  rO  rP  r  r  r  r   r  r  r  r  ZmultipleZstopallr_  Zmagic_methodsZnumericsr   r   ZinplacerightZ_non_defaultsr	  r  r:  Z_sync_async_magicsZ_async_magicsr;  r   r  r  r  r  r  r  r  r  r  r  r  r   r  r   r  r   r	   r  r   r  rZ   rF  r   r   r  r   r1   r  r6   r  r  r   r   r   r  r   r   r   r   <module>   s~  	


1          	h4  <   
    
2    
Mw	             	
    
	
		 8+ B
  
 
N                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        