U
    c6{iu  ã                   @  s¤   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZ ddlmZ G dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )zJ
Tests for the insults windowing module, L{twisted.conch.insults.window}.
é    )Úannotations)ÚCallable)ÚServerProtocol)ÚScrolledAreaÚ	SelectionÚ
TextOutputÚ	TopWindowÚWidget)ÚTestCasec                   @  s   e Zd ZdZddœdd„ZdS )ÚTopWindowTestszB
    Tests for L{TopWindow}, the root window container class.
    ÚNone©Úreturnc                   sÎ   g ‰ g }t ‡ fdd„|jƒ}|  ˆ g ¡ |  |g ¡ | ¡  |  ˆ g ¡ |  t|ƒd¡ | ¡  |  ˆ g ¡ |  t|ƒd¡ | ¡ ƒ  |  tˆ ƒd¡ |  |g ¡ | ¡  |  tˆ ƒd¡ |  t|ƒd¡ dS )z”
        Verify that L{TopWindow.repaint} schedules an actual paint to occur
        using the scheduling object passed to its initializer.
        c                     s
   ˆ   d ¡S ©N)Úappend© ©Zpaintsr   úB/tmp/pip-unpacked-wheel-hfbvu0bz/twisted/conch/test/test_window.pyÚ<lambda>   ó    z5TopWindowTests.test_paintScheduling.<locals>.<lambda>é   N)r   r   ÚassertEqualZrepaintÚlenÚpop)ÚselfZ	scheduledÚrootr   r   r   Útest_paintScheduling   s"    
z#TopWindowTests.test_paintSchedulingN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   r   c                   @  s   e Zd ZdZddœdd„ZdS )ÚScrolledAreaTestsz—
    Tests for L{ScrolledArea}, a widget which creates a viewport containing
    another widget and can reposition that viewport using scrollbars.
    r   r   c                 C  s2   t ƒ }t|ƒ}|  |j|j¡ |  |jj|¡ dS )zÌ
        The parent of the widget passed to L{ScrolledArea} is set to a new
        L{Viewport} created by the L{ScrolledArea} which itself has the
        L{ScrolledArea} instance as its parent.
        N)r   r   ÚassertIsÚparentZ	_viewport)r   ÚwidgetZscrolledr   r   r   Útest_parentB   s    zScrolledAreaTests.test_parentN)r   r   r   r    r%   r   r   r   r   r!   <   s   r!   c                   @  sV   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„Zddœdd„ZdS )ÚSelectionTestszC
    Change focused entry in L{Selection} using function keys.
    r   r   c                 C  s2   dd„ t dƒD ƒ}t|dƒ| _d| j_d| j_dS )zg
        Create L{ScrolledArea} widget with 10 elements and position selection to 5th element.
        c                 S  s   g | ]}|›   d ¡‘qS )Úascii)Úencode)Ú.0Z_numr   r   r   Ú
<listcomp>W   s     z(SelectionTests.setUp.<locals>.<listcomp>é
   Né   )Úranger   r$   ÚheightÚfocusedIndex)r   Úseqr   r   r   ÚsetUpS   s    zSelectionTests.setUpc                 C  s$   | j  tjd¡ |  | j jd¡ dS )zO
        Send DOWN_ARROW to select element just below the current one.
        Né   )r$   ÚkeystrokeReceivedr   Ú
DOWN_ARROWr"   r/   ©r   r   r   r   Útest_selectionDownArrow\   s    z&SelectionTests.test_selectionDownArrowc                 C  s$   | j  tjd¡ |  | j jd¡ dS )zM
        Send UP_ARROW to select element just above the current one.
        Né   )r$   r3   r   ÚUP_ARROWr"   r/   r5   r   r   r   Útest_selectionUpArrowc   s    z$SelectionTests.test_selectionUpArrowc                 C  s$   | j  tjd¡ |  | j jd¡ dS )zQ
        Send PGDN to select element one page down (here: last element).
        Né	   )r$   r3   r   ÚPGDNr"   r/   r5   r   r   r   Útest_selectionPGDNj   s    z!SelectionTests.test_selectionPGDNc                 C  s$   | j  tjd¡ |  | j jd¡ dS )zP
        Send PGUP to select element one page up (here: first element).
        Nr   )r$   r3   r   ÚPGUPr"   r/   r5   r   r   r   Útest_selectionPGUPq   s    z!SelectionTests.test_selectionPGUPN)	r   r   r   r    r1   r6   r9   r<   r>   r   r   r   r   r&   N   s   	r&   c                   @  s~   e Zd ZdZddœdd„Zdddœdd	„Zdddœd
d„Zdddœdd„Zdddœdd„Zdddœdd„Z	dddœdd„Z
dS )ÚRecordingWidgetzn
    A dummy Widget implementation to test handling of function keys by
    recording keyReceived events.
    r   r   c                 C  s   t  | ¡ g | _d S r   )r	   Ú__init__Ú	triggeredr5   r   r   r   r@      s    
zRecordingWidget.__init__Ústr)Úmodifierr   c                 C  s   | j  d¡ d S )NÚF1©rA   r   ©r   rC   r   r   r   Úfunc_F1ƒ   s    zRecordingWidget.func_F1c                 C  s   | j  d¡ d S )NÚHOMErE   rF   r   r   r   Ú	func_HOME†   s    zRecordingWidget.func_HOMEc                 C  s   | j  d¡ d S )Nr4   rE   rF   r   r   r   Úfunc_DOWN_ARROW‰   s    zRecordingWidget.func_DOWN_ARROWc                 C  s   | j  d¡ d S )Nr8   rE   rF   r   r   r   Úfunc_UP_ARROWŒ   s    zRecordingWidget.func_UP_ARROWc                 C  s   | j  d¡ d S )Nr;   rE   rF   r   r   r   Ú	func_PGDN�   s    zRecordingWidget.func_PGDNc                 C  s   | j  d¡ d S )Nr=   rE   rF   r   r   r   Ú	func_PGUP’   s    zRecordingWidget.func_PGUPN)r   r   r   r    r@   rG   rI   rJ   rK   rL   rM   r   r   r   r   r?   y   s   r?   c                   @  s   e Zd ZdZddœdd„ZdS )ÚWidgetFunctionKeyTestszN
    Call functionKeyReceived with key values from insults.ServerProtocol
    r   r   c                   sP   t ƒ ‰dddœ‡ ‡fdd„}|dƒ |dƒ |dƒ |d	ƒ |d
ƒ |dƒ dS )zŒ
        L{Widget.functionKeyReceived} dispatches its input, a constant on
        ServerProtocol, to a matched C{func_KEY} method.
        rB   r   )Úkeyr   c                   s0   ˆ  tt| ƒd ¡ ˆ  | gˆj¡ ˆj ¡  d S r   )ZfunctionKeyReceivedÚgetattrr   r   rA   Úclear)rO   ©r   r$   r   r   ÚcheckOneKey¢   s    zLWidgetFunctionKeyTests.test_functionKeyReceivedDispatch.<locals>.checkOneKeyrD   rH   r4   r8   r;   r=   N)r?   )r   rS   r   rR   r   Ú test_functionKeyReceivedDispatch›   s    z7WidgetFunctionKeyTests.test_functionKeyReceivedDispatchN)r   r   r   r    rT   r   r   r   r   rN   –   s   rN   N)r    Ú
__future__r   Útypingr   Ztwisted.conch.insults.insultsr   Ztwisted.conch.insults.windowr   r   r   r   r	   Ztwisted.trial.unittestr
   r   r!   r&   r?   rN   r   r   r   r   Ú<module>   s   )+