%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/internet/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/internet/test/__pycache__/test_inotify.cpython-312.pyc

�

Ϫ�f�H���dZddlZddlmZmZddlmZmZddlm	Z	ddl
mZe	d��ddlmZndZGd	�d
ej�Zy)z?
Tests for the inotify wrapper in L{twisted.internet.inotify}.
�N)�defer�reactor)�filepath�runtime)�
requireModule)�unittestztwisted.python._inotify)�inotifyc���eZdZdZej
j
�sdZd�Zd�Z	d d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#y)!�INotifyTestsz]
    Define all the tests for the basic functionality exposed by
    L{inotify.INotify}.
    z&This platform doesn't support INotify.c�8�tj|j��|_|jj	�tj�|_|j
j�|j|j
j�y�N)
r�FilePath�mktemp�dirname�createDirectoryr	�INotify�startReading�
addCleanup�loseConnection��selfs �D/usr/lib/python3/dist-packages/twisted/internet/test/test_inotify.py�setUpzINotifyTests.setUps^���(�(�����7������$�$�&����(������!�!�#�������3�3�4�c��Gd�d�}|jtjd|��|jtjtj�y)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��eZdZd�Zy)�;INotifyTests.test_initializationErrors.<locals>.FakeINotifyc�*�tj��r
)r	�INotifyErrorrs r�initz@INotifyTests.test_initializationErrors.<locals>.FakeINotify.init.s���*�*�,�,rN)�__name__�
__module__�__qualname__r �rr�FakeINotifyr-s��
-rr%�_inotifyN)�patchr	r�assertRaisesr)rr%s  r�test_initializationErrorsz&INotifyTests.test_initializationErrors$s>��	-�	-�	
�
�
�7�?�?�J��
�>����'�.�.����@rNc���������jjd��tj�����fd�}�j	|��j
j
�j��fd�g��|���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.
        zfoo.barc���|\}}}�j|j��j���j|�z�yr
)�assertEqual�asBytesMode�
assertTrue)�result�watch�filename�events�expectedPath�maskrs    ���r�
cbNotifiedz2INotifyTests._notificationTest.<locals>.cbNotifiedKsA���(.�%�U�H�f����X�1�1�3�\�5M�5M�5O�P��O�O�F�T�M�*rc�&���j|�Sr
��callback��args�notifieds �r�<lambda>z0INotifyTests._notificationTest.<locals>.<lambda>Ss���h�>O�>O�PT�>U�r�r4�	callbacks)r�childr�Deferred�addCallbackr	r0)rr4�	operationr3r5r;s`` ` @r�_notificationTestzINotifyTests._notificationTest4su���&���<�<�-�-�i�8�L��>�>�#��	+�
	���Z�(�������L�L�t�0U�/V�	�	
�	�,���rc�H�d�}|jtj|�S)z{
        Reading from a file in a monitored directory sends an
        C{inotify.IN_ACCESS} event to the callback.
        c�F�|jd�|j�y)N�foo)�
setContent�
getContent��paths rrBz+INotifyTests.test_access.<locals>.operation^s���O�O�F�#��O�O�r)rCr	�	IN_ACCESS�rrBs  r�test_accesszINotifyTests.test_accessXs"��	��%�%�g�&7�&7��C�Crc�H�d�}|jtj|�S)zy
        Writing to a file in a monitored directory sends an
        C{inotify.IN_MODIFY} event to the callback.
        c�r�|jd�5}|jd�ddd�y#1swYyxYw)N�wrF)�open�write)rJ�fObjs  rrBz+INotifyTests.test_modify.<locals>.operationjs0�����3��
#�4��
�
�6�"�
#�
#�
#�s�-�6)rCr	�	IN_MODIFYrLs  r�test_modifyzINotifyTests.test_modifyds"��	#��%�%�g�&7�&7��C�Crc�H�d�}|jtj|�S)z�
        Changing the metadata of a file in a monitored directory
        sends an C{inotify.IN_ATTRIB} event to the callback.
        c�D�|j�|j�yr
)�touchrIs rrBz+INotifyTests.test_attrib.<locals>.operationvs���J�J�L��J�J�Lr)rCr	�	IN_ATTRIBrLs  r�test_attribzINotifyTests.test_attribps"��	��%�%�g�&7�&7��C�Crc�H�d�}|jtj|�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.
        c�B�|jd�j�y�NrP�rQ�closerIs rrBz/INotifyTests.test_closeWrite.<locals>.operation�����I�I�c�N� � �"r)rCr	�IN_CLOSE_WRITErLs  r�test_closeWritezINotifyTests.test_closeWrite|s"��	#��%�%�g�&<�&<�i�H�Hrc�H�d�}|jtj|�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.
        c�b�|j�|jd�j�y)N�r)rXrQr_rIs rrBz1INotifyTests.test_closeNoWrite.<locals>.operation�s���J�J�L��I�I�c�N� � �"r)rCr	�IN_CLOSE_NOWRITErLs  r�test_closeNoWritezINotifyTests.test_closeNoWrite�s"��	#��%�%�g�&>�&>�	�J�Jrc�H�d�}|jtj|�S)zt
        Opening a file in a monitored directory sends an
        C{inotify.IN_OPEN} event to the callback.
        c�B�|jd�j�yr]r^rIs rrBz)INotifyTests.test_open.<locals>.operation�r`r)rCr	�IN_OPENrLs  r�	test_openzINotifyTests.test_open�s ��	#��%�%�g�o�o�y�A�Arc�N���fd�}�jtj|�S)z}
        Moving a file out of a monitored directory sends an
        C{inotify.IN_MOVED_FROM} event to the callback.
        c���|jd�j�|jtj�j���yr])rQr_�moveTorrr�rJrs �rrBz.INotifyTests.test_movedFrom.<locals>.operation�s4����I�I�c�N� � �"��K�K��)�)�$�+�+�-�8�9r)rCr	�
IN_MOVED_FROMrLs` r�test_movedFromzINotifyTests.test_movedFrom�s#���	:��%�%�g�&;�&;�Y�G�Grc�N���fd�}�jtj|�S)zy
        Moving a file into a monitored directory sends an
        C{inotify.IN_MOVED_TO} event to the callback.
        c���tj�j��}|j�|j	|�yr
)rrrrXrn)rJ�prs  �rrBz,INotifyTests.test_movedTo.<locals>.operation�s-����!�!�$�+�+�-�0�A�
�G�G�I�
�H�H�T�Nr)rCr	�IN_MOVED_TOrLs` r�test_movedTozINotifyTests.test_movedTo�s#���	�
�%�%�g�&9�&9�9�E�Erc�H�d�}|jtj|�S)zw
        Creating a file in a monitored directory sends an
        C{inotify.IN_CREATE} event to the callback.
        c�B�|jd�j�yr]r^rIs rrBz+INotifyTests.test_create.<locals>.operation�r`r)rCr	�	IN_CREATErLs  r�test_createzINotifyTests.test_create�s"��	#��%�%�g�&7�&7��C�Crc�H�d�}|jtj|�S)zw
        Deleting a file in a monitored directory sends an
        C{inotify.IN_DELETE} event to the callback.
        c�D�|j�|j�yr
)rX�removerIs rrBz+INotifyTests.test_delete.<locals>.operation�s���J�J�L��K�K�Mr)rCr	�	IN_DELETErLs  r�test_deletezINotifyTests.test_delete�s"��	��%�%�g�&7�&7��C�Crc�`�d�}|jtj||j��S)z{
        Deleting the monitored directory itself sends an
        C{inotify.IN_DELETE_SELF} event to the callback.
        c�$�|j�yr
)r}rIs rrBz/INotifyTests.test_deleteSelf.<locals>.operation�s���K�K�Mr�r3)rCr	�IN_DELETE_SELFrrLs  r�test_deleteSelfzINotifyTests.test_deleteSelf�s2��	��%�%��"�"�I�D�L�L�&�
�	
rc������fd�}�jj�jd�fd�g��tj���j|��jj
��S)z�
        Deleting the monitored directory itself sends an
        C{inotify.IN_DELETE_SELF} event to the callback
        even if the mask isn't specified by the call to watch().
        c����|\}}}�j|j��jj���j|tj
z�yr
)r,r-rr.r	r�)r/r0r1r2rs    �rr5z6INotifyTests.test_deleteSelfForced.<locals>.cbNotified�sL���(.�%�U�H�f����X�1�1�3�T�\�\�5M�5M�5O�P��O�O�F�W�%;�%;�;�<rrc�&���j|�Sr
r7)r:�ds �rr<z4INotifyTests.test_deleteSelfForced.<locals>.<lambda>�s���Q�Z�Z��=M�rr=)r	r0rrr@rAr})rr5r�s` @r�test_deleteSelfForcedz"INotifyTests.test_deleteSelfForced�s_���	=�
	
������L�L�s�/M�.N�	�	
�
�N�N���	�
�
�j�!��������rc�f���fd�}�jtj|�j��S)zy
        Renaming the monitored directory itself sends an
        C{inotify.IN_MOVE_SELF} event to the callback.
        c�j��|jtj�j���yr
)rnrrrros �rrBz-INotifyTests.test_moveSelf.<locals>.operation�s ����K�K��)�)�$�+�+�-�8�9rr�)rCr	�IN_MOVE_SELFrrLs` r�
test_moveSelfzINotifyTests.test_moveSelf�s3���	:��%�%�� � �)�$�,�,�&�
�	
rc�.�������fd�}tjtjz}�jj�j|d|g���jjd��t
j���j��S)z�
        L{inotify.INotify} when initialized with autoAdd==True adds
        also adds the created subdirectories to the watchlist.
        c�@�����fd�}tjd|�y)Nc���	�j�jj����jd�y#t$r�j�YywxYwr
)r.r	�
_isWatchedr8�	Exception�errback�r�r�subdirs���r�_zIINotifyTests.test_simpleSubdirectoryAutoAdd.<locals>._callback.<locals>._	sG��� ��O�O�D�L�L�$;�$;�F�$C�D��J�J�t�$�� � ��I�I�K� ���;?�A�Ar�r�	callLater)�wpr1r4r�r�rr�s    ���r�	_callbackz>INotifyTests.test_simpleSubdirectoryAutoAdd.<locals>._callback����
 �
���a��#rT�r4�autoAddr>�test�	r	�IN_ISDIRryr0rr?rr@r�rr��	checkMaskr�r�s`  @@r�test_simpleSubdirectoryAutoAddz+INotifyTests.test_simpleSubdirectoryAutoAddsy���
	$��$�$�w�'8�'8�8�	�������L�L�y�$�9�+�	�	
����#�#�F�+���N�N������ ��rc�6�����g�����fd�}tjtjz}�jj�j|d|g���jjd��t
j���j��S)zz
        L{inotify.INotify} removes a directory from the watchlist when
        it's removed from the filesystem.
        c������fd�}���fd�}�s(�j|�tjd|�ytjd|�y)Nc���	�j�jj����j�y#t$r�j�YywxYwr
)r.r	r�r}r�r�r�s���rr�zEINotifyTests.test_simpleDeleteDirectory.<locals>._callback.<locals>._%sD��� ��O�O�D�L�L�$;�$;�F�$C�D��M�M�O�� � ��I�I�K� �s�:>�A�Ac���	�j�jj����jd�y#t$r�j�YywxYwr
��assertFalser	r�r8r�r�r�s���r�_ebzGINotifyTests.test_simpleDeleteDirectory.<locals>._callback.<locals>._eb,sI��� ��$�$�T�\�\�%<�%<�V�%D�E��J�J�t�$�� � ��I�I�K� �r�r)�appendrr�)	r�r1r4r�r��callsr�rr�s	     ����rr�z:INotifyTests.test_simpleDeleteDirectory.<locals>._callback"s@���
 �
 �����X�&��!�!�!�Q�'��!�!�!�S�)rTr�r�r�)rr�r�r�r�r�s`  @@@r�test_simpleDeleteDirectoryz'INotifyTests.test_simpleDeleteDirectorys����
��	*�4�$�$�w�'8�'8�8�	�������L�L�y�$�9�+�	�	
����#�#�F�+���N�N������ ��rc�P������fd�}�j�jj�jtj�fd�g���tj���j|��jj�tj���S)z�
        L{inotify.INotify} closes the file descriptor after removing a
        directory from the filesystem (and therefore from the watchlist).
        c�����fd�}|\}}}�j|j��jj���j|tj
z�t
jd|�y)Nc���	�j�jj�j���j�jj��jd�y#t$r�j�YywxYwr
)r�r	r�r�	connectedr8r�r�)r�rs��rr�zIINotifyTests.test_deleteSelfLoseConnection.<locals>.cbNotified.<locals>._Lse��� ��$�$�T�\�\�%<�%<�T�\�\�%J�K��$�$�T�\�\�%;�%;�<��J�J�t�$�� � ��I�I�K� �s�A*A.�.B
�	B
r)r,r-rr.r	r�rr�)r/r��ignoredr1r2r�rs     ��rr5z>INotifyTests.test_deleteSelfLoseConnection.<locals>.cbNotifiedKsc���
 �+1�'�W�h�����X�1�1�3�T�\�\�5M�5M�5O�P��O�O�F�W�%;�%;�;�<����a��#rc�&���j|�Sr
r7r9s �rr<z<INotifyTests.test_deleteSelfLoseConnection.<locals>.<lambda>]s����):�):�4�)@�rr=)	r.r	r0rr�rr@rAr})rr5r�r;s` @@r�test_deleteSelfLoseConnectionz*INotifyTests.test_deleteSelfLoseConnectionEs����	$�	
����L�L�������+�+�@�A�
�
�	
��>�>�#�����Z�(��������N�N����rc�l�|jj|jd��|j|jj	|j��|jj|j�|j
|jj	|j��y)zR
        L{inotify.INotify.ignore} removes a directory from the watchlist
        T)r�N)r	r0rr.r��ignorer�rs r�test_ignoreDirectoryz!INotifyTests.test_ignoreDirectoryhsu��	
�����4�<�<���6�������/�/����=�>������D�L�L�)�������0�0����>�?rc�H�tjD]-\}}|jtj|�d|��/tjtj
ztjz}|jttj|��hd��y)zy
        L{inotify.humaReadableMask} translates all the possible event
        masks to a human readable string.
        r>rQ�access�close_writeN)r	�_FLAG_TO_HUMANr,�humanReadableMaskrarKrj�set)rr4�valuer�s    r�test_humanReadableMaskz#INotifyTests.test_humanReadableMaskqs���
#�1�1�	H�K�D�%����W�6�6�t�<�Q�?��G�	H��*�*�W�->�->�>����P�	������)�)�)�4�5�-�	
rc��|jjd�}|jd�}|jd�}|j�|||g}|jj	|jd��|jj	|jd��|D],}|j|jj
|���.y)z�
        L{inotify.INotify.watch} with recursive==True will add all the
        subdirectories under the given path to the watchlist.
        r��test2�test3T)�	recursiveN)rr?�makedirsr	r0r.r�)rr��subdir2�subdir3�dirsr�s      r�test_recursiveWatchz INotifyTests.test_recursiveWatchs���
���#�#�F�+���,�,�w�'���-�-��(���������)�������4�<�<�4��8������4�<�<�4��8��	8�A��O�O�D�L�L�3�3�A�6�7�	8rc��ddl}tj�}|j|j�|j�|j
�y)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)�osr	rr_�_fdr�flushLoggedErrors)rr��in_s   r�test_connectionLostErrorz%INotifyTests.test_connectionLostError�s;��
	��o�o���
�������������� rc�.�������fd�}tjtjz}�jj�j|d|g���jjd��t
j���j��S)z�
        L{inotify.INotify.watch} with autoAdd==False will stop inotify
        from watching subdirectories created under the watched one.
        c�@�����fd�}tjd|�y)Nc���	�j�jj����jd�y#t$r�j�YywxYwr
r�r�s���rr�zEINotifyTests.test_noAutoAddSubdirectory.<locals>._callback.<locals>._�sI��� ��$�$�T�\�\�%<�%<�V�%D�E��J�J�t�$�� � ��I�I�K� �r�rr�)r��fpr4r�r�rr�s    ���rr�z:INotifyTests.test_noAutoAddSubdirectory.<locals>._callback�r�rFr�r�r�r�s`  @@r�test_noAutoAddSubdirectoryz'INotifyTests.test_noAutoAddSubdirectory�sy���
	$��$�$�w�'8�'8�8�	�������L�L�y�%�I�;�	�	
����#�#�F�+���N�N������ ��rc�������jjd���j�tj����fd�}�fd�}�j�jj�|g����jj���j�jj�tj|g����j|��j��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.bar2c���|\}}}�j|j��j���j|tjz�yr
�r,r-r.r	r�)r/r�r1r2r3rs    ��rr5z<INotifyTests.test_seriesOfWatchAndIgnore.<locals>.cbNotified�sH���*0�'�W�h�����X�1�1�3�\�5M�5M�5O�P��O�O�F�W�%;�%;�;�<rc�(���j|�yr
r7r9s �r�callItz8INotifyTests.test_seriesOfWatchAndIgnore.<locals>.callIt��������d�#r�r>r=)rr?rXrr@r.r	r0r�r�rAr})rr5r�r3r;s`  @@r�test_seriesOfWatchAndIgnorez(INotifyTests.test_seriesOfWatchAndIgnore�s����
�|�|�)�)�*�5�������>�>�#��	=�
	$�	
������*�*�<�F�8�*�L�M������L�)�����L�L����7�#9�#9�f�X�
�
�	
�	���Z�(�	�����rc�~�����jjd�}|j��jjd���j�tj����fd�}�fd�}�j�jj|tj|g����j|��j�jj�tj|g����jj|�|j��j��S)zr
        L{inotify.INotify} will ignore a filepath after it has been removed from
        the watch list.
        r�zfoo.bar3c���|\}}}�j|j��j���j|tjz�yr
r�)r/r�r1r2�
expectedPath2rs    ��rr5z4INotifyTests.test_ignoreFilePath.<locals>.cbNotified�sH���*0�'�W�h�����X�1�1�3�]�5N�5N�5P�Q��O�O�F�W�%;�%;�;�<rc�(���j|�yr
r7r9s �rr�z0INotifyTests.test_ignoreFilePath.<locals>.callIt�r�rr�)rr?rXrr@r.r	r0r�rAr�r})rr3r5r�r�r;s`   @@r�test_ignoreFilePathz INotifyTests.test_ignoreFilePath�s����
�|�|�)�)�*�5���������*�*�:�6�
������>�>�#��	=�
	$�	
����L�L���|�W�-C�-C�PV�x��X�	
�	���Z�(�����L�L����w�5�5�&��
�
�	
�	
�����L�)����������rc��|jjd�}|j�|jt|j
j|�y)zf
        L{inotify.INotify} will raise KeyError if a non-watched filepath is
        ignored.
        zfoo.ignoredN)rr?rXr(�KeyErrorr	r�)rr3s  r�test_ignoreNonWatchedFilez&INotifyTests.test_ignoreNonWatchedFiles@��
�|�|�)�)�-�8���������(�D�L�L�$7�$7��Frc�������	�
�t��������	�
fd�}tjtjz}�jj	�j
|d|g���j
j
d���j
d��	�	j
d��
tj���
j��j
d��	j
d��
j
d	�g�t��D]A\}}|j|jjtj����C�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.
        c�d���j|�t��dk(r�	�j�jj	�	���j�jj	�
���j�jj	�����	�
�gz}|D�chc]}|j���}}�j
t��t|���j
�|��jd�yycc}w#t$r�j�YywxYw)N�)
�add�lenr.r	r�r-r,r8r�r�)r�r1r4�created�fr�r�r�	someFilesr�r�r�s     �������rr�z?INotifyTests.test_complexSubdirectoryAutoAdd.<locals>._callbacks�����I�I�h���5�z�Q��%��O�O�D�L�L�$;�$;�F�$C�D��O�O�D�L�L�$;�$;�G�$D�E��O�O�D�L�L�$;�$;�G�$D�E�'�6�7�G�*D�D�G�8?�@�1�q�}�}��@�G�@��$�$�S��Z��W��>��$�$�U�G�4��J�J�t�$���A��!� ��I�I�K� �s$�B
D�,D�8D�D�D/�.D/Tr�r�r�r�z	file1.datz	file2.datz	file3.dat)r�r	r�ryr0rr?rr@r��	enumeraterGrJ�encode�sys�getfilesystemencoding)rr�r��ir1r�r�r�r�r�r�s`    @@@@@@r�test_complexSubdirectoryAutoAddz,INotifyTests.test_complexSubdirectoryAutoAdds������	%�	%� �$�$�w�'8�'8�8�	�������L�L�y�$�9�+�	�	
����#�#�F�+���,�,�w�'���-�-��(���N�N�������
�L�L��%��M�M�+�&��M�M�+�&�
�	�%�Y�/�	S�K�A�x�����
�
� 4� 4�S�5N�5N�5P� Q�R�	S��rr
)$r!r"r#�__doc__r�platform�supportsINotify�skiprr)rCrMrUrZrbrgrkrqrvrzrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r$rrrrs����
���+�+�-�7��5�A� "�H
D�
D�
D�
I�K�	B�
H�F�	D�
D�
��,
��6(�T!�F@�
�8� 
!��6#�J$�LG�.rr)r�r��twisted.internetrr�twisted.pythonrr�twisted.python.reflectr�
twisted.trialrr	�TestCaserr$rr�<module>r�sC����+�,�0�"��*�+�7�(��G�e�8�$�$�er

Zerion Mini Shell 1.0