File: //usr/lib/python3/dist-packages/twisted/test/__pycache__/test_modules.cpython-310.pyc
o
^h�bD � @ s� d Z ddlZddlZddlZddlZddlZddlmZ ddlm Z ddl
mZ ddlm
Z
ddlmZ ddlmZ dd lmZ G d
d� dee�ZG dd
� d
e�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�Zg d�ZdS )zV
Tests for twisted.python.modules, abstract access to imported or importable
objects.
� N)�modules)�
networkString)�FilePath)�namedAny)�TwistedModulesMixin)�zipit)�TestCasec @ s e Zd ZdZedfdd�ZdS )�TwistedModulesTestCasez/
Base class for L{modules} test cases.
Fc C s: |j |d�D ]}|j|kr| S q| �d|�d�� 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.
��importPackageszUnable to find module z through iteration.N)�walkModules�name�fail)�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 sR t d� d}| �� }|�d�}|�d��|� |�d�}|�� |�d��|� |�d��d� | �� }|�d�}|�d��|� |�d�}|�� |�d��|� |�d��d� | �|j|jg� t�d�}z d d
� |j dd�D �} W t
tj�� �D ]}|�
d�r�tj|= q|nt
tj�� �D ]}|�
d�r�tj|= q�w g d
�}
| �| |
� dS )zd
Duplicate packages are not yielded when iterating over namespace
packages.
�pkgutilsB import pkgutil; __path__ = pkgutil.extend_path(__path__, __name__)�test_package�__init__.py�nested_packagez module.py� z
module2.pyc S � g | ]}|j �qS r �r
)�.0�modr r r �
<listcomp>h � z6BasicTests.test_namespacedPackages.<locals>.<listcomp>Tr
)r ztest_package.nested_packagez"test_package.nested_package.modulez#test_package.nested_package.module2N)�
__import__�pathEntryWithOnePackage�child�
setContent�makedirs�replaceSysPath�pathr � getModuler �list�sys�keys�
startswith�assertEqual)r �namespaceBoilerplate�entry�testPackagePath�nestedEntry�anotherEntry�anotherPackagePath�anotherNestedEntry�module�walkedNames�expectedr r r �test_namespacedPackages+ 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)�sysPath�moduleLoader�
importerCache�sysPathHooks�
moduleDict)r �
PythonPathr'