Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/twisted/trial/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/twisted/trial/__pycache__/runner.cpython-310.pyc
o

�b�|�@s�dZgd�ZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
ddlmZddlmZmZmZmZmZddlmZmZdd	lmZmZdd
lmZddlmZddl m!Z!m"Z"dd
l#m$Z$e%d�Z&dd�Z'dd�Z(dd�Z)dd�Z*dd�Z+dd�Z,dd�Z-Gdd�de$�Z.dZ/Gd d!�d!e$�Z0Gd"d#�d#e$�Z1d$d%�Z2d&d'�Z3e
e�Gd(d)�d)��Z4Gd*d+�d+e4�Z5Gd,d-�d-�Z6d.d/�Z7Gd0d1�d1�Z8dS)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)rrcCs2t|tj�sdStj�tj�|j��d}|dkS)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
8sr
cCs>dd�}|�D]}d|}tj�tj�||��r|SqdS)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
    cSs
tj��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
�rcCstj�|�tj�|�kS)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,rQsrc	Cs|}dtjkr
dkrnntj�|�stj�t��|�}tj�|�s+t|�d���t	�
|�}zt	�|�}WnttfyHt
||d�YSwt|dd�durWt
||d�Stj�|j�dd}ttjd	t�}tj�|�r|||�stj|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)Nrz.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	Ys&&
�
r	cCs|t|�}|stj�tj�|�d�d}|tjvrtj|Stj�	||�}|s+t
|��tj�|�}|j�
|�|tj|<|S)N���r)�_resolveDirectoryr%r&r'�splitr?rr.r�spec_from_file_location�SyntaxError�module_from_spec�loader�exec_module)rKr>�specr*r+r+r,rG�s


rGcCs<tj�|�rt|�}|rtj�||�}|St|�d���|S)Nz is not a package directory)r%r&�isdirrr4rC)rKr7r+r+r,rQ�s�rQcCsHt|j|jt��|kr!t|j�D]}t|j|t��|kr |Sq|jS)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@seZdZdZdd�ZdS)rzQ
    A test suite which remove the tests once run, to minimize memory usage.
    cCs0|jr|jr		|S|j�d�}||�|js|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��zDestructiveTestSuite.runN)rJ�
__module__�__qualname__�__doc__rfr+r+r+r,r�srz
<not in test>cs eZdZdZ�fdd�Z�ZS)rz[
    Any errors logged in this suite will be reported to the L{TestResult}
    object.
    csJt}|��t��|�|��|��D]
}|�tt�|�q|�	�dS)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�addErrorrr�flushErrors)rcrd�observer�error��	__class__r+r,rf�szLoggedSuite.run)rJrgrhrirf�
__classcell__r+r+rrr,r�srcs2eZdZdZd
�fdd�	Zdd�Zdd	�Z�ZS)rz�
    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+FcsF|rg}|D]
}t�|t�}|�|�q|}t|�}t��|g�dSr-)r�decorater�appendrrkr!)rc�tests�forceGarbageCollection�newTestsre�suiterrr+r,r!�szTrialSuite.__init__csHddlm}t���|�dd�fdd��|�d�t�d����dS)Nr)�reactor�after�shutdowncs
��d�Sr-)�callbackr+��dr+r,�<lambda>��
z"TrialSuite._bail.<locals>.<lambda>�mktemp)	�twisted.internetr{r�Deferred�addSystemEventTrigger�fireSystemEventr�TestCase�_wait)rcr{r+rr,�_bail�s

zTrialSuite._bailcCs&z
t�||�W|��dS|��wr-)rrfr��rcrdr+r+r,rf�szTrialSuite.run)r+F)rJrgrhrir!r�rfrtr+r+rrr,r�s

rcCs@t|�rt�|�}|Sz|��}W|Sty|j}Y|Sw)z�
    @param thing: an object from modules (instance of PythonModule,
        PythonAttribute), a TestCase subclass, or an instance of a TestCase.
    )rr�qual�idrFr
)�thing�theNamer+r+r,r
s
	�
��r
cCs$zt|tj�WStyYdSw)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@sDeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)rz�
    Placeholder for a L{TestCase} inside a reporter. As far as a L{TestResult}
    is concerned, this looks exactly like a unit test.
    NcCs
||_dS)zM
        @param description: A string to be displayed L{TestResult}.
        N��description)rcr�r+r+r,r!,s
zTestHolder.__init__cCs
|�|�Sr-�rfr�r+r+r,�__call__2r2zTestHolder.__call__cC�|jSr-r��rcr+r+r,r�5�z
TestHolder.idcCsdS)Nrr+r�r+r+r,�countTestCases8szTestHolder.countTestCasescCs"|�|�|�|�|�|�dS)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

zTestHolder.runcCr�r-r�r�r+r+r,�shortDescriptionFr�zTestHolder.shortDescription)rJrgrhri�failureExceptionr!r�r�r�rfr�r+r+r+r,r#srcs6eZdZdZ�fdd�Zdefdd�Zdd�Z�ZS)	ra
    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.
    cst��|�t�|�|_dS)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)rkr!r�excInfoOrFailureToExcInforq)rcr�rqrrr+r,r!RszErrorHolder.__init__�returncCsd�|j|jd�S)Nz)<ErrorHolder description={!r} error={!r}>�)�formatr�rqr�r+r+r,�__repr__]s�zErrorHolder.__repr__cCs&|�|�|�||j�|�|�dS)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�rnrqr�r�r+r+r,rfcs
zErrorHolder.run)	rJrgrhrir!�strr�rfrtr+r+rrr,rJs
rc@s�eZdZdZdZdZdd�Zdd�Zdd	�Zd&dd�Z	d
d�Z
e
Zdd�ZeZ
dd�Zdd�Zdd�Zd&dd�Zdd�Zd'dd�Zd&dd�ZeZd&d d!�Zd"d#�Zd&d$d%�ZdS)(ra4
    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_cCst|_t|_g|_dSr-)r�suiteFactoryr
�sorter�
_importErrorsr�r+r+r,r!�s
zTestLoader.__init__cCst||jd�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�szTestLoader.sortcCs4g}t�|�D]
\}}t|�r|�|�q|�|�S)z-Given a module, return all Trial test classes)�inspect�
getmembersrrvr�)rcr*�classesr
�valr+r+r,�findTestClasses�s
�
zTestLoader.findTestClassesFc	Csbtj|vr!t�|�}zt|�Wnty |j||d�YSw|}d}}}t|�D]B\}}z
t�|�}|}Wn4tyot	�
�d}	|	jdurU|	j}	|	jdusM|	jj
j}
|
tjkr`�|dkrmt�d|�d���Yq-w|dur�t�|�}|�d�td�|j��dd�}z|D]
}|t||�}}q�Wnty�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��zThe module z does not exist.�.r�)�parent�qualNamer�)r%�seprrD�
__import__�ImportError�loadFile�_qualNameWalker�namedModuler?�exc_info�tb_next�tb_frame�f_code�co_filenamer)�ModuleNotFoundrErR�lenrJrHrF�loadAnything)rc�_namer�r
r�r��	remaining�
searchName�
remainingName�tb�filenameWhereHappened�partr+r+r,�
findByName�sN

�


�

��
"���zTestLoader.findByNamecCs�t|tj�s
t|�d���t|d�r|��St|d�r|��S|��}|�|�D]
}|�	|�
|��q(t|d�s:|S|��}|jD]
}|�	|�|��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)rcr*rz�	testClass�docSuite�docTestr+r+r,�
loadModule�s



zTestLoader.loadModulecs\t�t�st��d���t��st��d�������}����fdd�|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 casecsg|]}����j|��qSr+)�	_makeCase�methodPrefix)�.0r
��klassrcr+r,�
<listcomp>sz(TestLoader.loadClass.<locals>.<listcomp>)r"�typer�rrC�getTestCaseNamesr�r�)rcr��namesrwr+r�r,r�s

�
zTestLoader.loadClasscCst�||j�S)z�
        Given a class that contains C{TestCase}s, return a list of names of
        methods that probably contain tests.
        )r�prefixedMethodNamesr�)rcr�r+r+r,r�%szTestLoader.getTestCaseNamescCstd��)NzCan't happen on Py3)�NotImplementedError)rcr]r+r+r,�
loadMethod,�zTestLoader.loadMethodcCs||�Sr-r+)rcr��
methodNamer+r+r,r�/r�zTestLoader._makeCasec	Cs�t|�st|�d���t�|j�}|r|��}n|��}g}|D]}|j�d�d�	|j
�r3|�|�q |��}|�
|�D]$}z|��}	WntyVt|jt���}
Ynw|�|	�}
|�|
�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�modulePrefixrvr�r��load�
BaseExceptionrr�Failurer�r�)rc�packager��pkgobj�	discovery�
discovered�discorz�modinfor*�
thingToAddr+r+r,�loadPackage2s*

��
zTestLoader.loadPackagecCsxt|t�rzt�|�}Wntyt|t���YSwt�	|�s)t
�d�dSi}dd�}||d<tj
|fi|��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 modulesNcSs t|d|j�|_|j��|_dS)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)rer+r+r,�saveGlobalsmsz,TestLoader.loadDoctests.<locals>.saveGlobals�setUp)r"r�rrEr�rrr�r��ismodule�warnings�warn�doctest�DocTestSuite)rcr*�	extraArgsr�r+r+r,r�\s
�

	zTestLoader.loadDoctestsNcCs�t|tj�rt|�r|j||d�S|�|�St|t�r&t|tj	�r&|�
|�St|tj�rLt|t�rLt|tj	�rL|d}||�}t||j
�j|ksJJ�|St|t�rS|Std|����)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�rPz"don't know how to make test from: )r"r#r$r
r��loadTestsFromModuler�r�r�r��loadTestsFromTestCase�FunctionTyperH�_testMethodName�__func__rr�)rcr�r�r�r�r
�instr+r+r,r�ys&


��
�
zTestLoader.loadAnythingc	CsBz|�|j||d�g�WSty |�t|t���g�YSw)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�rrr�)rcr
r�r+r+r,�
loadByName�s
	�zTestLoader.loadByNamec
Csjg}g}|D]!}z|�|j||d��Wqty'|�t|t����Yqw|�|�|�|�|��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�)	rvrr�rrr��extendr��_uniqueTests)rcr�r��things�errorsr
r+r+r,�loadByNames�s	�
zTestLoader.loadByNamesccsF�t�}|D]}|j}|D]}t|�|vr|V|�t|��q
qdS)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)rcr�seen�	testthing�
testthingsr�r+r+r,r
�s����zTestLoader._uniqueTestscCsFt�|�}zt||���}|j||d�WSty"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.)rrDr�load_moduler��OSErrorrC)rc�fileNamer�r
r*r+r+r,r��s
	�zTestLoader.loadFile�F)FNN)rJrgrhrir�r�r!r�r�r�r�rr�rr�r�r�r�r�r�r�loadTestsFromNamerr
r�r+r+r+r,ros.
V
*

0
rccsR�|gfV|�d�}tdt|��D]}d�|d|��||d�fVqdS)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�eZdZdZdZdZdd�Zdd�ZeZ	dd	�Z
d
dejdd
ddd
dd
dfdd�Z
dd�Zdd�Zdd�Zddd�Zdd�Zd
S)rz=
    A specialised runner that the trial front end uses.
    �debugzdry-runcCs<|��t��}t�|j�}t�|�\}|_t�	|j
�|Sr-)�_tearDownLogFiler%rBr�FilePath�workingDirectoryr�_unusedTestDirectory�_testDirLock�chdirr&)rc�
currentDir�base�testdirr+r+r,�
_setUpTestdirszTrialRunner._setUpTestdircCst�|�|j��dSr-)r%r$r#�unlock)rc�oldDirr+r+r,�_tearDownTestdirs
zTrialRunner._tearDownTestdircCs8|�|j|j|j|j�}|jrt|�}|jrt|�}|Sr-)	�reporterFactory�stream�tbformat�rterrors�_log�
_exitFirstr �uncleanWarningsr)rc�reporterr+r+r,�_makeResults�zTrialRunner._makeResultNztest.logF�defaultc

Cst||_||_||_||_||_||_||_d|_|	pd|_d|_	d|_
|
|_||_||_
|r8t�|jd�|_dSdS)N�_trial_tempzprofile.data)r,�logfile�moder-r.r/r2�_resultr!�_logFileObserver�_logFileObject�_forceGarbageCollection�debuggerr1r�profiledrf)
rcr,r8r7r-�profile�tracebackFormat�realTimeErrorsr2r!rxr=�	exitFirstr+r+r,r!#s"
�zTrialRunner.__init__cCs@|jdurt�|jj�d|_|jdur|j��d|_dSdSr-)r:r�removeObserver�emitr;�closer�r+r+r,rCs



�zTrialRunner._tearDownLogFilecCsL|��|jdkr
tj}nt|jd�}||_t�|�|_t�	|jj
d�dS)N�-�ar)rr7r?�stdout�openr;r�FileLogObserverr:�startLoggingWithObserverrD)rc�logFiler+r+r,�
_setUpLogFileKs
zTrialRunner._setUpLogFilecCst�|t�}|�||j�S)zC
        Run the test or suite and return a result object.
        )rrur�_runWithoutDecorationr<)rcrer+r+r,rfUszTrialRunner.runc		sF����t|g|��t��}�j�jkr+t��D]}��|���|���|�qn7�j�j	kr:���fdd�}n��fdd�}��
�}z���|�W�����
|�n
�����
|�wt��}t�dd�}|dur�tjdt��j�tdd�������j���d	�j||���d
�����S����S)zR
        Private helper that runs the given test but doesn't decorate it.
        cs�j��j��Sr-)r=�runcallrfr+�rdrcrzr+r,r�msz3TrialRunner._runWithoutDecoration.<locals>.<lambda>cs
����Sr-r�r+)rdrzr+r,r�or��doneNzR%s should implement done() but doesn't. Falling back to printErrors() and friends.r;)�category�
stacklevelzRan %d tests in %.3fs�
)r4r�timer8�DRY_RUNrr�r�r��DEBUGr(rMrr+rHrrrr�rs�DeprecationWarning�printErrors�writeln�	separator�testsRun�write�printSummaryrQ)	rcrerx�	startTime�singlerfr*�endTimerQr+rPr,rN\sP

��
���
�z!TrialRunner._runWithoutDecorationcCs^d}	|d7}|j�d|f�|dkr|�|�}n|�|�}|jdkr'	|S|��s.	|Sq)z8
        Repeatedly run C{test} until it fails.
        rTr�z
Test Pass %d
)r-r]rfrNr\�
wasSuccessful)rcre�countrdr+r+r,�runUntilFailure�s

��zTrialRunner.runUntilFailurer)rJrgrhrirWrVr(r+rr0r4r?rHr!rrMrfrNrdr+r+r+r,rs2

� 

1r)9ri�__all__rr.r�r%r?rUr#r�importlib.machineryr�zope.interfacerr�r�twisted.pythonrrrrr�
twisted.trialrr�twisted.trial._asyncrunnerrr�twisted.trial._synctestr�twisted.trial.itrialr�twisted.trial.reporterrr �twisted.trial.unittestrr�r�r
rrr	rGrQr_rrrrr
rrrrr�rr+r+r+r,�<module>sV1
$&%

Spamworldpro Mini