%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/test/__pycache__/test_modules.cpython-312.pyc

�

Ϫ�f^G��h�dZddlmZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZm
Z
ddlmZddlZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZGd�de�ZGd�dee�ZGd�de�Z Gd�de�Z!Gd�de!�Z"Gd�de!�Z#Gd�de�Z$gd�Z%y)zV
Tests for twisted.python.modules, abstract access to imported or importable
objects.
�)�annotationsN)�PathEntryFinder)�
ModuleType)�Any�	Generator)�Protocol)�modules)�
networkString)�FilePath)�namedAny)�TwistedModulesMixin)�zipit)�TestCasec��eZdZ				dd�Zy)�_SupportsWalkModulesc��y�N�)�self�importPackagess  �;/usr/lib/python3/dist-packages/twisted/test/test_modules.py�walkModulesz _SupportsWalkModules.walkModuless��	�N)r�bool�returnz+Generator[modules.PythonModule, None, None])�__name__�
__module__�__qualname__rrrrrrs���"��	4�rrc�,�eZdZdZedf							dd�Zy)�TwistedModulesTestCasez/
    Base class for L{modules} test cases.
    Fc��|j|��D]}|j|k(s�|cS|jd|�d��y)z�
        You don't ever actually want to do this, so it's not in the public
        API, but sometimes we want to compare the result of an iterative call
        with a lookup call and make sure they're the same for test purposes.
        �rzUnable to find module z through iteration.N)r�name�fail)r�modname�wherer�modinfos     r�findByIterationz&TwistedModulesTestCase.findByIteration*sK���(�(��(�G�	�G��|�|�w�&���	�	
�	�	�*�7�+�5H�I�JrN)r%�strr&rrrrzmodules.PythonModule)rrr�__doc__r	r(rrrr r %s?���'.�$�	K��K�$�K��	K�

�Krr c�l�eZdZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd	�Zdd
�Zdd�Z
dd�Zy
)�
BasicTestsc���td�d}|j�}|jd�}|jd�j|�|jd�}|j	�|jd�j|�|jd�jd�|j�}|jd�}|jd�j|�|jd�}|j	�|jd�j|�|jd�jd�|j|j|jg�tjd�}	|jd	�
�D�	cgc]}	|	j��}
}	ttjj��D]%}|jd�s�tj|=�'	gd�}|j|
|�ycc}	w#ttjj��D]%}|jd�s�tj|=�'wxYw)
zd
        Duplicate packages are not yielded when iterating over namespace
        packages.
        �pkgutilsBimport pkgutil; __path__ = pkgutil.extend_path(__path__, __name__)�test_package�__init__.py�nested_packagez	module.pyrz
module2.pyTr")r/ztest_package.nested_packagez"test_package.nested_package.modulez#test_package.nested_package.module2N)�
__import__�pathEntryWithOnePackage�child�
setContent�makedirs�replaceSysPath�pathr	�	getModulerr#�list�sys�keys�
startswith�assertEqual)r�namespaceBoilerplate�entry�testPackagePath�nestedEntry�anotherEntry�anotherPackagePath�anotherNestedEntry�module�mod�walkedNames�expecteds            r�test_namespacedPackagesz"BasicTests.test_namespacedPackages<s��	�9��
V�	�2�,�,�.���+�+�n�5�����m�,�7�7�8L�M�%�+�+�,<�=���������-�(�3�3�4H�I����+�&�1�1�#�6��3�3�5��)�/�/��?��� � ��/�:�:�;O�P�/�5�5�6F�G���#�#�%�� � ��/�:�:�;O�P�� � ��.�9�9�#�>����U�Z�Z��):�):�;�<��"�"�>�2��
	,�/5�/A�/A�QU�/A�/V�W��3�8�8�W�K�W��s�{�{�/�/�1�2�
,���$�$�^�4����F�+�
,�
��	
����h�/��X���s�{�{�/�/�1�2�
,���$�$�^�4����F�+�
,�s$�H$�#H�6H$�H$�$<I5�!I5c���g}tj|j�jg|jiiddi��}|j|g�|j
|dj��y)a
        If a package has been explicitly forbidden from importing by setting a
        L{None} key in sys.modules under its name,
        L{modules.PythonPath.__getitem__} should still be able to retrieve an
        unloaded L{modules.PythonModule} for that package.
        r/N)�sysPath�moduleLoader�
importerCache�sysPathHooks�
moduleDict)r	�
PythonPathr3r8�appendr>�assertFalse�isLoaded)r�
shouldNotLoadr8s   r�test_unimportablePackageGetItemz*BasicTests.test_unimportablePackageGetItem�ss��$&�
��!�!��1�1�3�8�8�9�&�-�-���&��-�
��	
�����+�����n�-�6�6�8�9rc�`�|j�}|j|jg�|jddi�t	tj��}|j|D�cgc]}|j��c}dg�|j|dj��ycc}w)a	
        If a package has been explicitly forbidden from importing by setting a
        L{None} key in sys.modules under its name, L{modules.walkModules} should
        still be able to retrieve an unloaded L{modules.PythonModule} for that
        package.
        r/Nr)r3r7r8�replaceSysModulesr:r	rr>r#rSrT)r�existentPath�walked�ms    r�#test_unimportablePackageWalkModulesz.BasicTests.test_unimportablePackageWalkModules�s����3�3�5�����\�.�.�/�0������5�6��g�)�)�+�,�����&�1�Q�!�&�&�1�N�3C�D�������+�+�-�.��2s�,B+c��|j�}t|j��}|j|j	��|j|jg�tjd�g}ttj��}tjj|j�ttj��}|j||�|j||�y)z~
        Verify that L{modules.walkModules} ignores entries in sys.path which
        do not exist in the filesystem.
        r/N)r3r�mktemprS�existsr7r8r	r9r:rr;rRr>)rrY�nonexistentPathrI�
beforeModules�afterModuless      r�test_nonexistentPathsz BasicTests.test_nonexistentPaths�s���
�3�3�5��"�4�;�;�=�1������/�/�1�2����\�.�.�/�0��%�%�n�5�6���W�0�0�2�3�
�������,�,�-��G�/�/�1�2�������1�����x�0rc���|j�}t|j��}|j|j	��|jd�|j
|jg�ttj��}tjj|j�ttj��}|j||�y)z�
        Verify that L{modules.walkModules} ignores entries in sys.path which
        refer to regular files in the filesystem.
        szip file or whatever
N)r3rr^rSr_r5r7r8r:r	rr;rRr>)rrY�nonDirectoryPathrarbs     r�test_nonDirectoryPathsz!BasicTests.test_nonDirectoryPaths�s���
�3�3�5��#�D�K�K�M�2�����)�0�0�2�3��#�#�$=�>����\�.�.�/�0��W�0�0�2�3�
������(�-�-�.��G�/�/�1�2�������5rc�l�|jtjd�|jd��y)z�
        Scrounge around in the top-level module namespace and make sure that
        Twisted shows up, and that the module thusly obtained is the same as
        the module that we find when we look for it explicitly by name.
        �twistedN�r>r	r9r(�rs r�test_twistedShowsUpzBasicTests.test_twistedShowsUp�s*��	
����*�*�9�5�t�7K�7K�I�7V�Wrc	��|jtjd�|jdtjd����y)zo
        Verify that the walkModules APIs will give us back subpackages, not just
        subpackages.
        �twisted.pythonrh)r&Nrirjs r�test_dottedNameszBasicTests.test_dottedNames�s@��
	
������.�/�� � �!1��9J�9J�9�9U� �V�	
rc��tj�D]-}|jd|jvd|jz��/y)z�
        Verify that the iterModules API will only return top-level modules and
        packages, not submodules or subpackages.
        �.z9no nested modules should be returned from iterModules: %rN)r	�iterModulesrSr#�filePath)rrFs  r�test_onlyTopModuleszBasicTests.test_onlyTopModules�sE��
�)�)�+�	�F�����v�{�{�"�K��?�?�$�
�	rc���dD]o}t|�}|jtj|�j	�|�|j|j|�j	�|��qy)zl
        Verify that we can locate and load packages, modules, submodules, and
        subpackages.
        ��osrhrmztwisted.python.reflectN)r�failUnlessIdenticalr	r9�loadr()r�nr[s   r�test_loadPackagesAndModulesz&BasicTests.test_loadPackagesAndModules�sg��
O�	H�A����A��$�$�W�%6�%6�q�%9�%>�%>�%@�!�D��$�$�T�%9�%9�!�%<�%A�%A�%C�Q�G�	Hrc��dD]S}|jtj|�jjj
tj
��Uy)zu
        Verify that path entries discovered via module loading are, in fact, on
        sys.path somewhere.
        ruN)�failUnlessInr	r9�	pathEntryrrr8r;)rrys  r�test_pathEntriesOnPathz!BasicTests.test_pathEntriesOnPath�sG��
O�	V�A����g�/�/��2�<�<�E�E�J�J�C�H�H�U�	Vrc���t|j��}|j�tj|j
g��}|j�d
�fd�}|jd�jd�tj|j
d��|jtt|j���d�||_|j|dj|jd��y	)z~
        Verify that .py files will always be preferred to .pyc files, regardless of
        directory listing order.
        �rLc�L����|�}|j�d�fd�}||_|S)Nc�h��t���}|j�|j�|Sr)r:�sort�reverse)�x�originalChildrens �r�evilChildrenzLBasicTests.test_alwaysPreferPy.<locals>._evilSmartPath.<locals>.evilChildrens*����)�+�,�������	�	���r)rr)�children)�pathName�or�r��originalSmartPaths   @�r�_evilSmartPathz6BasicTests.test_alwaysPreferPy.<locals>._evilSmartPaths*���!�(�+�A� �z�z��
�&�A�J��Hrzabcd.py�
T)�quiet��abcdN)r�r)rr)rr^�createDirectoryr	rQr8�
_smartPathr4r5�
compileall�compile_dirr>�lenr:r�rr)r�mypath�ppr�r�s    @r�test_alwaysPreferPyzBasicTests.test_alwaysPreferPys����
�$�+�+�-�(����� �
�
�
����
�
6���M�M��
	�	���Y��*�*�5�1����v�{�{�$�7�����T�&�/�/�"3�4�5�q�9�&��
�����F��,�,�f�l�l�9�.E�Frc��t|j��}|j�tj|j
g��}|j
d�}|j�|j
d�jd�tj
j|j
�td�	t|j��}|jt|�d�|j|djd�tjd=tj
j!|j
�y#tjd=tj
j!|j
�wxYw)z�
        A package can delete its __path__ for some reasons,
        C{modules.PythonPath} should be able to deal with it.
        r�r�r0s
del __path__
�rN)rr^r�r	rQr8r4r5r;rRr2r:rr>r�r#�remove)rr�r��subpath�ls     r�test_packageMissingPathz"BasicTests.test_packageMissingPath!s
��
�$�+�+�-�(����� �
�
�
����
�
6���,�,�v�&�����!��
�
�m�$�/�/�0A�B���������$��6��	)��R�^�^�%�&�A����S��V�Q�'����Q�q�T�Y�Y��/����F�#��H�H�O�O�F�K�K�(�����F�#��H�H�O�O�F�K�K�(�s
�AE�<FN�r�None)rrrrJrVr\rcrfrkrnrsrzr~r�r�rrrr,r,;sE��J0�X:�$
/�1�*6�&X�
�
�H�V�G�@)rr,c�t�eZdZdZej
�Zdd�Zdd�Zdd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd	�Zy
)�PathModificationTestszp
    These tests share setup/cleanup behavior of creating a dummy package and
    stuffing some code in it.
    c��|j�|_t|j�|_|jj	�dt|j�fz|_|jj|j�|_	|jj	�|jjd�jd�|jjd�jd�|jjd�jd�|jjd�jd�d|_y)Nzpyspacetests%dr0rza.pyzb.pyzc__init__.pyF)r^�pathExtensionNamer�
pathExtensionr��next�
_serialnum�packageNamer4�packagePathr5�	pathSetUprjs r�setUpzPathModificationTests.setUp@s��!%������%�d�&<�&<�=������*�*�,�+�t�D�O�O�/D�.F�F����-�-�3�3�D�4D�4D�E������(�(�*������}�-�8�8��=������v�&�1�1�#�6������v�&�1�1�#�6������~�.�9�9�#�>���rc��|jrJ�d|_tjj|j�y�NT)r�r;r8rRr�rjs r�
_setupSysPathz#PathModificationTests._setupSysPathMs,���>�>�!�!����������.�.�/rc�:�|j�}t|�}|j�|jd�j	d�|j
jd�j	t
dt|��d���|j�tj|j�}|j|j|jdz||��|d�|j|dj�jd	�y)
Nz	foozle.pysx = 123
r0z__path__.append(z)
z.foozler"�foozle�{)r^rr�r4r5r�r
�reprr�r	r9r�r>r(rxr�)r�doImport�moddir2�fpmdr's     r�_underUnderPathTestz)PathModificationTests._underUnderPathTestRs����+�+�-���� �������
�
�;��*�*�<�8������}�-�8�8��,�T�'�]�O�3�?�@�	
�	
�����#�#�D�$4�$4�5������ � �� � �9�,�g�h�
!�
�
�H��		
�	
�����*�/�/�1�3�3�S�9rc�$�|j�y)z]
        Verify that iterModules will honor the __path__ of already-loaded packages.
        N)r�rjs r�"test_underUnderPathAlreadyImportedz8PathModificationTests.test_underUnderPathAlreadyImportedes��	
� � �"rc��tj|j�}|j�D�cgc] }|jjd�d��"}}|j
�|j|gd��ycc}w)Nrp���)�a�b�	c__init__)r	r9r�rqr#�splitr�r>)r�pkginfor'�nfnis    r�_listModulesz"PathModificationTests._listModulesksh���#�#�D�$4�$4�5��;B�;N�;N�;P�Q�����"�"�3�'��+�Q��Q��	�	������6�7��Rs�%A>c�D�|j�|j�y)z�
        Make sure the module list comes back as we expect from iterModules on a
        package, whether zipped or not.
        N)r�r�rjs r�test_listingModulesz)PathModificationTests.test_listingModulesqs��
	
�������rc�n�|j�t|j�|j�y)z�
        Make sure the module list comes back as we expect from iterModules on a
        package, whether zipped or not, even if the package has already been
        imported.
        N)r�rr�r�rjs r�#_test_listingModulesAlreadyImportedz9PathModificationTests._test_listingModulesAlreadyImportedys*��	
������!�!�"����rc���|jr]d}tjj�|jus
J|dz��|jtjvs
J|dz��yy)Nz<path cleanup failed: don't be surprised if other tests breakz, 1z, 2)r�r;r8�popr�)r�HORKs  r�tearDownzPathModificationTests.tearDown�s]���>�>�Q�D��8�8�<�<�>�T�%;�%;�;�I�T�E�\�I�;��)�)����9�G�4�%�<�G�9�rNr�)T)r�rrr�)rrrr*�	itertools�countr�r�r�r�r�r�r�r�r�rrrr�r�7s@���
!����"�J��0�
:�&#�8���Hrr�c� �eZdZdZdd�Zdd�Zy)�RebindingTestsz�
    These tests verify that the default path interrogation API works properly
    even when sys.path has been rebound to a different object.
    c���|jrJ�d|_tj|_tjddt_tjj	|j
�yr�)r�r;r8�savedSysPathrRr�rjs rr�zRebindingTests._setupSysPath�sG���>�>�!�!�����H�H����8�8�A�;���������.�.�/rc�H�|jr|jt_yy)zF
        Clean up sys.path by re-binding our original object.
        N)r�r�r;r8rjs rr�zRebindingTests.tearDown�s���>�>��(�(�C�H�rNr�)rrrr*r�r�rrrr�r��s���
0�)rr�c��eZdZdd�Zy)�ZipPathModificationTestsc��|jrJ�t|j|jdz�|xjdz
c_tj|j�sJ�t
j
|�y)Nz.zip)r�rr��zipfile�
is_zipfiler�r�rjs rr�z&ZipPathModificationTests._setupSysPath�sc���>�>�!�!�
�d�$�$�d�&<�&<�v�&E�F����&�(���!�!�$�"8�"8�9�9�9��+�+�D�1rNr�)rrrr�rrrr�r��s��2rr�c�0�eZdZdZdd�Zdd�Zdd�Zdd�Zy)�PythonPathTestsz�
    Tests for the class which provides the implementation for all of the
    public API of L{twisted.python.modules}, L{PythonPath}.
    c���	�Gd�d��d	�fd�}dg}i}|g}i}d
d�}tj|||||�}t|j���	|j	t�	�d�|j
t�	fd��y)z}
        Make sure that the behavior when encountering an unknown importer
        type is not catastrophic failure.
        c��eZdZy)�>PythonPathTests.test_unhandledImporter.<locals>.SecretImporterN)rrrrrr�SecretImporterr��s��rr�c�����Srr)r#r�s �r�hookz4PythonPathTests.test_unhandledImporter.<locals>.hook�s���!�#�#rzexample/pathc��yrr)r#s r�	sysloaderz9PythonPathTests.test_unhandledImporter.<locals>.sysloader�s��rr�c����ddS)NrrFr)�entriess�r�<lambda>z8PythonPathTests.test_unhandledImporter.<locals>.<lambda>�s���G�A�J�x�,@�rN)r#�objectrr�)r#r�rr�)r	rQr:�iterEntriesr>r��assertRaises�KeyError)
rr��syspath�
sysmodules�syshooks�syscacher��spacer�r�s
        @@r�test_unhandledImporterz&PythonPathTests.test_unhandledImporter�s����	�	�	$�"�"��,.�
��6��68��	��"�"�7�J��(�I�V���u�(�(�*�+������W��q�)����(�$@�Arc��tjgtjgi�}|t}|j	|j
g�}|j
|ddt�|j
|ddttj�j�j�dztzdz�|j
t|�d�|j
|jt�y)z�
        If the path a module loaded with L{PythonPath.__getitem__} is not
        present in the path importer cache, a warning is emitted, but the
        L{PythonModule} is returned as usual.
        r�category�messagez
 (for module zR) not in path importer cache (PEP 302 violation - check your local configuration).r�N)r	rQr;r�
flushWarnings�test_inconsistentImporterCacher>�UserWarningrrh�__file__�parent�dirnamer�r#)rr��
thisModule�warningss    rr�z.PythonPathTests.test_inconsistentImporterCache�s����"�"�2�s�{�{�B��;���8�_�
��%�%�t�'J�'J�&K�L������!��Z�0�+�>�����Q�K�	�"��W�%�%�&�-�-�/�7�7�9��
��
�D�
D�	
�	
����X���*�������(�3rc�P�tj�}|jd|�y)z�
        L{PythonPath} implements the C{in} operator so that when it is the
        right-hand argument and the name of a module which exists on that
        L{PythonPath} is the left-hand argument, the result is C{True}.
        rvN)r	rQ�assertIn�r�thePaths  r�test_containsModulez#PythonPathTests.test_containsModule�s ���$�$�&���
�
�d�G�$rc�P�tj�}|jd|�y)z�
        L{PythonPath} implements the C{in} operator so that when it is the
        right-hand argument and the name of a module which does not exist on
        that L{PythonPath} is the left-hand argument, the result is C{False}.
        �bogusModuleN)r	rQ�assertNotInr�s  r�test_doesntContainModulez(PythonPathTests.test_doesntContainModule�s"���$�$�&�������0rNr�)rrrr*r�r�r�rrrrr�r��s���
B�24�*%�1rr�)r,r�r�r�r�)&r*�
__future__rr�r�r;r��
importlib.abcr�typesr�typingrrrrh�twisted.pythonr	�twisted.python.compatr
�twisted.python.filepathr�twisted.python.reflectr�#twisted.python.test.modules_helpersr
� twisted.python.test.test_zippathr�twisted.trial.unittestrrr r,r�r�r�r��__all__rrr�<module>r
s����#���
��)��!���"�/�,�+�C�2�+��8��K�0�(�K�,y)�'�y)�xRH�2�RH�j)�*�)�*2�4�2�D1�h�D1�N�r

Zerion Mini Shell 1.0