File: //proc/self/root/lib/python3/dist-packages/twisted/test/__pycache__/test_twisted.cpython-38.pyc
U
W[�+ � @ sH d Z ddlmZmZ ddlZddlZddlmZ ddlm Z ddl
mZ ddlm
Z
ddlmZ G d d
� d
e�Zdd� Zd
d� ZG dd� de�ZG dd� de�ZG dd� de�Zer�dddgZnddddddddgZeD ]hZG dd� de�Ze�� d Zee_e�r$d �ej�� dd!� eg �e_e � �!e�� d ei� [[q�[dS )"zt
Tests for miscellaneous behaviors of the top-level L{twisted} package (ie, for
the code in C{twisted/__init__.py}.
� )�division�absolute_importN)�
ModuleType)�_checkPythonVersion)�_PY3)�reflect)�TestCasec @ s0 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
S )�SetAsideModulez�
L{SetAsideModule} is a context manager for temporarily removing a module
from C{sys.modules}.
@ivar name: The name of the module to remove.
c C s
|| _ d S �N)�name)�selfr � r
�;/usr/lib/python3/dist-packages/twisted/test/test_twisted.py�__init__ s zSetAsideModule.__init__c s6 t � fdd�ttj�� �D ��}|D ]}tj|= q$|S )z�
Find the given module and all of its hierarchically inferior modules in
C{sys.modules}, remove them from it, and return whatever was found.
c s2 g | ]*\}}|� j ks&|�� j d �r||f�qS )�.)r �
startswith)�.0Z
moduleName�module�r r
r �
<listcomp>( s
�z,SetAsideModule._unimport.<locals>.<listcomp>)�dict�list�sys�modules�items)r r r r
r r � _unimport# s �
zSetAsideModule._unimportc C s | � | j�| _d S r
)r r r r r
r
r � __enter__3 s zSetAsideModule.__enter__c C s | � | j� tj�| j� d S r
)r r r r �update)r ZexcTypeZexcValue� tracebackr
r
r �__exit__7 s zSetAsideModule.__exit__N)�__name__�
__module__�__qualname__�__doc__r r r r r
r
r
r r s
r c C s i }t d| |� tj�|� dS )a
Take a mapping defining a package and turn it into real C{ModuleType}
instances in C{sys.modules}.
Consider these example::
a = {"foo": "bar"}
b = {"twisted": {"__version__": "42.6"}}
c = {"twisted": {"plugin": {"getPlugins": stub}}}
C{_install(a)} will place an item into C{sys.modules} with C{"foo"} as the
key and C{"bar" as the value.
C{_install(b)} will place an item into C{sys.modules} with C{"twisted"} as
the key. The value will be a new module object. The module will have a
C{"__version__"} attribute with C{"42.6"} as the value.
C{_install(c)} will place an item into C{sys.modules} with C{"twisted"} as
the key. The value will be a new module object with a C{"plugin"}
attribute. An item will also be placed into C{sys.modules} with the key
C{"twisted.plugin"} which refers to that module object. That module will
have an attribute C{"getPlugins"} with a value of C{stub}.
@param modules: A mapping from names to definitions of modules. The names
are native strings like C{"twisted"} or C{"unittest"}. Values may be
arbitrary objects. Any value which is not a dictionary will be added to
C{sys.modules} unmodified. Any dictionary value indicates the value is
a new module and its items define the attributes of that module. The
definition of this structure is recursive, so a value in the dictionary
may be a dictionary to trigger another level of processing.
@return: L{None}
N)�
_makePackagesr r r )r �resultr
r
r �_install= s "r&