File: //lib/python3/dist-packages/twisted/test/__pycache__/test_modules.cpython-38.pyc
U
W[�E � @ s d Z ddlmZmZ ddlZddlZddlZddlZddlZddl m
Z
ddlmZ ddl
mZ ddlmZ ddlmZ dd lmZ dd
lmZ G dd� dee�ZG d
d� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZdddddgZdS )zV
Tests for twisted.python.modules, abstract access to imported or importable
objects.
� )�division�absolute_importN)�modules)�
networkString)�FilePath)�namedAny)�TestCase)�TwistedModulesMixin)�zipitc @ s e Zd ZdZedfdd�ZdS )�TwistedModulesTestCasez/
Base class for L{modules} test cases.
Fc C s8 |j |d�D ]}|j|kr| S q| �d|f � dS )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.
��importPackagesz+Unable to find module %r through iteration.N)�walkModules�nameZfail)�self�modname�wherer
�modinfo� r �;/usr/lib/python3/dist-packages/twisted/test/test_modules.py�findByIteration! s
z&TwistedModulesTestCase.findByIterationN)�__name__�
__module__�__qualname__�__doc__r r r r r r r s r c @ sl e Zd Zdd� Zdd� Zdd� Zdd� Zd d
� Zdd� Zd
d� Z dd� Z
dd� Zdd� Zdd� Z
dd� ZdS )�
BasicTestsc
C s0 t d� d}| �� }|�d�}|�d��|� |�d�}|�� |�d��|� |�d��d� | �� }|�d�}|�d��|� |�d�}|�� |�d��|� |�d��d� | �|j|jg� t�d�}zd d
� |j
dd�D �} W 5 t t
j�� �D ]}|�d�r�t
j|= q�X dd
ddg}
| �| |
� dS )zd
Duplicate packages are not yielded when iterating over namespace
packages.
�pkgutilsB import pkgutil; __path__ = pkgutil.extend_path(__path__, __name__)�test_package�__init__.pyZnested_packagez module.py� z
module2.pyc S s g | ]
}|j �qS r �r )�.0�modr r r �
<listcomp>m s z6BasicTests.test_namespacedPackages.<locals>.<listcomp>Tr ztest_package.nested_packagez"test_package.nested_package.modulez#test_package.nested_package.module2N)�
__import__�pathEntryWithOnePackage�child�
setContent�makedirs�replaceSysPath�pathr � getModule�list�sys�keys�
startswithr �assertEqual)r ZnamespaceBoilerplate�entryZtestPackagePathZnestedEntryZanotherEntryZanotherPackagePathZanotherNestedEntry�moduleZwalkedNames�expectedr r r �test_namespacedPackages0 s@ �
�
�z"BasicTests.test_namespacedPackagesc C sH g }t j| �� jg|ji i ddid�}| �|g � | �|d �� � dS )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)�sysPathZmoduleLoaderZ
importerCacheZsysPathHooksZ
moduleDict)r �
PythonPathr% r* �appendr0 �assertFalse�isLoaded)r Z
shouldNotLoadr* r r r �test_unimportablePackageGetItem~ s �z*BasicTests.test_unimportablePackageGetItemc C s^ | � � }| �|jg� | �ddi� tt�� �}| �dd� |D �dg� | �|d � � � dS )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 Nc S s g | ]
}|j �qS r r )r! �mr r r r# � s zBBasicTests.test_unimportablePackageWalkModules.<locals>.<listcomp>r )
r% r) r* ZreplaceSysModulesr, r r r0 r8 r9 )r �existentPathZwalkedr r r �#test_unimportablePackageWalkModules� s �z.BasicTests.test_unimportablePackageWalkModulesc C s~ | � � }t| �� �}| �|�� � | �|jg� t�d�g}t t�
� �}tj�|j� t t�
� �}| �
||� | �
||� dS )z~
Verify that L{modules.walkModules} ignores entries in sys.path which
do not exist in the filesystem.
r N)r% r �mktempr8 �existsr) r* r r+ r, r r- r7 r0 )r r<