HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/test_inotify.cpython-38.pyc
U


W[.A�@sxdZddlZddlmZmZddlmZmZddlm	Z	ddl
mZe	d�dk	r^ddlmZndZGd	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�eZdZdZej��sdZdd�Zdd�Z	d8dd	�Z
d
d�Zdd
�Zdd�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.cCs@t�|���|_|j��t��|_|j��|�|jj	�dS�N)
r�FilePath�mktemp�dirname�createDirectoryr�INotifyZstartReadingZ
addCleanup�loseConnection��self�r�D/usr/lib/python3/dist-packages/twisted/internet/test/test_inotify.py�setUps



zINotifyTests.setUpcCs4Gdd�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@seZdZdd�ZdS)z;INotifyTests.test_initializationErrors.<locals>.FakeINotifycSst���dSr
)r�INotifyErrorrrrr�init.sz@INotifyTests.test_initializationErrors.<locals>.FakeINotify.initN)�__name__�
__module__�__qualname__rrrrr�FakeINotify-srZ_inotifyN)Zpatchrr�assertRaisesr)rrrrr�test_initializationErrors%sz&INotifyTests.test_initializationErrorsNcs`�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.barcs0|\}}}��|��������|�@�dSr
)�assertEqual�asBytesMode�
assertTrue)�result�watch�filename�events)�expectedPath�maskrrr�
cbNotifiedJs
z2INotifyTests._notificationTest.<locals>.cbNotifiedcs
��|�Sr
��callback��args��notifiedrr�<lambda>R�z0INotifyTests._notificationTest.<locals>.<lambda>�r&�	callbacks)r
�childr�Deferred�addCallbackrr")rr&�	operationr%r'r)r%r&r-rr�_notificationTest4s
�zINotifyTests._notificationTestcCsdd�}|�tj|�S)z{
        Reading from a file in a monitored directory sends an
        C{inotify.IN_ACCESS} event to the callback.
        cSs|�d�|��dS)N�foo)�
setContentZ
getContent��pathrrrr5\s
z+INotifyTests.test_access.<locals>.operation)r6r�	IN_ACCESS�rr5rrr�test_accessWszINotifyTests.test_accesscCsdd�}|�tj|�S)zy
        Writing to a file in a monitored directory sends an
        C{inotify.IN_MODIFY} event to the callback.
        c	Ss$|�d��}|�d�W5QRXdS)N�wr7)�open�write)r:ZfObjrrrr5hsz+INotifyTests.test_modify.<locals>.operation)r6rZ	IN_MODIFYr<rrr�test_modifycszINotifyTests.test_modifycCsdd�}|�tj|�S)z�
        Changing the metadata of a file in a monitored directory
        sends an C{inotify.IN_ATTRIB} event to the callback.
        cSs|��|��dSr
)�touchr9rrrr5tsz+INotifyTests.test_attrib.<locals>.operation)r6rZ	IN_ATTRIBr<rrr�test_attriboszINotifyTests.test_attribcCsdd�}|�tj|�S)z�
        Closing a file which was open for writing in a monitored
        directory sends an C{inotify.IN_CLOSE_WRITE} event to the
        callback.
        cSs|�d���dS�Nr>�r?�closer9rrrr5�sz/INotifyTests.test_closeWrite.<locals>.operation)r6r�IN_CLOSE_WRITEr<rrr�test_closeWrite{szINotifyTests.test_closeWritecCsdd�}|�tj|�S)z�
        Closing a file which was open for reading but not writing in a
        monitored directory sends an C{inotify.IN_CLOSE_NOWRITE} event
        to the callback.
        cSs|��|�d���dS)N�r)rBr?rFr9rrrr5�sz1INotifyTests.test_closeNoWrite.<locals>.operation)r6rZIN_CLOSE_NOWRITEr<rrr�test_closeNoWrite�szINotifyTests.test_closeNoWritecCsdd�}|�tj|�S)zt
        Opening a file in a monitored directory sends an
        C{inotify.IN_OPEN} event to the callback.
        cSs|�d���dSrDrEr9rrrr5�sz)INotifyTests.test_open.<locals>.operation)r6r�IN_OPENr<rrr�	test_open�szINotifyTests.test_opencs�fdd�}��tj|�S)z}
        Moving a file out of a monitored directory sends an
        C{inotify.IN_MOVED_FROM} event to the callback.
        cs&|�d���|�t������dSrD)r?rF�moveTorrrr9rrrr5�sz.INotifyTests.test_movedFrom.<locals>.operation)r6rZ
IN_MOVED_FROMr<rrr�test_movedFrom�szINotifyTests.test_movedFromcs�fdd�}��tj|�S)zy
        Moving a file into a monitored directory sends an
        C{inotify.IN_MOVED_TO} event to the callback.
        cs$t�����}|��|�|�dSr
)rrrrBrM)r:�prrrr5�sz,INotifyTests.test_movedTo.<locals>.operation)r6rZIN_MOVED_TOr<rrr�test_movedTo�szINotifyTests.test_movedTocCsdd�}|�tj|�S)zw
        Creating a file in a monitored directory sends an
        C{inotify.IN_CREATE} event to the callback.
        cSs|�d���dSrDrEr9rrrr5�sz+INotifyTests.test_create.<locals>.operation)r6r�	IN_CREATEr<rrr�test_create�szINotifyTests.test_createcCsdd�}|�tj|�S)zw
        Deleting a file in a monitored directory sends an
        C{inotify.IN_DELETE} event to the callback.
        cSs|��|��dSr
)rB�remover9rrrr5�sz+INotifyTests.test_delete.<locals>.operation)r6rZ	IN_DELETEr<rrr�test_delete�szINotifyTests.test_deletecCsdd�}|jtj||jd�S)z{
        Deleting the monitored directory itself sends an
        C{inotify.IN_DELETE_SELF} event to the callback.
        cSs|��dSr
)rSr9rrrr5�sz/INotifyTests.test_deleteSelf.<locals>.operation�r%)r6r�IN_DELETE_SELFr
r<rrr�test_deleteSelf�s�zINotifyTests.test_deleteSelfcs �fdd�}�jtj|�jd�S)zy
        Renaming the monitored directory itself sends an
        C{inotify.IN_MOVE_SELF} event to the callback.
        cs|�t������dSr
)rMrrrr9rrrr5�sz-INotifyTests.test_moveSelf.<locals>.operationrU)r6rZIN_MOVE_SELFr
r<rrr�
test_moveSelf�s�zINotifyTests.test_moveSelfcsT���fdd�}tjtjB}�jj�j|d|gd��j�d��t�������S)z�
        L{inotify.INotify} when initialized with autoAdd==True adds
        also adds the created subdirectories to the watchlist.
        cs ���fdd�}t�d|�dS)NcsBz ���j������d�Wntk
r<���YnXdSr
)r r�
_isWatchedr)�	Exception�errbackr��dr�subdirrr�_�s
zIINotifyTests.test_simpleSubdirectoryAutoAdd.<locals>._callback.<locals>._r�r�	callLater)�wpr#r&r_r\rr�	_callback�sz>INotifyTests.test_simpleSubdirectoryAutoAdd.<locals>._callbackT�r&�autoAddr1�test�	r�IN_ISDIRrQr"r
r2rr3r�rrc�	checkMaskrr\r�test_simpleSubdirectoryAutoAdd�s�z+INotifyTests.test_simpleSubdirectoryAutoAddcsZg�����fdd�}tjtjB}�jj�j|d|gd��j�d��t�������S)zz
        L{inotify.INotify} removes a directory from the watchlist when
        it's removed from the filesystem.
        csL���fdd�}���fdd�}�s<��|�t�d|�nt�d|�dS)Ncs@z���j�������Wntk
r:���YnXdSr
)r rrYrSrZr[rr\rrr_
s
zEINotifyTests.test_simpleDeleteDirectory.<locals>._callback.<locals>._csBz ���j������d�Wntk
r<���YnXdSr
��assertFalserrYr)rZr[rr\rr�_ebs
zGINotifyTests.test_simpleDeleteDirectory.<locals>._callback.<locals>._ebr)�appendrra)rbr#r&r_rn��callsr]rr^rrrcs
z:INotifyTests.test_simpleDeleteDirectory.<locals>._callbackTrdrfrgrirrpr�test_simpleDeleteDirectorys�z'INotifyTests.test_simpleDeleteDirectorycCsL|jj|jdd�|�|j�|j��|j�|j�|�|j�|j��dS)zR
        L{inotify.INotify.ignore} removes a directory from the watchlist
        T)reN)rr"r
r rY�ignorermrrrr�test_ignoreDirectory*sz!INotifyTests.test_ignoreDirectorycCs\tjD]\}}|�t�|�d|�qtjtjBtjB}|�tt�|��tdddg��dS)zy
        L{inotify.humaReadableMask} translates all the possible event
        masks to a human readable string.
        rZclose_write�accessr?N)rZ_FLAG_TO_HUMANrZhumanReadableMaskrGr;rK�set)rr&�valuerjrrr�test_humanReadableMask4s��z#INotifyTests.test_humanReadableMaskcCsv|j�d�}|�d�}|�d�}|��|||g}|jj|jdd�|jj|jdd�|D]}|�|j�|��qZdS)z�
        L{inotify.INotify.watch} with recursive==True will add all the
        subdirectories under the given path to the watchlist.
        rf�test2�test3T)�	recursiveN)r
r2�makedirsrr"r rY)rr^�subdir2�subdir3�dirsr]rrr�test_recursiveWatchCs


z INotifyTests.test_recursiveWatchcCs0ddl}t��}|�|j�|��|��dS)z�
        L{inotify.INotify.connectionLost} if there's a problem while closing
        the fd shouldn't raise the exception but should log the error
        rN)�osrrrFZ_fdrZflushLoggedErrors)rr�Zin_rrr�test_connectionLostErrorTs
z%INotifyTests.test_connectionLostErrorcsT���fdd�}tjtjB}�jj�j|d|gd��j�d��t�������S)z�
        L{inotify.INotify.watch} with autoAdd==False will stop inotify
        from watching subdirectories created under the watched one.
        cs ���fdd�}t�d|�dS)NcsBz ���j������d�Wntk
r<���YnXdSr
rlrr\rrr_gs
zEINotifyTests.test_noAutoAddSubdirectory.<locals>._callback.<locals>._rr`)rb�fpr&r_r\rrrcdsz:INotifyTests.test_noAutoAddSubdirectory.<locals>._callbackFrdrfrgrirr\r�test_noAutoAddSubdirectory_s�z'INotifyTests.test_noAutoAddSubdirectorycs��j�d�����t�����fdd�}�fdd�}���jj�|gd���j������jj�tj	|gd����
|�����S)z�
        L{inotify.INotify} will watch a filepath for events even if the same
        path is repeatedly added/removed/re-added to the watchpoints.
        �foo.bar2cs2|\}}}��|��������|tj@�dSr
�rrr rrV�r!Zignoredr#r$)r%rrrr'�s
z<INotifyTests.test_seriesOfWatchAndIgnore.<locals>.cbNotifiedcs��|�dSr
r(r*r,rr�callIt�sz8INotifyTests.test_seriesOfWatchAndIgnore.<locals>.callIt�r1r0)r
r2rBrr3r rr"rsrVr4rS)rr'r�r)r%r-rr�test_seriesOfWatchAndIgnoreys"��
z(INotifyTests.test_seriesOfWatchAndIgnorecs��j�d�}|���j�d�����t�����fdd�}�fdd�}���jj|tj|gd����	|����jj�tj|gd���j�
|�|������S)zr
        L{inotify.INotify} will ignore a filepath after it has been removed from
        the watch list.
        r�zfoo.bar3cs2|\}}}��|��������|tj@�dSr
r�r�)�
expectedPath2rrrr'�s
z4INotifyTests.test_ignoreFilePath.<locals>.cbNotifiedcs��|�dSr
r(r*r,rrr��sz0INotifyTests.test_ignoreFilePath.<locals>.callItr�)r
r2rBrr3r rr"rVr4rsrS)rr%r'r�r)r�r-rr�test_ignoreFilePath�s4��
��z INotifyTests.test_ignoreFilePathcCs*|j�d�}|��|�t|jj|�dS)zf
        L{inotify.INotify} will raise KeyError if a non-watched filepath is
        ignored.
        zfoo.ignoredN)r
r2rBr�KeyErrorrrs)rr%rrr�test_ignoreNonWatchedFile�sz&INotifyTests.test_ignoreNonWatchedFilecs�t���������fdd�}tjtjB}�jj�j|d|gd��j�d����d����d��t�����	���d���d	���d
�g�t
��D]\}}|�|j�
t����q��S)aB
        L{inotify.INotify} with autoAdd==True for a watched path
        generates events for every file or directory already present
        in a newly created subdirectory under the watched one.

        This tests that we solve a race condition in inotify even though
        we may generate duplicate events.
        cs���|�t��dkr�zv���j�������j�������j��������g}dd�|D�}��t��t|�����|�Wntk
r����YnX��d�dS)N�cSsh|]}|���qSr)r)�.0�frrr�	<setcomp>�szRINotifyTests.test_complexSubdirectoryAutoAdd.<locals>._callback.<locals>.<setcomp>)	�add�lenr rrYrrZr[r))rbr#r&Zcreated�rqr]rZ	someFilesr^r}r~rrrc�s
z?INotifyTests.test_complexSubdirectoryAutoAdd.<locals>._callbackTrdrfryrzz	file1.datz	file2.datz	file3.dat)rvrrhrQr"r
r2rr3r|�	enumerater8r:�encode�sys�getfilesystemencoding)rrcrj�ir#rr�r�test_complexSubdirectoryAutoAdd�s.	�

��z,INotifyTests.test_complexSubdirectoryAutoAdd)N)"rrr�__doc__r�platformZsupportsINotify�skiprrr6r=rArCrHrJrLrNrPrRrTrWrXrkrrrtrxr�r�r�r�r�r�r�rrrrr	s:

#

)
#$r	)r�r�Ztwisted.internetrrZtwisted.pythonrrZtwisted.python.reflectrZ
twisted.trialrrZTestCaser	rrrr�<module>s