File: //lib/python3/dist-packages/twisted/internet/test/__pycache__/test_inotify.cpython-38.pyc
U
W[.A � @ sx d Z ddlZddlmZmZ ddlmZmZ ddlm Z ddl
mZ e d�dk r^ddlmZ ndZG d d
� d
ej
�ZdS )z?
Tests for the inotify wrapper in L{twisted.internet.inotify}.
� N)�defer�reactor)�filepath�runtime)�
requireModule)�unittestztwisted.python._inotify)�inotifyc @ s� e Zd ZdZej�� sdZdd� Zdd� Z d8dd �Z
d
d� Zdd
� Zdd� Z
dd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zd d!� Zd"d#� Zd$d%� Zd&d'� Zd(d)� Zd*d+� Zd,d-� Zd.d/� Zd0d1� Zd2d3� Zd4d5� Z d6d7� Z!dS )9�INotifyTestsz]
Define all the tests for the basic functionality exposed by
L{inotify.INotify}.
z&This platform doesn't support INotify.c C s@ t �| �� �| _| j�� t�� | _| j�� | �| jj � d S �N)
r �FilePath�mktemp�dirname�createDirectoryr �INotifyZstartReadingZ
addCleanup�loseConnection��self� r �D/usr/lib/python3/dist-packages/twisted/internet/test/test_inotify.py�setUp s
zINotifyTests.setUpc C s4 G dd� d�}| � tjd|� � | �tjtj� dS )a
L{inotify.INotify} emits a C{RuntimeError} when initialized
in an environment that doesn't support inotify as we expect it.
We just try to raise an exception for every possible case in
the for loop in L{inotify.INotify._inotify__init__}.
c @ s e Zd Zdd� ZdS )z;INotifyTests.test_initializationErrors.<locals>.FakeINotifyc S s t �� �d S r
)r �INotifyErrorr r r r �init. s z@INotifyTests.test_initializationErrors.<locals>.FakeINotify.initN)�__name__�
__module__�__qualname__r r r r r �FakeINotify- s r Z_inotifyN)Zpatchr r �assertRaisesr )r r r r r �test_initializationErrors% s z&INotifyTests.test_initializationErrorsNc s` � dkr�j �d�� t�� �� ��fdd�}��|� �jj�j ��fdd�gd� |� � �S )a�
Test notification from some filesystem operation.
@param mask: The event mask to use when setting up the watch.
@param operation: A function which will be called with the
name of a file in the watched directory and which should
trigger the event.
@param expectedPath: Optionally, the name of the path which is
expected to come back in the notification event; this will
also be passed to C{operation} (primarily useful when the
operation is being done to the directory itself, not a
file in it).
@return: A L{Deferred} which fires successfully when the
expected event has been received or fails otherwise.
Nzfoo.barc s0 | \}}}�� |�� � �� � ��|�@ � d S r
)�assertEqual�asBytesMode�
assertTrue)�result�watch�filename�events)�expectedPath�maskr r r �
cbNotifiedJ s
z2INotifyTests._notificationTest.<locals>.cbNotifiedc s
� � | �S r
��callback��args��notifiedr r �<lambda>R � z0INotifyTests._notificationTest.<locals>.<lambda>�r&