HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/trial/test/__pycache__/test_loader.cpython-38.pyc
U


W[�e�@s�dZddlmZmZddlZddlZddlZddlm	Z	ddl
mZmZddl
mZddlmZmZmZddlmZdd	lmZdd
lmZddlmZdd
�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�de�Z Gdd�dej�Z!dS)z"
Tests for loading tests by name.
�)�absolute_import�divisionN)�md5)�util�filepath)�packages)�runner�reporter�unittest)�	ITestCase)�
_iterateTests)�	getModule)�_PY3cCs$g}t|�D]}|�|���q|S)zI
    Return the id of each test within the given test suite or case.
    )r�append�id)Ztests�names�test�r�@/usr/lib/python3/dist-packages/twisted/trial/test/test_loader.py�	testNamessrc@sxeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e
r\dZee_ee_ee_ee	_dd�Z
dd�Zdd�ZdS)�FinderTestsz4
    Tests for L{runner.TestLoader.findByName}.
    cCstj�|�t��|_dS�N)r�PackageTest�setUpr�
TestLoader�loader��selfrrrr*szFinderTests.setUpcCstj�|�dSr)rr�tearDownrrrrr.szFinderTests.tearDowncCs$|j�d�}ddl}|�||�dS)N�twistedr)r�
findByNamer�assertEqual�r�sample1�sample2rrr�test_findPackage1szFinderTests.test_findPackagecCs(|j�d�}ddlm}|�||�dS)N�twisted.trial.test.sampler��sample)rr �twisted.trial.testr(r!r"rrr�test_findModule6szFinderTests.test_findModulecCs4t�td�}|j�|�}ddlm}|�||�dS)N�	sample.pyrr')r�sibpath�__file__rr r)r(r!)r�pathr#r$rrr�
test_findFile;szFinderTests.test_findFilecCs*|j�d�}ddlm}|�|j|�dS)N�!twisted.trial.test.sample.FooTestrr')rr r)r(r!�FooTest)rr#r(rrr�test_findObjectAszFinderTests.test_findObjectzNot relevant on Python 3cCs|�t|jjd�dS)Nztwisted.trial.test.nonexistent)�assertRaises�AttributeErrorrr rrrr�test_findNonModuleQs�zFinderTests.test_findNonModulecCs|�t|jjd�dS)NZ	nonextant)r3�
ValueErrorrr rrrr�test_findNonPackageVs�zFinderTests.test_findNonPackagecCs"t�td�}|�t|jj|�dS)Nznonexistent.py)rr,r-r3r6rr )rr.rrr�test_findNonFile[szFinderTests.test_findNonFileN)�__name__�
__module__�__qualname__�__doc__rrr%r*r/r2rZ_Py3SkipMsg�skipr5r7r8rrrrr&s rc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�	FileTestsz/
    Tests for L{runner.filenameToModule}.
    cCs$|�ttjd�}|�t|�d�dS)zo
        L{runner.filenameToModule} raises a C{ValueError} when a non-existing
        file is passed.
        �itz'it' doesn't existN)r3r6r�filenameToModuler!�str)r�errrrr�test_notFileeszFileTests.test_notFilecCs.t�t�td��}ddlm}|�||�dS)z�
        If the file in question is a module on the Python path, then it should
        properly import and return that module.
        r+rr'N)rr@rr,r-r)r(r!r"rrr�test_moduleInPathnszFileTests.test_moduleInPathcCsz|�tjjdd�|�|j�t�tj	�
|jdd��}|�|j�ddl
m}|�tj	�|j�dtj	�|j�d�dS)a
        If passed the path to a file containing the implementation of a
        module within a package which is not on the import path,
        L{runner.filenameToModule} returns a module object loosely
        resembling the module defined by that file anyway.
        �test_sampleN�goodpackageztest_sample.pyr)rE)�
addCleanup�sys�modules�pop�
mangleSysPath�oldPathrr@�osr.�join�parent�newPathrFrEr!�splitextr-r"rrr�test_moduleNotInPathxs��zFileTests.test_moduleNotInPathcCs.t�tj�|jd��}ddl}|�||�dS)z�
        If the file in question is a package on the Python path, then it should
        properly import and return that package.
        rFrN)rr@rMr.rNrOrFr!�rZpackage1rFrrr�test_packageInPath�s
�zFileTests.test_packageInPathcCsr|�tjjd�|�|j�t�tj	�
|jd��}|�|j�ddl
}|�tj	�|j�dtj	�|j�d�dS)z�
        If passed the path to a directory which represents a package which
        is not on the import path, L{runner.filenameToModule} returns a
        module object loosely resembling the package defined by that
        directory anyway.
        �__init__rFrN)rGrHrIrJrKrLrr@rMr.rNrOrPrFr!rQr-rSrrr�test_packageNotInPath�s��zFileTests.test_packageNotInPathcCsHt�|j��d�}|��|�ttj|j	�}|�
t|�d|j	f�dS)z�
        L{runner.filenameToModule} raises a C{ValueError} when the name of an
        empty directory is passed that isn't considered a valid Python package
        because it doesn't contain a C{__init__.py} file.
        ZemptyDirectoryz%r is not a package directoryN)r�FilePathrO�child�createDirectoryr3r6rr@r.r!rA)rZemptyDirrBrrr�test_directoryNotPackage�s
��z"FileTests.test_directoryNotPackagecCs2t�|j��d�}|�d�|�ttj|j	�dS)zn
        L{runner.filenameToModule} raises a C{SyntaxError} when a non-Python
        file is passed.
        Z	notpythonsThis isn't pythonN)
rrWrOrX�
setContentr3�SyntaxErrorrr@r.)r�filenamerrr�test_filenameNotPython�s
�z FileTests.test_filenameNotPythoncCsTt�|j��d�}|�tj�d��z t	�
|j�}|�|j|j
�W5|��XdS)zX
        The C{__file__} attribute of the module should match the package name.
        zgoodpackage.py�utf8N)rrWrOrXr[r�
testModule�encode�removerr@r.r!r-)rr]�modulerrr�test_filenameMatchesPackage�sz%FileTests.test_filenameMatchesPackagecCs�t�|j��d�}|��|�d��d�zHt�|j	�}|�
|j�d��t�|j	t
j	j�}|�
|j�d��W5|��XdS)z�
        Test loader against a filesystem directory containing an empty
        C{__init__.py} file. It should handle 'path' and 'path/' the same way.
        Z
goodDirectory�__init__.py�N)rrWrOrXrYr[rbrr@r.�
assertTruer9�endswithrM�sep)rZgoodDirrcrrr�test_directory�szFileTests.test_directoryN)
r9r:r;r<rCrDrRrTrVrZr^rdrjrrrrr>as	
r>c@sLeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&e'�rHdHZ(e(e_)e(e	_)e(e_)e(e_)[(dIS)J�LoaderTestsz(
    Tests for L{trial.TestLoader}.
    cCst��|_tj�|�dSr)rrrr�SysPathManglingTestrrrrrr�s
zLoaderTests.setUpcs�ddlm}|j�|j�}|�dddgdd�|jD��dddg}tt|t	d�����fd	d
�|j_
|j�|j�}|�|dd�|jD��dS)Nrr'Ztest_aZtest_bZtest_ccSsg|]
}|j�qSr��_testMethodName��.0rrrr�
<listcomp>�sz.LoaderTests.test_sortCases.<locals>.<listcomp>�cs��|��d�S)N���)�getZshortDescription)�x�ZsortDictrr�<lambda>�rfz,LoaderTests.test_sortCases.<locals>.<lambda>cSsg|]
}|j�qSrrmrorrrrq�s)r)r(r�	loadClassZAlphabetTestr!�_tests�dict�zip�range�sorter)rr(�suiteZnewOrderrrvr�test_sortCases�s�
�zLoaderTests.test_sortCasescCs>ddlm}|j�|jj�}|�d|���|�d|j�dS)Nrr'��test_foo)	r)r(r�
loadMethodr1r�r!�countTestCasesrn�rr(r~rrr�test_loadMethodszLoaderTests.test_loadMethodcCsRddlm}|j�|jj�}t��}|�|�|�	|j
d�|�	t|j�d�dS)Nr)�	erroneousr�)
r)r�rr�ZTestRegularFailZ	test_failr	�
TestResult�runr!�testsRun�len�failures)rr�r~�resultrrr�test_loadFailingMethod	s
z"LoaderTests.test_loadFailingMethodcCsB|j�d�}t��}|�|�|�|jd�|�t|j�d�dS)z{
        Loading a test that fails and getting the result of it ends up with one
        test ran and one failure.
        z6twisted.trial.test.erroneous.TestRegularFail.test_failr�N)	r�
loadByNamer	r�r�r!r�r�r�)rr~r�rrr�test_loadFailures�
zLoaderTests.test_loadFailurecCsZddlm}|�t|jj|�|�t|jj|j�|�t|jjd�|�t|jjd�dS�Nrr'�string)ZfooZbar)r)r(r3�	TypeErrorrr�r1�rr(rrr�test_loadNonMethod s��zLoaderTests.test_loadNonMethodcCsLddlm}|jj|jj|jdddgd�}|�d|���|�d|j�dS)	z�
        A decorated test method for which the decorator has failed to set the
        method's __name__ correctly is loaded and its name in the class scope
        discovered.
        rr'r(�DecorationTest�test_badDecorator�rOZqualNamer�N)	r)r(r�loadAnythingr�r�r!r�rnr�rrr�test_loadBadDecorator*s�z!LoaderTests.test_loadBadDecoratorcCsLddlm}|jj|jj|jdddgd�}|�d|���|�d|j�dS)	z�
        A decorated test method for which the decorator has set the method's
        __name__ correctly is loaded and the only name by which it goes is used.
        rr'r(r��test_goodDecoratorr�r�N)	r)r(rr�r�r�r!r�rnr�rrr�test_loadGoodDecorator9s�z"LoaderTests.test_loadGoodDecoratorcCsLddlm}|jj|jj|jdddgd�}|�d|���|�d|j�dS)	z�
        Load a decorated method which has been copied to a new name inside the
        class.  Thus its __name__ and its key in the class's __dict__ no
        longer match.
        rr'r(r��test_renamedDecoratorr�r�N)	r)r(rr�r�r�r!r�rnr�rrr�test_loadRenamedDecoratorGs�z%LoaderTests.test_loadRenamedDecoratorcCsJddlm}|j�|j�}|�d|���|�ddgdd�|jD��dS)Nrr'�Ztest_barr�cSsg|]
}|j�qSrrmrorrrrq[sz.LoaderTests.test_loadClass.<locals>.<listcomp>)r)r(rrxr1r!r�ryr�rrr�test_loadClassVs
�zLoaderTests.test_loadClasscCs\ddlm}|�t|jj|�|�t|jj|jj�|�t|jjd�|�t|jjd�dSr�)r)r(r3r�rrxr1r�r�rrr�test_loadNonClass^s��zLoaderTests.test_loadNonClasscCs$ddlm}|�t|jj|j�dS�Nrr')r)r(r3r6rrxZNotATestr�rrr�test_loadNonTestCasehs�z LoaderTests.test_loadNonTestCasecCs,ddlm}|j�|�}|�d|���dS)Nrr'�
)r)r(r�
loadModuler!r�r�rrr�test_loadModulenszLoaderTests.test_loadModulecCs^ddlm}|�t|jj|j�|�t|jj|jj�|�t|jjd�|�t|jjd�dSr�)r)r(r3r�rr�r1r�r�rrr�test_loadNonModulets���zLoaderTests.test_loadNonModulecCs(ddl}|j�|�}|�d|���dS�Nr��rFr�loadPackager!r��rrFr~rrr�test_loadPackageszLoaderTests.test_loadPackagecCs^ddlm}|�t|jj|j�|�t|jj|jj�|�t|jjd�|�t|jjd�dSr�)r)r(r3r�rr�r1r�r�rrr�test_loadNonPackage�s���zLoaderTests.test_loadNonPackagecCs"ddlm}|�t|jj|�dSr�)r)r(r3r�rr�r�rrr�test_loadModuleAsPackage�sz$LoaderTests.test_loadModuleAsPackagecCs,ddl}|jj|dd�}|�d|���dS�NrT�Zrecurse�r�r�rrr�test_loadPackageRecursive�sz%LoaderTests.test_loadPackageRecursivecCs:ddlm}|j�|�}|�|j|jdjdjj�dSr�)	r)r(rr�r!r9ry�	__class__r:r�rrr�test_loadAnythingOnModule�s
�z%LoaderTests.test_loadAnythingOnModulecCs.ddlm}|j�|j�}|�d|���dS)Nrr'r�)r)r(rr�r1r!r�r�rrr�test_loadAnythingOnClass�sz$LoaderTests.test_loadAnythingOnClasscCs0ddlm}|j�|jj�}|�d|���dS)Nrr'r�)r)r(rr�r1r�r!r�r�rrr�test_loadAnythingOnMethod�sz%LoaderTests.test_loadAnythingOnMethodcCs<ddl}|j�|�}|�t||jj��|�d|���dSr��rFrr�rg�
isinstanceZsuiteFactoryr!r�r�rrr�test_loadAnythingOnPackage�sz&LoaderTests.test_loadAnythingOnPackagecCs@ddl}|jj|dd�}|�t||jj��|�d|���dSr�r�r�rrr�#test_loadAnythingOnPackageRecursive�sz/LoaderTests.test_loadAnythingOnPackageRecursivecCs|�t|jjd�dS)NrF)r3r�rr�rrrr�test_loadAnythingOnString�s�z%LoaderTests.test_loadAnythingOnStringcCsxddl}|jj|dd�}t��}|�|�|�d|���|�dt|j	��dd�|j	D�}|�
�|�|dd	g�dS)
NrTr�Fr�cSsg|]\}}|���qSr)r)rpr�errorrrrrq�sz1LoaderTests.test_importErrors.<locals>.<listcomp>zpackage.test_bad_modulezpackage.test_import_module)�packagerr�r	�Reporterr�r!�
wasSuccessfulr��errors�sort)rr�r~r�r�rrr�test_importErrors�s
�zLoaderTests.test_importErrorscCsBGdd�dtj�}|j�|�}t��}|�|�|�|���dS)z�
        L{TestLoader.loadClass} returns a suite with each test method
        represented by a different instances of the L{TestCase} they are
        defined on.
        c@seZdZdd�Zdd�ZdS)z>LoaderTests.test_differentInstances.<locals>.DistinctInstancescSs
d|_dS)NZtest1Run)�firstrrrr�test_1�szELoaderTests.test_differentInstances.<locals>.DistinctInstances.test_1cSs|�t|d��dS)Nr�)ZassertFalse�hasattrrrrr�test_2�szELoaderTests.test_differentInstances.<locals>.DistinctInstances.test_2N)r9r:r;r�r�rrrr�DistinctInstances�sr�N)	�pyunitZTestCaserrxr	r�r�rgr�)rr�r~r�rrr�test_differentInstances�s

z#LoaderTests.test_differentInstancescCs@ddlm}|j�|�}|�d|���|�dt|dd��dS)zp
        Check that C{test_suite} is used when present and other L{TestCase}s are
        not included.
        r)�mockcustomsuite�
MyCustomSuite�nameN)r)r�rr�r!r��getattr)rr�r~rrr�test_loadModuleWith_test_suite�sz*LoaderTests.test_loadModuleWith_test_suitecCs@ddlm}|j�|�}|�d|���|�dt|dd��dS)zo
        Check that C{testSuite} is used when present and other L{TestCase}s are
        not included.
        r��mockcustomsuite2r�r�N)r)r�rr�r!r�r�)rr�r~rrr�test_loadModuleWith_testSuite�sz)LoaderTests.test_loadModuleWith_testSuitecCs0ddlm}|j�|�}|�dt|dd��dS)z�
        Check that if C{testSuite} and C{test_suite} are both present in a
        module then C{testSuite} gets priority.
        r)�mockcustomsuite3�	testSuiter�N)r)r�rr�r!r�)rr�r~rrr�test_loadModuleWithBothCustom�sz)LoaderTests.test_loadModuleWithBothCustomcCsFdd�}ddlm}||j|_}z|�t|jj|�W5||_XdS)zz
        Make sure that any C{AttributeError}s raised by C{testSuite} are not
        swallowed by L{TestLoader}.
        cSstd��dS)Nzshould be reraised)r4rrrrr�	szBLoaderTests.test_customLoadRaisesAttributeError.<locals>.testSuiterr�N)r)r�r�r3r4rr�)rr�r�Zoriginalrrr�#test_customLoadRaisesAttributeErrors��z/LoaderTests.test_customLoadRaisesAttributeErrorcCs0t|�}t|�}|��|��|�||�dSr)rr�r!)rZtest1Ztest2Znames1Znames2rrr�assertSuitesEquals
zLoaderTests.assertSuitesEqualcCs4d}|j�||gd�}|j�|d�}|�||�dS)z@
        Check that loadByNames ignores duplicate names
        �twisted.trial.test.test_logTN)r�loadByNamesr�r�)rrc�suite1�suite2rrr�test_loadByNamesDuplicatesz%LoaderTests.test_loadByNamesDuplicatecCsHddddddg}|j�|�}t�t|jj|��}|�t|�t|��dS)zX
        L{TestLoader.loadByNames} preserves the order of tests provided to it.
        �$inheritancepackage.test_x.A.test_foor&rFr�r0�package.test_moduleN)rr�r�	TestSuite�mapr�r!r�rrIr�r�rrr�test_loadByNamesPreservesOrder(s�z*LoaderTests.test_loadByNamesPreservesOrdercCs8ddg}|j�|�}t�t|jj|��}|�||�dS)zM
        Check that loadByNames loads all the names that it is given
        rFr�N�rr�rr�r�r�r�r�rrr�test_loadDifferentNames8sz#LoaderTests.test_loadDifferentNamescCs8ddg}|j�|�}t�t|jj|��}|�||�dS)zu
        Check that test methods names which are inherited from are all
        loaded rather than just one.
        r�z$inheritancepackage.test_x.B.test_fooNr�)r�methodsr�r�rrr�test_loadInheritedMethodsAs�z%LoaderTests.test_loadInheritedMethodszNot possible on Python 3.N)*r9r:r;r<rrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rZ_msgr=rrrrrk�sV







	rkc@seZdZdd�ZdS)�ZipLoadingTestscCsNddlm}t�|�||j|jd�|jd7_|�|j|jg�dS)Nr)�zipitz.zip)Z twisted.python.test.test_zippathr�rkrrOrKrL)rr�rrrr\s

zZipLoadingTests.setUpN)r9r:r;rrrrrr�[sr�c@s:eZdZdd�Zdd�Zejfdd�Zdd�Zd	d
�Z	dS)�PackageOrderingTestscCslt��|_|��|_tj�|jd�}t�|�t	tj�|d�d��
�tj�
||�|�|j|jg�dS)N�uberpackagere�wb)rrrZmktempZtopDirrMr.rN�makedirs�open�closerrlrrKrL)rrOrrrrgs


zPackageOrderingTests.setUpccs�td�}g}|��D]$}|j�d�d�d�r|�|�qt||d�}|D]�}|�d�}|dkrh|VqJg}|��D]}	t	�
|	���rt|�|	�qtt||d�}
|
D]R}g}|��D]$}
|
j�d�d�d�r�|�|
�q�t||d�}|D]
}|Vq�q�qJdS)a�
        Right now, halfway by accident, trial sorts like this:

            1. all modules are grouped together in one list and sorted.

            2. within each module, the classes are grouped together in one list
               and sorted.

            3. finally within each class, each test method is grouped together
               in a list and sorted.

        This attempts to return a sorted list of testable thingies following
        those rules, so that we can compare the behavior of loadPackage.

        The things that show as 'cases' are errors from modules which failed to
        import, and test methods.  Let's gather all those together.
        r��.rsZtest_)�keyNr)r
ZwalkModulesr��split�
startswithr�sorted�loadZiterAttributesrZ
isTestCase)rr}�pkgZtestModulesr`Z
sortedModulesZmodinforcZtestClassesZattribZ
sortedClassesZclsinfoZtestMethods�attrZ
sortedMethodsZmethinforrr�_trialSortAlgorithmps.
z(PackageOrderingTests._trialSortAlgorithmc	
Cs�ddl}||j_|jj|dd�}t�|t�}tt|��}t|�	|��}t
t||��D]0\}\}}|�|j
|��d||j
|��f�qT|�t|�t|��dS)zG
        Verify that packages are loaded in the correct order.
        rNTr�z
#%d: %s != %s)r�rr}r�r
Zdecorater�listrr��	enumerater{r!r�rr�)	rr}r�r~ZresultingTestsZmanifestZnumberZmanifestTestZ
actualTestrrr�loadSortedPackages�s"���z'PackageOrderingTests.loadSortedPackagescCs|��dSr�r�rrrr�test_sortPackagesDefaultOrder�sz2PackageOrderingTests.test_sortPackagesDefaultOrdercCsdd�}|�|�dS)NcSs t�|�}t|�d����}|S)Nr_)rr�rraZ	hexdigest)�s�n�drrr�sillySorter�s
zEPackageOrderingTests.test_sortPackagesSillyOrder.<locals>.sillySorterr�)rr�rrr�test_sortPackagesSillyOrder�sz0PackageOrderingTests.test_sortPackagesSillyOrderN)
r9r:r;rr�rr�r�r�rrrrrr�es
	-r�)"r<Z
__future__rrrMrHr
r�ZhashlibrZtwisted.pythonrrr)rZ
twisted.trialrr	Ztwisted.trial.itrialrZtwisted.trial._asyncrunnerrZtwisted.python.modulesr
Ztwisted.python.compatrrrrrlr>rkr�r�rrrr�<module>s*;q