U
    ˆj~  ã                   @   s¨   d Z ddlmZ ddlmZ ddlmZ zddlmZ W n e	k
rP   dZ
Y nX eZ
e
r�e ¡ r�ddlmZmZmZ ddlmZmZmZmZ ndZ
G d	d
„ d
eƒZdS )z'
Tests for L{twisted.python._inotify}.
é    )ÚFilePath)Úplatform)ÚTestCase)Ú_inotifyN)Úc_char_pÚc_intÚc_uint32)ÚINotifyErrorÚaddÚinitÚinitializeModulec                   @   sL   e Zd ZdZedkrdZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ ZdS )ÚINotifyTestsz/
    Tests for L{twisted.python._inotify}.
    Nz&This platform doesn't support INotify.c                 C   s"   G dd„ dƒ}|   tt|ƒ ¡ dS )z‰
        If the I{libc} object passed to L{initializeModule} has no
        C{inotify_init} attribute, L{ImportError} is raised.
        c                   @   s   e Zd Zdd„ Zdd„ ZdS )z+INotifyTests.test_missingInit.<locals>.libcc                 S   s   d S ©N© ©Úselfr   r   úD/tmp/pip-unpacked-wheel-j5h_c8_q/twisted/python/test/test_inotify.pyÚinotify_add_watch*   s    z=INotifyTests.test_missingInit.<locals>.libc.inotify_add_watchc                 S   s   d S r   r   r   r   r   r   Úinotify_rm_watch-   s    z<INotifyTests.test_missingInit.<locals>.libc.inotify_rm_watchN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   Úlibc)   s   r   N©ÚassertRaisesÚImportErrorr   ©r   r   r   r   r   Útest_missingInit#   s    zINotifyTests.test_missingInitc                 C   s"   G dd„ dƒ}|   tt|ƒ ¡ dS )zŽ
        If the I{libc} object passed to L{initializeModule} has no
        C{inotify_add_watch} attribute, L{ImportError} is raised.
        c                   @   s   e Zd Zdd„ Zdd„ ZdS )z*INotifyTests.test_missingAdd.<locals>.libcc                 S   s   d S r   r   r   r   r   r   Úinotify_init9   s    z7INotifyTests.test_missingAdd.<locals>.libc.inotify_initc                 S   s   d S r   r   r   r   r   r   r   <   s    z;INotifyTests.test_missingAdd.<locals>.libc.inotify_rm_watchN)r   r   r   r   r   r   r   r   r   r   8   s   r   Nr   r   r   r   r   Útest_missingAdd2   s    zINotifyTests.test_missingAddc                 C   s"   G dd„ dƒ}|   tt|ƒ ¡ dS )z�
        If the I{libc} object passed to L{initializeModule} has no
        C{inotify_rm_watch} attribute, L{ImportError} is raised.
        c                   @   s   e Zd Zdd„ Zdd„ ZdS )z-INotifyTests.test_missingRemove.<locals>.libcc                 S   s   d S r   r   r   r   r   r   r   H   s    z:INotifyTests.test_missingRemove.<locals>.libc.inotify_initc                 S   s   d S r   r   r   r   r   r   r   K   s    z?INotifyTests.test_missingRemove.<locals>.libc.inotify_add_watchN)r   r   r   r   r   r   r   r   r   r   G   s   r   Nr   r   r   r   r   Útest_missingRemoveA   s    zINotifyTests.test_missingRemovec                 C   sŠ   G dd„ dƒ}|ƒ }t |ƒ |  |jjg ¡ |  |jjt¡ |  |jjttg¡ |  |jjt¡ |  |jjttt	g¡ |  |jjt¡ dS )zØ
        If the I{libc} object passed to L{initializeModule} has all of the
        necessary attributes, it sets the C{argtypes} and C{restype} attributes
        of the three ctypes methods used from libc.
        c                   @   s<   e Zd Zdd„ ZeeƒZdd„ ZeeƒZdd„ ZeeƒZdS )z(INotifyTests.test_setTypes.<locals>.libcc                 S   s   d S r   r   r   r   r   r   r   X   s    z5INotifyTests.test_setTypes.<locals>.libc.inotify_initc                 S   s   d S r   r   r   r   r   r   r   ]   s    z9INotifyTests.test_setTypes.<locals>.libc.inotify_rm_watchc                 S   s   d S r   r   r   r   r   r   r   b   s    z:INotifyTests.test_setTypes.<locals>.libc.inotify_add_watchN)r   r   r   r   Ústaticmethodr   r   r   r   r   r   r   W   s   r   N)
r   ÚassertEqualr   ÚargtypesÚrestyper   r   r   r   r   )r   r   Úcr   r   r   Útest_setTypesP   s    zINotifyTests.test_setTypesc                 C   s.   G dd„ dƒ}|   td|ƒ ¡ |  tt¡ dS )zg
        If C{inotify_init} returns a negative number, L{init} raises
        L{INotifyError}.
        c                   @   s   e Zd Zdd„ ZdS )z*INotifyTests.test_failedInit.<locals>.libcc                 S   s   dS ©Néÿÿÿÿr   r   r   r   r   r   y   s    z7INotifyTests.test_failedInit.<locals>.libc.inotify_initN)r   r   r   r   r   r   r   r   r   x   s   r   N)ÚpatchÚinotifyr   r	   r   r   r   r   r   Útest_failedInitr   s    zINotifyTests.test_failedInitc                 C   s8   G dd„ dƒ}|   td|ƒ ¡ |  ttdtdƒd¡ dS )zk
        If C{inotify_add_watch} returns a negative number, L{add}
        raises L{INotifyError}.
        c                   @   s   e Zd Zdd„ ZdS )z.INotifyTests.test_failedAddWatch.<locals>.libcc                 S   s   dS r'   r   )r   ÚfdÚpathÚmaskr   r   r   r   †   s    z@INotifyTests.test_failedAddWatch.<locals>.libc.inotify_add_watchN)r   r   r   r   r   r   r   r   r   …   s   r   é   z/foor   N)r)   r*   r   r	   r
   r   r   r   r   r   Útest_failedAddWatch   s    z INotifyTests.test_failedAddWatch)r   r   r   Ú__doc__r*   Úskipr   r   r    r&   r+   r0   r   r   r   r   r      s   "r   )r1   Ztwisted.python.filepathr   Ztwisted.python.runtimer   Ztwisted.trial.unittestr   Ztwisted.pythonr   r   r*   ZsupportsINotifyÚctypesr   r   r   Ztwisted.python._inotifyr	   r
   r   r   r   r   r   r   r   Ú<module>   s   
