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 Nr   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   