o
    ¯b~  ã                   @   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	y'   dZ
Y nw eZ
e
rGe ¡ rGd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u 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   ó"   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                   @   ó   e Zd Zdd„ Zdd„ ZdS )z+INotifyTests.test_missingInit.<locals>.libcc                 S   ó   d S ©N© ©Úselfr   r   úB/usr/lib/python3/dist-packages/twisted/python/test/test_inotify.pyÚinotify_add_watch*   ó   z=INotifyTests.test_missingInit.<locals>.libc.inotify_add_watchc                 S   r   r   r   r   r   r   r   Úinotify_rm_watch-   r   z<INotifyTests.test_missingInit.<locals>.libc.inotify_rm_watchN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   Úlibc)   ó    r   N©ÚassertRaisesÚImportErrorr   ©r   r   r   r   r   Útest_missingInit#   ó   zINotifyTests.test_missingInitc                 C   r   )zŽ
        If the I{libc} object passed to L{initializeModule} has no
        C{inotify_add_watch} attribute, L{ImportError} is raised.
        c                   @   r   )z*INotifyTests.test_missingAdd.<locals>.libcc                 S   r   r   r   r   r   r   r   Úinotify_init9   r   z7INotifyTests.test_missingAdd.<locals>.libc.inotify_initc                 S   r   r   r   r   r   r   r   r   <   r   z;INotifyTests.test_missingAdd.<locals>.libc.inotify_rm_watchN)r   r   r   r$   r   r   r   r   r   r   8   r   r   Nr   r!   r   r   r   Útest_missingAdd2   r#   zINotifyTests.test_missingAddc                 C   r   )z�
        If the I{libc} object passed to L{initializeModule} has no
        C{inotify_rm_watch} attribute, L{ImportError} is raised.
        c                   @   r   )z-INotifyTests.test_missingRemove.<locals>.libcc                 S   r   r   r   r   r   r   r   r$   H   r   z:INotifyTests.test_missingRemove.<locals>.libc.inotify_initc                 S   r   r   r   r   r   r   r   r   K   r   z?INotifyTests.test_missingRemove.<locals>.libc.inotify_add_watchN)r   r   r   r$   r   r   r   r   r   r   G   r   r   Nr   r!   r   r   r   Útest_missingRemoveA   r#   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   r   r   r   r   r   r   r   r$   X   r   z5INotifyTests.test_setTypes.<locals>.libc.inotify_initc                 S   r   r   r   r   r   r   r   r   ]   r   z9INotifyTests.test_setTypes.<locals>.libc.inotify_rm_watchc                 S   r   r   r   r   r   r   r   r   b   r   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                   @   ó   e Zd Zdd„ ZdS )z*INotifyTests.test_failedInit.<locals>.libcc                 S   ó   dS ©Néÿÿÿÿr   r   r   r   r   r$   y   r   z7INotifyTests.test_failedInit.<locals>.libc.inotify_initN)r   r   r   r$   r   r   r   r   r   x   ó    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                   @   r-   )z.INotifyTests.test_failedAddWatch.<locals>.libcc                 S   r.   r/   r   )r   ÚfdÚpathÚmaskr   r   r   r   †   r   z@INotifyTests.test_failedAddWatch.<locals>.libc.inotify_add_watchN)r   r   r   r   r   r   r   r   r   …   r1   r   é   z/foor   N)r2   r3   r   r	   r
   r   r!   r   r   r   Útest_failedAddWatch   s   z INotifyTests.test_failedAddWatch)r   r   r   Ú__doc__r3   Úskipr"   r%   r&   r,   r4   r9   r   r   r   r   r      s    "r   )r:   Útwisted.python.filepathr   Útwisted.python.runtimer   Útwisted.trial.unittestr   Útwisted.pythonr   r    r3   ÚsupportsINotifyÚctypesr   r   r   Útwisted.python._inotifyr	   r
   r   r   r   r   r   r   r   Ú<module>   s   ÿ