%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f&>����dZddlmZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZd
ZdZej(�re
d��e
d
��dZdZGd�de�ZGd�de�Zy)z'
Tests for L{twisted.python.lockfile}.
�)�annotationsN)�skipIf�
skipUnless)�NoReturn)�lockfile)�
requireModule)�platform)�TestCaseF�zwin32api.OpenProcess�
pywintypesTzZOn windows, lockfile.kill is not implemented in the absence of win32api and/or pywintypes.c���eZdZdZdd�Zeej�d�dd��Zdd�Z	eej�d�dd��Z
eee
�dd��Zeee
�dd	��Zdd
�Zy)
�	UtilTestszM
    Tests for the helper functions used to implement L{FilesystemLock}.
    c���|j�}tjd|�|jttjd|�}|j|jtj�y)z�
        L{lockfile.symlink} raises L{OSError} with C{errno} set to L{EEXIST}
        when an attempt is made to create a symlink which already exists.
        �fooN)�mktempr�symlink�assertRaises�OSError�assertEqual�errno�EEXIST��self�name�excs   �</usr/lib/python3/dist-packages/twisted/test/test_lockfile.py�test_symlinkEEXISTzUtilTests.test_symlinkEEXIST(sS��
�{�{�}�������%������)9�)9�5�$�G��������E�L�L�1��Bspecial rename EIO handling only necessary and correct on Windows.c��|j�}dd�}|jtd|�|jttj
|d�}|j
|jtj�y)a<
        L{lockfile.symlink} raises L{OSError} with C{errno} set to L{EIO} when
        the underlying L{rename} call fails with L{EIO}.

        Renaming a file on Windows may fail if the target of the rename is in
        the process of being deleted (directory deletion appears not to be
        atomic).
        c�6�ttjd���N�rr�EIO��src�dsts  r�
fakeRenamez4UtilTests.test_symlinkEIOWindows.<locals>.fakeRenameAs���%�)�)�T�*�*r�renamerN�r&�strr'r+�returnr)	r�patchrr�IOErrorrrrr$)rrr(rs    r�test_symlinkEIOWindowsz UtilTests.test_symlinkEIOWindows2sZ���{�{�}��	+�	
�
�
�8�X�z�2������)9�)9�4��G��������E�I�I�.rc���|j�}|jttj|�}|j|jtj�y)z�
        L{lockfile.readlink} raises L{OSError} with C{errno} set to L{ENOENT}
        when an attempt is made to read a symlink which does not exist.
        N)rrrr�readlinkrr�ENOENTrs   r�test_readlinkENOENTzUtilTests.test_readlinkENOENTHsA��
�{�{�}�������):�):�D�A��������E�L�L�1r�Gspecial readlink EACCES handling only necessary and correct on Windows.c��|j�}dd�}|jtd|�|jttj
|�}|j
|jtj�y)a\
        L{lockfile.readlink} raises L{OSError} with C{errno} set to L{EACCES}
        on Windows when the underlying file open attempt fails with C{EACCES}.

        Opening a file on Windows may fail if the path is inside a directory
        which is in the process of being deleted (directory deletion appears
        not to be atomic).
        c�6�ttjd��r"�rr�EACCES)�path�modes  r�fakeOpenz6UtilTests.test_readlinkEACCESWindows.<locals>.fakeOpen`����%�,�,��-�-r�_openN)r9r+r:r+r,r)	rr-rrr.r1rrr8)rrr;rs    r�test_readlinkEACCESWindowsz$UtilTests.test_readlinkEACCESWindowsQsX���{�{�}��	.�	
�
�
�8�W�h�/������):�):�D�A��������E�L�L�1rc�T�tjtj�d�y)z}
        L{lockfile.kill} returns without error if passed the PID of a
        process which exists and signal C{0}.
        rN)r�kill�os�getpid�rs r�	test_killzUtilTests.test_killgs��	�
�
�b�i�i�k�1�%rc��|jttjdd�}|j	|j
t
j�y)z�
        L{lockfile.kill} raises L{OSError} with errno of L{ESRCH} if
        passed a PID which does not correspond to any process.
        i���rN)rrrr@rr�ESRCH)rrs  r�test_killESRCHzUtilTests.test_killESRCHos6���������	�1�E��������E�K�K�0rc���|jtdd�tj|j��}|j	�|j|j	��y)z�
        Verify that when L{lockfile.kill} does end up as None (e.g. on Windows
        without pywin32), it doesn't end up being called and raising a
        L{TypeError}.
        r@N)r-r�FilesystemLockr�lock�assertFalse)r�fls  r�test_noKillCallzUtilTests.test_noKillCallysG��	
�
�
�8�V�T�*�
�
$�
$�T�[�[�]�
3��
���	��������#rN�r,�None)�__name__�
__module__�__qualname__�__doc__rrr	�	isWindowsr/r3r>r�skipKill�skipKillReasonrDrGrM�rrrr#s����2�������O��/�	�/�$2�������T��2�	�2�$�H�n�%�&�&�&��H�n�%�1�&�1�	$rrc��eZdZdd�Zdd�Zeej�d�dd��Zdd�Z	dd�Z
dd�Zdd�Zdd	�Z
eej�d
�dd��Zeej�d�dd
��Z						dd�Zdd�Zeej�d�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zy)�LockingTestsc���d�fd�}|jtd|�|j�}tj|�}|j	t
|j�}|j|j��y)Nc���t�d��r")r)�source�destrs  �r�fakeSymlinkz3LockingTests._symlinkErrorTest.<locals>.fakeSymlink�s����%��&�&rr)r\r+r]r+r,r)	r-rrrIrrrJrr)rrr^�lockfrJrs `    r�_symlinkErrorTestzLockingTests._symlinkErrorTest�s_���	'�	
�
�
�8�Y��4����
���&�&�u�-���������3��������E�*rc�B�|jtj�y)z�
        An exception raised by C{symlink} other than C{EEXIST} is passed up to
        the caller of L{FilesystemLock.lock}.
        N)r`r�ENOSYSrCs r�test_symlinkErrorzLockingTests.test_symlinkError�s��
	
���u�|�|�,rz9POSIX-specific error propagation not expected on Windows.c��|jtj�|jtj�y)a 
        An L{OSError} raised by C{symlink} on a POSIX platform with an errno of
        C{EACCES} or C{EIO} is passed to the caller of L{FilesystemLock.lock}.

        On POSIX, unlike on Windows, these are unexpected errors which cannot
        be handled by L{FilesystemLock}.
        N)r`rr8r$rCs r�test_symlinkErrorPOSIXz#LockingTests.test_symlinkErrorPOSIX�s(��	
���u�|�|�,����u�y�y�)rc��|j�}tj|�}|j|j	��|j|j
�|j|j�y)z�
        If the lock has never been held, it can be acquired and the C{clean}
        and C{locked} attributes are set to C{True}.
        N)rrrI�
assertTruerJ�clean�locked�rr_rJs   r�test_cleanlyAcquirez LockingTests.test_cleanlyAcquire�sQ��
���
���&�&�u�-������	�	��$�����
�
�#�������$rc��|j�}tj|�}|j|j	��|j�|j
|j�tj|�}|j|j	��|j|j�|j|j�y)z�
        If a lock is released cleanly, it can be re-acquired and the C{clean}
        and C{locked} attributes are set to C{True}.
        N)	rrrIrgrJ�unlockrKrirhrjs   r�test_cleanlyReleasez LockingTests.test_cleanlyRelease�s���
���
���&�&�u�-������	�	��$����
�������%��&�&�u�-������	�	��$�����
�
�#�������$rc�*�|j�}tj|�}|j|j	��tj|�}|j|j	��|j|j�y)zK
        If a lock is currently locked, it cannot be locked again.
        N)rrrIrgrJrKri)rr_�	firstLock�
secondLocks    r�test_cannotLockLockedz"LockingTests.test_cannotLockLocked�sk�����
���+�+�E�2�	����	���(�)��,�,�U�3�
�������*�+�����*�*�+rc���d�d�fd�}|j�}|jtd|�tjt	��|�tj
|�}|j
|j��|j|j�|j
|j�|jtj|�t	tj���y)z�
        If a lock was held by a process which no longer exists, it can be
        acquired, the C{clean} attribute is set to C{False}, and the
        C{locked} attribute is set to C{True}.
        i90c���|dk7rttjd��|�k(rttjd��y)Nr�rr�EPERMrF)�pid�signal�owners  �r�fakeKillz4LockingTests.test_uncleanlyAcquire.<locals>.fakeKill�s8�����{��e�k�k�4�0�0��e�|��e�k�k�4�0�0�rr@N�rw�intrxr|r,rO)rr-rrr+rIrgrJrKrhrirr1rArB)rrzr_rJrys    @r�test_uncleanlyAcquirez"LockingTests.test_uncleanlyAcquire�s������	1����
���
�
�8�V�X�.�����U��U�+��&�&�u�-������	�	��$�������$�������$�����*�*�5�1�3�r�y�y�{�3C�Drc����d��fd�}|jtd|��dd�}|jtd|�|j��tj��}tjtd���|j
|j��|j
|j�|j
|j�y)	z�
        If the lock is initially held but then released before it can be
        examined to determine if the process which held it still exists, it is
        acquired and the C{clean} and C{locked} attributes are set to C{True}.
        c�x��tj���j�tj|�Sr")r�rmlink�restorer1)rr_�
readlinkPatchs ��r�fakeReadlinkz?LockingTests.test_lockReleasedBeforeCheck.<locals>.fakeReadlink�s,����O�O�E�"��!�!�#��$�$�T�*�*rr1c��|dk7rttjd��|dk(rttjd��y�Nr�u�ru�rwrxs  rrzz;LockingTests.test_lockReleasedBeforeCheck.<locals>.fakeKill��7����{��e�k�k�4�0�0��e�|��e�k�k�4�0�0�rr@r�N)rr+r,r+r{�
r-rrrIrr+rgrJrhri)rr�rzrJr_r�s    @@r�test_lockReleasedBeforeCheckz)LockingTests.test_lockReleasedBeforeCheck�s����	+��
�
�8�Z��F�
�	1�	
�
�
�8�V�X�.����
���&�&�u�-������U��U�+�����	�	��$�����
�
�#�������$rrc��dd�}|jtd|�|j�}tj|�}|j	|j��|j	|j�y)a�
        If the lock is released while an attempt is made to acquire
        it, the lock attempt fails and C{FilesystemLock.lock} returns
        C{False}.  This can happen on Windows when L{lockfile.symlink}
        fails with L{IOError} of C{EIO} because another process is in
        the middle of a call to L{os.rmdir} (implemented in terms of
        RemoveDirectory) which is not atomic.
        c�6�ttjd��r"r#r%s  rr^zGLockingTests.test_lockReleasedDuringAcquireSymlink.<locals>.fakeSymlinks���%�)�)�T�*�*rrNr*)r-rrrIrKrJri)rr^r_rJs    r�%test_lockReleasedDuringAcquireSymlinkz2LockingTests.test_lockReleasedDuringAcquireSymlinksZ��	+�
	
�
�
�8�Y��4����
���&�&�u�-���������%�������%rr4c�6�dd�}|jtd|�|j�}tj|�}tjtd�|�|j
|j��|j
|j�y)z�
        If the lock is initially held but is released while an attempt
        is made to acquire it, the lock attempt fails and
        L{FilesystemLock.lock} returns C{False}.
        c�6�ttjd��r"r7�rs rr�zILockingTests.test_lockReleasedDuringAcquireReadlink.<locals>.fakeReadlink+s���%�,�,��-�-rr1r�N�rr+r,r)	r-rrrIrr+rKrJri)rr�r_rJs    r�&test_lockReleasedDuringAcquireReadlinkz3LockingTests.test_lockReleasedDuringAcquireReadlink sn��	.�	
�
�
�8�Z��6����
���&�&�u�-������U��U�+��������%�������%rc�r���d��fd�}|jtd|�|j�}tjt	d�|�tj
|�}|j
�|j�}|j|j��|j|j�y)Nc�����d��r"rW)rr�
exceptionTypes ��rr�z5LockingTests._readlinkErrorTest.<locals>.fakeReadlink<s�����t�,�,rr1r�r�)r-rrrr+rIrrJrrrKri)rr�rr�r_rJrs ``    r�_readlinkErrorTestzLockingTests._readlinkErrorTest9s����	-�	
�
�
�8�Z��6����
��	����U��U�+��&�&�u�-�����
�t�y�y�9��������E�*�������%rc��|jttj�|jttj�y)z�
        An exception raised by C{readlink} other than C{ENOENT} is passed up to
        the caller of L{FilesystemLock.lock}.
        N)r�rrrbr.rCs r�test_readlinkErrorzLockingTests.test_readlinkErrorKs,��
	
�������6��������6rc��|jttj�|jttj�y)z�
        Any L{IOError} raised by C{readlink} on a POSIX platform passed to the
        caller of L{FilesystemLock.lock}.

        On POSIX, unlike on Windows, these are unexpected errors which cannot
        be handled by L{FilesystemLock}.
        N)r�r.rrbr8rCs r�test_readlinkErrorPOSIXz$LockingTests.test_readlinkErrorPOSIXSs,��	
�������6��������6rc����d��fd�}|jtd|��dd�}|jtd|�|j��tj��}tjtd���|j
|j��|j
|j�|j
|j�y)	z�
        If a second process cleans up the lock after a first one checks the
        lock and finds that no process is holding it, the first process does
        not fail when it tries to clean up the lock.
        c�x���j�tj��tj|�Sr")r�rr�)rr_�rmlinkPatchs ��r�
fakeRmlinkz?LockingTests.test_lockCleanedUpConcurrently.<locals>.fakeRmlinkis*������!��O�O�E�"��?�?�4�(�(rr�c��|dk7rttjd��|dk(rttjd��yr�rur�s  rrzz=LockingTests.test_lockCleanedUpConcurrently.<locals>.fakeKillrr�rr@r�N)rr+r,rOr{r�)rr�rzrJr_r�s    @@r�test_lockCleanedUpConcurrentlyz+LockingTests.test_lockCleanedUpConcurrentlybs����	)��j�j��8�Z�@��	1�	
�
�
�8�V�X�.����
���&�&�u�-������U��U�+�����	�	��$�����
�
�#�������$rc���dd�}|jtd|�dd�}|jtd|�|j�}tjt	d�|�tj
|�}|j
t|j�}|j|jtj�|j|j�y)	z�
        An exception raised by L{rmlink} other than C{ENOENT} is passed up
        to the caller of L{FilesystemLock.lock}.
        c�6�ttjd��r")rrrbr�s rr�z1LockingTests.test_rmlinkError.<locals>.fakeRmlink�r<rr�c��|dk7rttjd��|dk(rttjd��yr�rur�s  rrzz/LockingTests.test_rmlinkError.<locals>.fakeKill�r�rr@r�Nr�r{)r-rrrr+rIrrrJrrrbrKri)rr�rzr_rJrs      r�test_rmlinkErrorzLockingTests.test_rmlinkError�s���	.�	
�
�
�8�X�z�2�	1�	
�
�
�8�V�X�.����
��	����U��U�+��&�&�u�-���������3��������E�L�L�1�������%rc��dd�}|jtd|�|j�}tjt	d�|�tj
|�}|j
t|j�}|j|jtj�|j|j�y)z�
        If L{kill} raises an exception other than L{OSError} with errno set to
        C{ESRCH}, the exception is passed up to the caller of
        L{FilesystemLock.lock}.
        c�6�ttjd��r")rrrvr�s  rrzz-LockingTests.test_killError.<locals>.fakeKill�s���%�+�+�t�,�,rr@r�N)rwr|rxr|r,r)r-rrrr+rIrrrJrrrvrKri)rrzr_rJrs     r�test_killErrorzLockingTests.test_killError�s���	-�	
�
�
�8�V�X�.����
��	����U��U�+��&�&�u�-���������3��������E�K�K�0�������%rc��|j�}tjtt	j
�dz�|�tj|�}|jt|j�y)z�
        L{FilesystemLock.unlock} raises L{ValueError} if called for a lock
        which is held by a different process.
        �N)
rrrr+rArBrIr�
ValueErrorrmrjs   r�test_unlockOtherzLockingTests.test_unlockOther�sR��
���
������R�Y�Y�[�1�_�-�u�5��&�&�u�-�����*�d�k�k�2rc��|j�}|jtj|��tj|�}|j|j
��|jtj|��|j�|jtj|��y)zp
        L{isLocked} returns C{True} if the named lock is currently locked,
        C{False} otherwise.
        N)rrKr�isLockedrIrgrJrmrjs   r�
test_isLockedzLockingTests.test_isLocked�s���
���
������*�*�5�1�2��&�&�u�-������	�	��$�����)�)�%�0�1����
�����*�*�5�1�2rN)rr|r,rOrN)r�ztype[OSError] | type[IOError]rr|r,rO)rPrQrRr`rcrr	rTrerkrnrrr}r�rr�r�r�r�r�r�r�r�r�r�rWrrrYrY�s	��	+�-�������C��	*�	�	*�	%�%� 
,�E�2%�>������O��&�	�&�,������T��&�	�&�*&�:�&�CF�&�	
�&�$7�������C��	7�	�	7�%�>&�:&�,3�3rrY)rS�
__future__rrrA�unittestrr�typingr�twisted.pythonr�twisted.python.reflectr�twisted.python.runtimer	�twisted.trial.unittestr
rUrVrTrrYrWrr�<module>r�s���
�#��	�'��#�0�+�+������8�����,�-�5��,�'�/���
<�	�_$��_$�DD3�8�D3r

Zerion Mini Shell 1.0