U
    
W[7                     @   s   d Z ddlmZ ddlmZ ddlmZ e rjddlm	Z	m
Z
mZ ddl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}.
    )TestCase)FilePath)platform)c_intc_uint32c_char_p)_inotify)INotifyErrorinitializeModuleinitaddNc                   @   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   B/usr/lib/python3/dist-packages/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_init0   s    z7INotifyTests.test_missingAdd.<locals>.libc.inotify_initc                 S   s   d S r   r   r   r   r   r   r   2   s    z;INotifyTests.test_missingAdd.<locals>.libc.inotify_rm_watchN)r   r   r   r   r   r   r   r   r   r   /   s   r   Nr   r   r   r   r   test_missingAdd*   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   =   s    z:INotifyTests.test_missingRemove.<locals>.libc.inotify_initc                 S   s   d S r   r   r   r   r   r   r   ?   s    z?INotifyTests.test_missingRemove.<locals>.libc.inotify_add_watchN)r   r   r   r   r   r   r   r   r   r   <   s   r   Nr   r   r   r   r   test_missingRemove7   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   K   s    z5INotifyTests.test_setTypes.<locals>.libc.inotify_initc                 S   s   d S r   r   r   r   r   r   r   O   s    z9INotifyTests.test_setTypes.<locals>.libc.inotify_rm_watchc                 S   s   d S r   r   r   r   r   r   r   S   s    z:INotifyTests.test_setTypes.<locals>.libc.inotify_add_watchN)r   r   r   r   staticmethodr   r   r   r   r   r   r   J   s   r   N)
r
   ZassertEqualr   ZargtypesZrestyper   r   r   r   r   )r   r   cr   r   r   test_setTypesD   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 Nr   r   r   r   r   r   j   s    z7INotifyTests.test_failedInit.<locals>.libc.inotify_initN)r   r   r   r   r   r   r   r   r   i   s   r   N)patchr   r   r	   r   r   r   r   r   test_failedInitd   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   v   s    z@INotifyTests.test_failedAddWatch.<locals>.libc.inotify_add_watchN)r   r   r   r   r   r   r   r   r   u   s   r      z/foor   N)r&   r   r   r	   r   r   r   r   r   r   test_failedAddWatchp   s    z INotifyTests.test_failedAddWatch)r   r   r   __doc__r   skipr   r   r    r#   r'   r,   r   r   r   r   r      s    r   )r-   Ztwisted.trial.unittestr   Ztwisted.python.filepathr   Ztwisted.python.runtimer   ZsupportsINotifyZctypesr   r   r   Ztwisted.pythonr   Ztwisted.python._inotifyr	   r
   r   r   r   r   r   r   r   <module>   s   