o
    ¯b·|  ã                   @   s²  d Z g 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
mZ ddlmZ ddl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 ddlmZ ddl m!Z!m"Z" ddl#m$Z$ e%dƒ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e$ƒZ.dZ/G d d!„ d!e$ƒZ0G d"d#„ d#e$ƒZ1d$d%„ Z2d&d'„ Z3eeƒG d(d)„ d)ƒƒZ4G d*d+„ d+e4ƒZ5G d,d-„ d-ƒZ6d.d/„ Z7G d0d1„ d1ƒZ8dS )2zK
A miscellany of code used to run Trial tests.

Maintainer: Jonathan Lange
)Ú	TestSuiteÚDestructiveTestSuiteÚErrorHolderÚLoggedSuiteÚ
TestHolderÚ
TestLoaderÚTrialRunnerÚ
TrialSuiteÚfilenameToModuleÚ	isPackageÚisPackageDirectoryÚ
isTestCaseÚnameÚsamefileÚNOT_IN_TESTé    N)ÚSourceFileLoader)Úimplementer)Údefer)ÚfailureÚfilepathÚlogÚmodulesÚreflect)ÚunittestÚutil)Ú _ForceGarbageCollectionDecoratorÚ_iterateTests)Ú_logObserver)Ú	ITestCase)ÚUncleanWarningsReporterWrapperÚ_ExitWrapper)r   r   c                 C   s2   t | tjƒsdS tj tj | j¡¡d }|dkS )z>Given an object return True if the object looks like a packageFr   Ú__init__)Ú
isinstanceÚtypesÚ
ModuleTypeÚosÚpathÚsplitextÚbasenameÚ__file__)Úmoduler(   © r+   ú6/usr/lib/python3/dist-packages/twisted/trial/runner.pyr
   8   s   r
   c                 C   s>   dd„ }|ƒ D ]}d| }t j t j | |¡¡r|  S qdS )zÓ
    Is the directory at path 'dirname' a Python package directory?
    Returns the name of the __init__ file (it may have a weird extension)
    if dirname is a package directory.  Otherwise, returns False
    c                   S   s
   t j ¡ S ©N)Ú	importlibÚ	machineryÚall_suffixesr+   r+   r+   r,   Ú_getSuffixesG   ó   
z(isPackageDirectory.<locals>._getSuffixesr!   F)r%   r&   ÚexistsÚjoin)Údirnamer1   ÚextÚinitFiler+   r+   r,   r   @   s   
ÿr   c                 C   s   t j | ¡t j |¡kS )z 
    A hacky implementation of C{os.path.samefile}. Used by L{filenameToModule}
    when the platform doesn't provide C{os.path.samefile}. Do not use this.
    )r%   r&   Úabspath)Ú	filename1Ú	filename2r+   r+   r,   r   Q   s   r   c              	   C   s  | }dt j  krdk rn ntj | ¡stj t ¡ | ¡} tj | ¡s+t|›d�ƒ‚t	 
| ¡}zt	 |¡}W n ttfyH   t| |d� Y S w t|ddƒdu rWt| |d�S tj |j¡d d }ttjd	tƒ}tj | ¡r|| |ƒst j|j= t| |d�}|S )
aV  
    Given a filename, do whatever possible to return a module object matching
    that file.

    If the file in question is a module in Python path, properly import and
    return that module. Otherwise, load the source manually.

    @param fn: A filename.
    @return: A module object.
    @raise ValueError: If C{fn} does not exist.
    )é   é   )r;   é
   z doesn't exist)Ú
moduleNamer)   Nr   z.pyr   )ÚsysÚversion_infor%   r&   Úisabsr4   Úgetcwdr3   Ú
ValueErrorr   ÚfilenameToModuleNameÚnamedAnyÚAttributeErrorÚ_importFromFileÚgetattrr'   r)   r   Úisfiler   Ú__name__)ÚfnÚoldFnr>   ÚretÚretFileÚsamer+   r+   r,   r	   Y   s&   &
þ
r	   c                C   s|   t | ƒ} |stj tj | ¡d ¡d }|tjv rtj| S tj 	|| ¡}|s+t
| ƒ‚tj |¡}|j |¡ |tj|< |S )Néÿÿÿÿr   )Ú_resolveDirectoryr%   r&   r'   Úsplitr?   r   r.   r   Úspec_from_file_locationÚSyntaxErrorÚmodule_from_specÚloaderÚexec_module)rK   r>   Úspecr*   r+   r+   r,   rG   Š   s   


rG   c                 C   s<   t j | ¡rt| ƒ}|rt j | |¡} | S t| ›d�ƒ‚| S )Nz is not a package directory)r%   r&   Úisdirr   r4   rC   )rK   r7   r+   r+   r,   rQ   š   s   ÿrQ   c                 C   sH   t | j| jtƒ ƒ| kr!t| jƒD ]}t | j|tƒ ƒ| kr |  S q| jS )zá
    Find the attribute name on the method's class which refers to the method.

    For some methods, notably decorators which have not had __name__ set correctly:

    getattr(method.im_class, method.__name__) != method
    )rH   Úim_classrJ   ÚobjectÚdir)ÚmethodÚaliasr+   r+   r,   Ú_getMethodNameInClass¤   s   ÿr_   c                   @   s   e Zd ZdZdd„ ZdS )r   zQ
    A test suite which remove the tests once run, to minimize memory usage.
    c                 C   s0   | j r|jr		 |S | j  d¡}||ƒ | j s|S )zn
        Almost the same as L{TestSuite.run}, but with C{self._tests} being
        empty at the end.
        r   )Ú_testsÚ
shouldStopÚpop)ÚselfÚresultÚtestr+   r+   r,   Úrun¸   s   þüzDestructiveTestSuite.runN)rJ   Ú
__module__Ú__qualname__Ú__doc__rf   r+   r+   r+   r,   r   ³   s    r   z<not in test>c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )r   z[
    Any errors logged in this suite will be reported to the L{TestResult}
    object.
    c                    sJ   t }| ¡  tƒ  |¡ | ¡  | ¡ D ]
}| ttƒ|¡ q| 	¡  dS )zã
        Run the suite, storing all errors in C{result}. If an error is logged
        while no tests are running, then it will be added as an error to
        C{result}.

        @param result: A L{TestResult} object.
        N)
r   Ú_addÚsuperrf   Ú_removeÚ	getErrorsÚaddErrorr   r   ÚflushErrors)rc   rd   ÚobserverÚerror©Ú	__class__r+   r,   rf   Ð   s   zLoggedSuite.run)rJ   rg   rh   ri   rf   Ú__classcell__r+   r+   rr   r,   r   Ê   s    r   c                       s2   e Zd ZdZd
‡ fdd„	Zdd„ Zdd	„ Z‡  ZS )r   zÄ
    Suite to wrap around every single test in a C{trial} run. Used internally
    by Trial to set up things necessary for Trial tests to work, regardless of
    what context they are run in.
    r+   Fc                    sF   |rg }|D ]}t  |t¡}| |¡ q|}t|ƒ}tƒ  |g¡ d S r-   )r   Údecorater   Úappendr   rk   r!   )rc   ÚtestsÚforceGarbageCollectionÚnewTestsre   Úsuiterr   r+   r,   r!   è   s   zTrialSuite.__init__c                    sH   ddl m} t ¡ ‰ | dd‡ fdd„¡ | d¡ t d¡ ˆ ¡ d S )Nr   )ÚreactorÚafterÚshutdownc                      s
   ˆ   d ¡S r-   )Úcallbackr+   ©Údr+   r,   Ú<lambda>ö   ó   
 z"TrialSuite._bail.<locals>.<lambda>Úmktemp)	Útwisted.internetr{   r   ÚDeferredÚaddSystemEventTriggerÚfireSystemEventr   ÚTestCaseÚ_wait)rc   r{   r+   r   r,   Ú_bailò   s
   
zTrialSuite._bailc                 C   s&   zt  | |¡ W |  ¡  d S |  ¡  w r-   )r   rf   rŠ   ©rc   rd   r+   r+   r,   rf   þ   s   zTrialSuite.run)r+   F)rJ   rg   rh   ri   r!   rŠ   rf   rt   r+   r+   rr   r,   r   á   s
    
r   c                 C   s@   t | ƒrt | ¡}|S z|  ¡ }W |S  ty   | j}Y |S w )z–
    @param thing: an object from modules (instance of PythonModule,
        PythonAttribute), a TestCase subclass, or an instance of a TestCase.
    )r   r   ÚqualÚidrF   r   )ÚthingÚtheNamer+   r+   r,   r     s   
	ü
þþr   c                 C   s$   zt | tjƒW S  ty   Y dS w )z�
    @return: C{True} if C{obj} is a class that contains test cases, C{False}
        otherwise. Used to find all the tests in a module.
    F)Ú
issubclassÚpyunitrˆ   Ú	TypeError)Úobjr+   r+   r,   r     s
   ÿr   c                   @   sD   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S )r   z‹
    Placeholder for a L{TestCase} inside a reporter. As far as a L{TestResult}
    is concerned, this looks exactly like a unit test.
    Nc                 C   s
   || _ dS )zM
        @param description: A string to be displayed L{TestResult}.
        N©Údescription)rc   r•   r+   r+   r,   r!   ,  s   
zTestHolder.__init__c                 C   s
   |   |¡S r-   ©rf   r‹   r+   r+   r,   Ú__call__2  r2   zTestHolder.__call__c                 C   ó   | j S r-   r”   ©rc   r+   r+   r,   r�   5  ó   zTestHolder.idc                 C   s   dS )Nr   r+   r™   r+   r+   r,   ÚcountTestCases8  s   zTestHolder.countTestCasesc                 C   s"   |  | ¡ | | ¡ | | ¡ dS )zÉ
        This test is just a placeholder. Run the test successfully.

        @param result: The C{TestResult} to store the results in.
        @type result: L{twisted.trial.itrial.IReporter}.
        N)Ú	startTestÚ
addSuccessÚstopTestr‹   r+   r+   r,   rf   ;  s   

zTestHolder.runc                 C   r˜   r-   r”   r™   r+   r+   r,   ÚshortDescriptionF  rš   zTestHolder.shortDescription)rJ   rg   rh   ri   ÚfailureExceptionr!   r—   r�   r›   rf   rŸ   r+   r+   r+   r,   r   #  s    r   c                       s6   e Zd ZdZ‡ fdd„Zdefdd„Zdd„ Z‡  ZS )	r   a  
    Used to insert arbitrary errors into a test suite run. Provides enough
    methods to look like a C{TestCase}, however, when it is run, it simply adds
    an error to the C{TestResult}. The most common use-case is for when a
    module fails to import.
    c                    s   t ƒ  |¡ t |¡| _dS )a+  
        @param description: A string used by C{TestResult}s to identify this
        error. Generally, this is the name of a module that failed to import.

        @param error: The error to be added to the result. Can be an `exc_info`
        tuple or a L{twisted.python.failure.Failure}.
        N)rk   r!   r   ÚexcInfoOrFailureToExcInforq   )rc   r•   rq   rr   r+   r,   r!   R  s   zErrorHolder.__init__Úreturnc                 C   s   d  | j| jd ¡S )Nz)<ErrorHolder description={!r} error={!r}>é   )Úformatr•   rq   r™   r+   r+   r,   Ú__repr__]  s   þzErrorHolder.__repr__c                 C   s&   |  | ¡ | | | j¡ | | ¡ dS )z°
        Run the test, reporting the error.

        @param result: The C{TestResult} to store the results in.
        @type result: L{twisted.trial.itrial.IReporter}.
        N)rœ   rn   rq   rž   r‹   r+   r+   r,   rf   c  s   
zErrorHolder.run)	rJ   rg   rh   ri   r!   Ústrr¥   rf   rt   r+   r+   rr   r,   r   J  s
    r   c                   @   s°   e Zd ZdZdZdZdd„ Zdd„ Zdd	„ Zd&dd„Z	dd„ Z
e
Zdd„ ZeZdd„ Zdd„ Zdd„ Zd&dd„Zdd„ Zd'dd„Zd&dd„ZeZd&d d!„Zd"d#„ Zd&d$d%„ZdS )(r   a4  
    I find tests inside function, modules, files -- whatever -- then return
    them wrapped inside a Test (either a L{TestSuite} or a L{TestCase}).

    @ivar methodPrefix: A string prefix. C{TestLoader} will assume that all the
    methods in a class that begin with C{methodPrefix} are test cases.

    @ivar modulePrefix: A string prefix. Every module in a package that begins
    with C{modulePrefix} is considered a module full of tests.

    @ivar forceGarbageCollection: A flag applied to each C{TestCase} loaded.
    See L{unittest.TestCase} for more information.

    @ivar sorter: A key function used to sort C{TestCase}s, test classes,
    modules and packages.

    @ivar suiteFactory: A callable which is passed a list of tests (which
    themselves may be suites of tests). Must return a test suite.
    re   Útest_c                 C   s   t | _t| _g | _d S r-   )r   ÚsuiteFactoryr   ÚsorterÚ_importErrorsr™   r+   r+   r,   r!   ‡  s   
zTestLoader.__init__c                 C   s   t || jd�S )zt
        Sort the given things using L{sorter}.

        @param xs: A list of test cases, class or modules.
        )Úkey)Úsortedr©   )rc   Úxsr+   r+   r,   ÚsortŒ  s   zTestLoader.sortc                 C   s4   g }t  |¡D ]\}}t|ƒr| |¡ q|  |¡S )z-Given a module, return all Trial test classes)ÚinspectÚ
getmembersr   rv   r®   )rc   r*   Úclassesr   Úvalr+   r+   r,   ÚfindTestClasses”  s   
€
zTestLoader.findTestClassesFc              	   C   sb  t j|v r!t |¡}zt|ƒ W n ty    | j||d� Y S w |}d } }}t|ƒD ]B\}}z
t |¡}|}W  n4 tyo   t	 
¡ d }	|	jdurU|	j}	|	jdusM|	jjj}
|
tjkr`‚ |dkrmt d|› d�¡‚Y q-w |du rŠt |¡}| d¡td |j¡ƒd d… }z|D ]
}|t||ƒ}}q�W n ty§   t|› d�ƒ‚w | j||||d	�S )
aÊ  
        Find and load tests, given C{name}.

        @param _name: The qualified name of the thing to load.
        @param recurse: A boolean. If True, inspect modules within packages
            within the given package (and so on), otherwise, only inspect
            modules in the package itself.

        @return: If C{name} is a filename, return the module. If C{name} is a
        fully-qualified Python name, return the object it refers to.
        ©ÚrecurseNé   Ú zThe module z does not exist.Ú.r£   )ÚparentÚqualNamerµ   )r%   Úsepr   rD   Ú
__import__ÚImportErrorÚloadFileÚ_qualNameWalkerÚnamedModuler?   Úexc_infoÚtb_nextÚtb_frameÚf_codeÚco_filenamer)   ÚModuleNotFoundrE   rR   ÚlenrJ   rH   rF   ÚloadAnything)rc   Ú_namerµ   r   r“   r¹   Ú	remainingÚ
searchNameÚremainingNameÚtbÚfilenameWhereHappenedÚpartr+   r+   r,   Ú
findByNameœ  sN   

þ


ÿ

ÿî
"üÿÿzTestLoader.findByNamec                 C   s¦   t |tjƒst|›d�ƒ‚t|dƒr| ¡ S t|dƒr| ¡ S |  ¡ }|  |¡D ]
}| 	|  
|¡¡ q(t|dƒs:|S |  ¡ }|jD ]
}| 	|  |¡¡ qA|  ||g¡S )aÌ  
        Return a test suite with all the tests from a module.

        Included are TestCase subclasses and doctests listed in the module's
        __doctests__ module. If that's not good for you, put a function named
        either C{testSuite} or C{test_suite} in your module that returns a
        TestSuite, and I'll use the results of that instead.

        If C{testSuite} and C{test_suite} are both present, then I'll use
        C{testSuite}.
        z is not a moduleÚ	testSuiteÚ
test_suiteÚ__doctests__)r"   r#   r$   r’   ÚhasattrrÑ   rÒ   r¨   r³   ÚaddTestÚ	loadClassrÓ   ÚloadDoctests)rc   r*   rz   Ú	testClassÚdocSuiteÚdocTestr+   r+   r,   Ú
loadModuleò  s   



zTestLoader.loadModulec                    s\   t ˆ tƒstˆ ›d�ƒ‚tˆ ƒstˆ ›d�ƒ‚ˆ ˆ ¡}ˆ ‡ ‡fdd„|D ƒ¡}ˆ |¡S )zŽ
        Given a class which contains test cases, return a list of L{TestCase}s.

        @param klass: The class to load tests from.
        z is not a classz is not a test casec                    s   g | ]}ˆ  ˆ ˆj| ¡‘qS r+   )Ú	_makeCaseÚmethodPrefix)Ú.0r   ©Úklassrc   r+   r,   Ú
<listcomp>  s    z(TestLoader.loadClass.<locals>.<listcomp>)r"   Útyper’   r   rC   ÚgetTestCaseNamesr®   r¨   )rc   rà   Únamesrw   r+   rß   r,   rÖ     s   

ÿ
zTestLoader.loadClassc                 C   s   t  || j¡S )z‚
        Given a class that contains C{TestCase}s, return a list of names of
        methods that probably contain tests.
        )r   ÚprefixedMethodNamesrÝ   )rc   rà   r+   r+   r,   rã   %  s   zTestLoader.getTestCaseNamesc                 C   s   t dƒ‚)NzCan't happen on Py3)ÚNotImplementedError)rc   r]   r+   r+   r,   Ú
loadMethod,  ó   zTestLoader.loadMethodc                 C   s   ||ƒS r-   r+   )rc   rà   Ú
methodNamer+   r+   r,   rÜ   /  rè   zTestLoader._makeCasec              	   C   sÈ   t |ƒst|›d�ƒ‚t |j¡}|r| ¡ }n| ¡ }g }|D ]}|j d¡d  	| j
¡r3| |¡ q |  ¡ }|  |¡D ]$}z| ¡ }	W n tyV   t|jt ¡ ƒ}
Y nw |  |	¡}
| |
¡ q=|S )aÔ  
        Load tests from a module object representing a package, and return a
        TestSuite containing those tests.

        Tests are only loaded from modules whose name begins with 'test_'
        (or whatever C{modulePrefix} is set to).

        @param package: a types.ModuleType object (or reasonable facsimile
        obtained by importing) which may contain tests.

        @param recurse: A boolean.  If True, inspect modules within packages
        within the given package (and so on), otherwise, only inspect modules
        in the package itself.

        @raise TypeError: If C{package} is not a package.

        @return: a TestSuite created with my suiteFactory, containing all the
        tests.
        z is not a packager¸   rP   )r
   r’   r   Ú	getModulerJ   ÚwalkModulesÚiterModulesr   rR   Ú
startswithÚmodulePrefixrv   r¨   r®   ÚloadÚBaseExceptionr   r   ÚFailurerÛ   rÕ   )rc   Úpackagerµ   ÚpkgobjÚ	discoveryÚ
discoveredÚdiscorz   Úmodinfor*   Ú
thingToAddr+   r+   r,   ÚloadPackage2  s*   

€ÿ
zTestLoader.loadPackagec                 C   sx   t |tƒrzt |¡}W n ty   t|t ¡ ƒ Y S w t 	|¡s)t
 d¡ dS i }dd„ }||d< tj|fi |¤ŽS )zŽ
        Return a suite of tests for all the doctests defined in C{module}.

        @param module: A module object or a module name.
        z&trial only supports doctesting modulesNc                 S   s    t | d| jƒ| _| j ¡ | _dS )z«
            Save C{test.globs} and replace it with a copy so that if
            necessary, the original will be available for the next test
            run.
            Ú_savedGlobalsN)rH   Úglobsrú   Úcopy)re   r+   r+   r,   ÚsaveGlobalsm  s   z,TestLoader.loadDoctests.<locals>.saveGlobalsÚsetUp)r"   r¦   r   rE   rð   r   r   rñ   r¯   ÚismoduleÚwarningsÚwarnÚdoctestÚDocTestSuite)rc   r*   Ú	extraArgsrý   r+   r+   r,   r×   \  s   
ÿ

	zTestLoader.loadDoctestsNc                 C   s´   t |tjƒrt|ƒr| j||d�S |  |¡S t |tƒr&t|tj	ƒr&|  
|¡S t |tjƒrLt |tƒrLt|tj	ƒrL|d }||ƒ}t||jƒj|ksJJ ‚|S t |tƒrS|S td|› �ƒ‚)aÏ  
        Load absolutely anything (as long as that anything is a module,
        package, class, or method (with associated parent class and qualname).

        @param obj: The object to load.
        @param recurse: A boolean. If True, inspect modules within packages
            within the given package (and so on), otherwise, only inspect
            modules in the package itself.
        @param parent: If C{obj} is a method, this is the parent class of the
            method. C{qualName} is also required.
        @param qualName: If C{obj} is a method, this a list containing is the
            qualified name of the method. C{parent} is also required.

        @return: A C{TestCase} or C{TestSuite}.
        r´   rP   z"don't know how to make test from: )r"   r#   r$   r
   rù   ÚloadTestsFromModulerâ   r�   r‘   rˆ   ÚloadTestsFromTestCaseÚFunctionTyperH   Ú_testMethodNameÚ__func__r   r’   )rc   r“   rµ   r¹   rº   r   Úinstr+   r+   r,   rÈ   y  s&   


ÿþ
ý
zTestLoader.loadAnythingc              	   C   sB   z|   | j||d�g¡W S  ty    |   t|t ¡ ƒg¡ Y S w )a*  
        Load some tests by name.

        @param name: The qualified name for the test to load.
        @param recurse: A boolean. If True, inspect modules within packages
            within the given package (and so on), otherwise, only inspect
            modules in the package itself.
        r´   )r¨   rÐ   rð   r   r   rñ   )rc   r   rµ   r+   r+   r,   Ú
loadByName©  s
   	ÿzTestLoader.loadByNamec              
   C   sj   g }g }|D ]!}z|  | j||d�¡ W q ty'   |  t|t ¡ ƒ¡ Y qw | |¡ |  |  |¡¡S )a+  
        Load some tests by a list of names.

        @param names: A L{list} of qualified names.
        @param recurse: A boolean. If True, inspect modules within packages
            within the given package (and so on), otherwise, only inspect
            modules in the package itself.
        r´   )	rv   r  rð   r   r   rñ   Úextendr¨   Ú_uniqueTests)rc   rä   rµ   ÚthingsÚerrorsr   r+   r+   r,   ÚloadByNames¹  s   	ÿ
zTestLoader.loadByNamesc                 c   sF   � t ƒ }|D ]}|j}|D ]}t|ƒ|vr|V  | t|ƒ¡ qqdS )a  
        Gather unique suite objects from loaded things. This will guarantee
        uniqueness of inherited methods on TestCases which would otherwise hash
        to same value and collapse to one test unexpectedly if using simpler
        means: e.g. set().
        N)Úsetr`   r¦   Úadd)rc   r  ÚseenÚ	testthingÚ
testthingsrŽ   r+   r+   r,   r  Ì  s   €€üþzTestLoader._uniqueTestsc                 C   sF   t  |¡}zt||ƒ ¡ }| j||d�W S  ty"   t|› d�ƒ‚w )a1  
        Load a file, and then the tests in that file.

        @param fileName: The file name to load.
        @param recurse: A boolean. If True, inspect modules within packages
            within the given package (and so on), otherwise, only inspect
            modules in the package itself.
        r´   z is not a Python file.)r   rD   r   Úload_modulerÈ   ÚOSErrorrC   )rc   ÚfileNamerµ   r   r*   r+   r+   r,   r¾   Ü  s   
	ÿzTestLoader.loadFile©F)FNN)rJ   rg   rh   ri   rÝ   rî   r!   r®   r³   rÐ   rÛ   r  rÖ   r  rã   rç   rÜ   rù   r×   rÈ   r  ÚloadTestsFromNamer  r  r¾   r+   r+   r+   r,   r   o  s.    
V
*

0
r   c                 c   sR   � | g fV  |   d¡}tdt|ƒƒD ]}d |d| … ¡|| d… fV  qdS )a3  
    Given a Python qualified name, this function yields a 2-tuple of the most
    specific qualified name first, followed by the next-most-specific qualified
    name, and so on, paired with the remainder of the qualified name.

    @param qualName: A Python qualified name.
    @type qualName: L{str}
    r¸   r£   N)rR   ÚrangerÇ   r4   )rº   Ú	qualPartsÚindexr+   r+   r,   r¿   í  s   €


&ür¿   c                   @   s€   e Zd ZdZdZdZdd„ Zdd„ ZeZ	dd	„ Z
d
dejddddd
dd
dfdd„Zdd„ Zdd„ Zdd„ Zddd„Zdd„ Zd
S )r   z=
    A specialised runner that the trial front end uses.
    Údebugzdry-runc                 C   s<   |   ¡  t ¡ }t | j¡}t |¡\}| _t 	|j
¡ |S r-   )Ú_tearDownLogFiler%   rB   r   ÚFilePathÚworkingDirectoryr   Ú_unusedTestDirectoryÚ_testDirLockÚchdirr&   )rc   Ú
currentDirÚbaseÚtestdirr+   r+   r,   Ú_setUpTestdir  s   zTrialRunner._setUpTestdirc                 C   s   t  |¡ | j ¡  d S r-   )r%   r$  r#  Úunlock)rc   ÚoldDirr+   r+   r,   Ú_tearDownTestdir  s   
zTrialRunner._tearDownTestdirc                 C   s8   |   | j| j| j| j¡}| jrt|ƒ}| jrt|ƒ}|S r-   )	ÚreporterFactoryÚstreamÚtbformatÚrterrorsÚ_logÚ
_exitFirstr    ÚuncleanWarningsr   )rc   Úreporterr+   r+   r,   Ú_makeResult  s   ÿzTrialRunner._makeResultNztest.logFÚdefaultc                 C   st   || _ || _|| _|| _|| _|| _|| _d | _|	pd| _d | _	d | _
|
| _|| _|| _|r8t | jd¡| _d S d S )NÚ_trial_tempzprofile.data)r,  ÚlogfileÚmoder-  r.  r/  r2  Ú_resultr!  Ú_logFileObserverÚ_logFileObjectÚ_forceGarbageCollectionÚdebuggerr1  r   Úprofiledrf   )rc   r,  r8  r7  r-  ÚprofileÚtracebackFormatÚrealTimeErrorsr2  r!  rx   r=  Ú	exitFirstr+   r+   r,   r!   #  s"   
ÿzTrialRunner.__init__c                 C   s@   | j d urt | j j¡ d | _ | jd ur| j ¡  d | _d S d S r-   )r:  r   ÚremoveObserverÚemitr;  Úcloser™   r+   r+   r,   r  C  s   



þzTrialRunner._tearDownLogFilec                 C   sL   |   ¡  | jdkrtj}nt| jdƒ}|| _t |¡| _t 	| jj
d¡ d S )Nú-Úar   )r  r7  r?   ÚstdoutÚopenr;  r   ÚFileLogObserverr:  ÚstartLoggingWithObserverrD  )rc   ÚlogFiler+   r+   r,   Ú_setUpLogFileK  s   
zTrialRunner._setUpLogFilec                 C   s   t  |t¡}|  || j¡S )zC
        Run the test or suite and return a result object.
        )r   ru   r   Ú_runWithoutDecorationr<  )rc   re   r+   r+   r,   rf   U  s   zTrialRunner.runc           	   	      sF  ˆ  ¡ ‰ t|g|ƒ‰t ¡ }ˆjˆjkr+tˆƒD ]}ˆ  |¡ ˆ  |¡ ˆ  |¡ qn7ˆjˆj	kr:‡ ‡‡fdd„}n‡ ‡fdd„}ˆ 
¡ }zˆ ¡  |ƒ  W ˆ ¡  ˆ |¡ n
ˆ ¡  ˆ |¡ w t ¡ }tˆ ddƒ}|du r�tjdt ˆ j¡ tdd� ˆ  ¡  ˆ  ˆ j¡ ˆ  d	ˆ j|| ¡ ˆ  d
¡ ˆ  ¡  ˆ S ˆ  ¡  ˆ S )zR
        Private helper that runs the given test but doesn't decorate it.
        c                      s   ˆj  ˆjˆ ¡S r-   )r=  Úruncallrf   r+   ©rd   rc   rz   r+   r,   r�   m  s    z3TrialRunner._runWithoutDecoration.<locals>.<lambda>c                      s
   ˆ  ˆ ¡S r-   r–   r+   )rd   rz   r+   r,   r�   o  r‚   ÚdoneNzR%s should implement done() but doesn't. Falling back to printErrors() and friends.r;   )ÚcategoryÚ
stacklevelzRan %d tests in %.3fsÚ
)r4  r   Útimer8  ÚDRY_RUNr   rœ   r�   rž   ÚDEBUGr(  rM  r  r+  rH   r   r  r   rŒ   rs   ÚDeprecationWarningÚprintErrorsÚwritelnÚ	separatorÚtestsRunÚwriteÚprintSummaryrQ  )	rc   re   rx   Ú	startTimeÚsinglerf   r*  ÚendTimerQ  r+   rP  r,   rN  \  sP   

ýÿ
ÿüÿ
ÿz!TrialRunner._runWithoutDecorationc                 C   s^   d}	 |d7 }| j  d|f ¡ |dkr|  |¡}n|  |¡}|jdkr'	 |S | ¡ s.	 |S q)z8
        Repeatedly run C{test} until it fails.
        r   Tr£   zTest Pass %d
)r-  r]  rf   rN  r\  ÚwasSuccessful)rc   re   Úcountrd   r+   r+   r,   ÚrunUntilFailure�  s   

þõzTrialRunner.runUntilFailurer  )rJ   rg   rh   ri   rW  rV  r(  r+  r   r0  r4  r?   rH  r!   r  rM  rf   rN  rd  r+   r+   r+   r,   r     s2    
ó 

1r   )9ri   Ú__all__r  r.   r¯   r%   r?   rU  r#   r   Úimportlib.machineryr   Úzope.interfacer   r„   r   Útwisted.pythonr   r   r   r   r   Útwisted.trialr   r   Útwisted.trial._asyncrunnerr   r   Útwisted.trial._synctestr   Útwisted.trial.itrialr   Útwisted.trial.reporterr   r    Útwisted.trial.unittestr   r¼   r‘   r
   r   r   r	   rG   rQ   r_   r   r   r   r   r   r   r   r   r   r¿   r   r+   r+   r+   r,   Ú<module>   sV   1
$&%   