U
    
W[P  ã                   @   sÆ   d dl mZ d dlmZmZmZmZ d dlmZmZ d dlm	Z	m
Z
mZmZmZ d dlmZ d dlmZ dZdZG d	d
„ d
ejƒZG dd„ dƒZG dd„ dƒZG dd„ dejƒZG dd„ dejƒZdS )é    )Úhelper)ÚG0ÚG1ÚG2ÚG3)ÚmodesÚprivateModes)ÚNORMALÚBOLDÚ	UNDERLINEÚBLINKÚREVERSE_VIDEO)Ú_PY3)ÚunittestéP   é   c                   @   s  e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"dAdB„ Z#dCdD„ Z$dES )FÚBufferTestsc                 C   s   t  ¡ | _| j ¡  d S ©N)r   ZTerminalBufferÚtermÚconnectionMade©Úself© r   ú@/usr/lib/python3/dist-packages/twisted/conch/test/test_helper.pyÚsetUp   s    
zBufferTests.setUpc                 C   sP   |   | jjt¡ |   | jjt¡ |   | j ¡ dtd  ¡ |   | j ¡ d¡ d S )Nó   
é   ©r   r   )ÚassertEqualr   ÚwidthÚWIDTHZheightÚHEIGHTÚ	__bytes__ÚreportCursorPositionr   r   r   r   ÚtestInitialState   s    
ÿzBufferTests.testInitialStatec                 C   s    |   tjdtjdi| jj¡ dS )zš
        Verify that only DEC Auto Wrap Mode (DECAWM) and DEC Text Cursor Enable
        Mode (DECTCEM) are initially in the Set Mode (SM) state.
        TN)r   r   Ú	AUTO_WRAPÚCURSOR_MODEr   r   r   r   r   Útest_initialPrivateModes   s     ÿýz$BufferTests.test_initialPrivateModesc                 C   sL   | j  d¡ | j  d¡ |  | j  ¡ d¡ | j  d¡ |  | j  ¡ d¡ dS )zQ
        C{""} moves the cursor to the first column in the current row.
        é   é   ©r(   r)   ó   ©r   r)   N)r   ÚcursorForwardÚ
cursorDownr   r#   ÚinsertAtCursorr   r   r   r   Útest_carriageReturn)   s
    zBufferTests.test_carriageReturnc                 C   s@   | j  d¡ |  | j  ¡ d¡ | j  d¡ |  | j  ¡ d¡ dS )zV
        C{"
"} moves the cursor to the next row without changing the column.
        r(   )r(   r   r   ©r(   r   N)r   r-   r   r#   r/   r   r   r   r   Útest_linefeed4   s    zBufferTests.test_linefeedc                 C   sL   | j  d¡ | j  d¡ |  | j  ¡ d¡ | j  d¡ |  | j  ¡ d¡ dS )z:
        C{write} transforms C{"
"} into C{"
"}.
        r(   r)   r*   r   ©r   é   N)r   r-   r.   r   r#   Úwriter   r   r   r   Útest_newline>   s
    zBufferTests.test_newlinec                 C   sH   | j j ¡ }| j  tjtjg¡ d|tj< d|tj< |  || j j¡ dS )z›
        Verify that L{helper.TerminalBuffer.setPrivateModes} changes the Set
        Mode (SM) state to "set" for the private modes it is passed.
        TN)r   r   ÚcopyZsetPrivateModesZSCROLLZSCREENr   ©r   Zexpectedr   r   r   Útest_setPrivateModesI   s
    

z BufferTests.test_setPrivateModesc                 C   sD   | j j ¡ }| j  tjtjg¡ |tj= |tj= |  || j j¡ dS )zŸ
        Verify that L{helper.TerminalBuffer.resetPrivateModes} changes the Set
        Mode (SM) state to "reset" for the private modes it is passed.
        N)r   r   r7   ZresetPrivateModesr%   r&   r   r8   r   r   r   Útest_resetPrivateModesU   s
    z"BufferTests.test_resetPrivateModesc                 C   sd   | j  d¡ |  | j  ¡ d¡ | j  ¡  |  | j  ¡ d¡ | j  t¡ |  | j  ¡ dtd f¡ d S )Nr)   r,   r3   r   r   )r   r.   r   r#   r!   r   r   r   r   ÚtestCursorDowna   s    
zBufferTests.testCursorDownc                 C   sj   | j  d¡ |  | j  ¡ d¡ | j  d¡ | j  d¡ |  | j  ¡ d¡ | j  d¡ |  | j  ¡ d¡ d S )Nr(   r   é   r   )r   é   r=   )r   ZcursorUpr   r#   r.   r   r   r   r   ÚtestCursorUpi   s    zBufferTests.testCursorUpc                 C   sb   | j  d¡ |  | j  ¡ d¡ | j  d¡ |  | j  ¡ d¡ | j  t¡ |  | j  ¡ tdf¡ d S )Né   )r?   r   )r4   r   r   )r   r-   r   r#   r    r   r   r   r   ÚtestCursorForwardt   s    zBufferTests.testCursorForwardc                 C   sˆ   | j  d¡ | j  d¡ |  | j  ¡ d¡ | j  d¡ |  | j  ¡ d¡ | j  d¡ |  | j  ¡ d¡ | j  d¡ |  | j  ¡ d¡ d S )Né
   r?   )é   r   é   )r   r   r   r   )r   r-   ÚcursorBackwardr   r#   r   r   r   r   ÚtestCursorBackward|   s    zBufferTests.testCursorBackwardc                 C   s$   | j  dd¡ |  | j  ¡ d¡ d S )Nr)   é	   )r)   rF   )r   ÚcursorPositionr   r#   r   r   r   r   ÚtestCursorPositioningˆ   s    z!BufferTests.testCursorPositioningc                 C   s6   d}| j  |¡ |  | j  ¡ |d dtd   ¡ d S )Nó   Hello, world.r   r?   )r   r5   r   r"   r!   ©r   Úsr   r   r   ÚtestSimpleWriting   s    
ÿþzBufferTests.testSimpleWritingc                 C   sn   d}| j  |¡ | j  t|ƒ¡ | j  tjg¡ | j  d¡ |  | j  ¡ d|dd …  d dt	d   ¡ d S )Ns   hello, world.ó   Hr   r   r?   )
r   r5   rD   ÚlenZ
resetModesr   ÚIRMr   r"   r!   rJ   r   r   r   ÚtestOvertype–   s    
ÿþzBufferTests.testOvertypec                 C   sf   d}| j  |¡ | j  t|ƒ¡ | j  tjg¡ | j  d¡ |  | j  ¡ d| d dt	d   ¡ d S )Ns   ello, world.rM   r   r?   )
r   r5   rD   rN   ZsetModesr   rO   r   r"   r!   rJ   r   r   r   Ú
testInsert¢   s    

ÿþzBufferTests.testInsertc                 C   s^   d}| j  d¡ | j  d¡ | j  |¡ |  | j  ¡ d| j jd  | d dtd   ¡ d S )NrI   r(   s   




r   rC   )r   r.   r-   r5   r   r"   Zfillr!   rJ   r   r   r   ÚtestWritingInTheMiddle®   s     
ÿÿÿ
þþz"BufferTests.testWritingInTheMiddlec                 C   sd   d}| j  td ¡ | j  |¡ |  | j  ¡ |d d…  t¡d |dd …  d dtd   ¡ d S )NrI   r(   r   r)   )r   r-   r    r5   r   r"   Úrjustr!   rJ   r   r   r   ÚtestWritingWrappedAtEndOfLineº   s    
ÿÿ
þþz)BufferTests.testWritingWrappedAtEndOfLinec                 C   sj   | j  ¡  |  | j  ¡ d¡ | j  t¡ |  | j  ¡ dtd f¡ | j  ¡  |  | j  ¡ dtd f¡ d S )N©r   r   r   r   )r   Úindexr   r#   r.   r!   r   r   r   r   Ú	testIndexÅ   s    

zBufferTests.testIndexc                 C   sZ   | j  ¡  |  | j  ¡ d¡ | j  d¡ |  | j  ¡ d¡ | j  ¡  |  | j  ¡ d¡ d S )Nr   r?   ©r   r?   rU   )r   ZreverseIndexr   r#   r.   r   r   r   r   ÚtestReverseIndexÎ   s    

zBufferTests.testReverseIndexc                 C   sZ   | j  ¡  |  | j  ¡ d¡ | j  d¡ |  | j  ¡ d¡ | j  ¡  |  | j  ¡ d¡ dS )zm
        C{nextLine} positions the cursor at the beginning of the row below the
        current row.
        rU   r(   r1   rX   N)r   ZnextLiner   r#   r-   r   r   r   r   Útest_nextLine×   s    

zBufferTests.test_nextLinec                 C   s~   | j  d¡ | j  d¡ |  | j  ¡ d¡ | j  ¡  | j  d¡ | j  d¡ |  | j  ¡ d¡ | j  ¡  |  | j  ¡ d¡ d S )Nr(   rC   )rC   r(   r)   )r4   é   )r   r.   r-   r   r#   Z
saveCursorrD   ZrestoreCursorr   r   r   r   ÚtestSaveCursorä   s    

zBufferTests.testSaveCursorc                 C   sð   | j  ¡  | j  d¡ | j  dd¡}|  |d d¡ |  |d jt¡ | j  dd¡}|  |d d¡ |  |d jt¡ | j  ¡  | j  d¡ | j  dd¡}|  |d d¡ |  |d jt	¡ | j  d	d¡}|  |d d¡ |  |d jt¡ d S )
Ns   Hir   rM   r   ó   is   !!r?   ó   !r)   )
r   ZsingleShift2r5   ÚgetCharacterr   Úcharsetr   r   ZsingleShift3r   ©r   Úchr   r   r   ÚtestSingleShiftsð   s     

zBufferTests.testSingleShiftsc           	   	   C   sÆ   d}d}d}| j  d¡ | j  ¡  | j  d¡ | j  ¡  | j  d¡ t}d}|||fD ]j}tt|ƒƒD ]@}| j  ||¡}|  |d |||d … ¡ |  |d j	|¡ qf|tkr´t
p¶t}|d7 }qVd S )	Ns   Hellos   Worlds   Bye!s   Hello
s   World
s   Bye!
r   r   )r   r5   ZshiftOutZshiftInr   ÚrangerN   r_   r   r`   r   )	r   Ús1Ús2Ús3ÚgÚhrK   Úirb   r   r   r   ÚtestShifting  s"    

zBufferTests.testShiftingc                 C   sâ  | j  tttt¡ | j  d¡ | j  t¡ | j  d¡ | j  t¡ | j  d¡ | j  t¡ | j  d¡ | j  dd¡}|  	|d d¡ |  
|d j¡ |  
|d j¡ |  
|d j¡ |  
|d j¡ | j  dd¡}|  	|d d¡ |  |d j¡ |  |d j¡ |  |d j¡ |  |d j¡ | j  dd¡}|  	|d d¡ |  
|d j¡ |  |d j¡ |  |d j¡ |  |d j¡ | j  dd¡}|  	|d d¡ |  
|d j¡ |  
|d j¡ |  |d j¡ |  |d j¡ d S )	Nó   Wó   Xó   Yó   Zr   r   r?   r)   )r   ÚselectGraphicRenditionr
   r   r   r   r5   r	   r_   r   Ú
assertTrueÚboldÚ	underlineÚblinkÚreverseVideoÚassertFalsera   r   r   r   ÚtestGraphicRendition  s@    z BufferTests.testGraphicRenditionc                 C   sÄ  d}d}| j  tjtj tjtj ¡ | j  |d ¡ | j  t¡ | j  |d ¡ t	t
|ƒƒD ]¨}| j  |d¡}|  |d |||d … ¡ |  |d jt¡ |  |d j¡ |  |d j¡ |  |d j¡ |  |d j¡ |  |d jtj¡ |  |d jtj¡ q^t	t
|ƒƒD ]ª}| j  |d¡}|  |d |||d … ¡ |  |d jt¡ |  |d j¡ |  |d j¡ |  |d j¡ |  |d j¡ |  |d jtj¡ |  |d jtj¡ qd S )Ns
   Merry xmass   Just kiddingr   r   r   )r   rp   r   Z
FOREGROUNDZREDZ
BACKGROUNDZGREENr5   r	   rd   rN   r_   r   r`   r   rv   rr   rs   rt   ru   Ú
foregroundZ
backgroundZWHITEZBLACK)r   re   rf   rj   rb   r   r   r   ÚtestColorAttributesD  s8    
ÿzBufferTests.testColorAttributesc                 C   sr   d}d}d}| j  d |||f¡d ¡ | j  dd¡ | j  ¡  |  | j  ¡ |d d | d dtd   ¡ d S )Ns   line 1s   line 2s   line 3r   r   r4   )r   r5   ÚjoinrG   Z	eraseLiner   r"   r!   ©r   re   rf   rg   r   r   r   ÚtestEraseLined  s$    
ÿþþ
ýþzBufferTests.testEraseLinec                 C   sT   d}| j  |¡ | j  d¡ | j  ¡  |  | j  ¡ |d d… d dtd   ¡ d S )NrI   r(   éûÿÿÿr   r?   )r   r5   rD   ZeraseToLineEndr   r"   r!   rJ   r   r   r   ÚtestEraseToLineEndt  s    

ÿþzBufferTests.testEraseToLineEndc                 C   s^   d}| j  |¡ | j  d¡ | j  ¡  |  | j  ¡ |dd …  t|ƒ¡d dtd   ¡ d S )NrI   r(   éüÿÿÿr   r?   )	r   r5   rD   ZeraseToLineBeginningr   r"   rS   rN   r!   rJ   r   r   r   ÚtestEraseToLineBeginning  s    

ÿþz$BufferTests.testEraseToLineBeginningc                 C   s@   | j  d¡ | j  d¡ | j  ¡  |  | j  ¡ dtd  ¡ d S )Ns   Hello world
s   Goodbye world
r   r   )r   r5   ZeraseDisplayr   r"   r!   r   r   r   r   ÚtestEraseDisplayŠ  s    

þzBufferTests.testEraseDisplayc                 C   sn   d}d}| j  d ||df¡¡ | j  dd¡ | j  ¡  |  | j  ¡ |d |d d…  d dtd   ¡ d S )Nó   Hello worldó   Goodbye worldr   ó    r(   r   r)   )r   r5   rz   rG   ZeraseToDisplayEndr   r"   r!   ©r   re   rf   r   r   r   ÚtestEraseToDisplayEnd”  s    

ÿÿ
þþz!BufferTests.testEraseToDisplayEndc                 C   sr   d}d}| j  d ||f¡¡ | j  dd¡ | j  ¡  |  | j  ¡ d|dd …  t|ƒ¡ d dt	d   ¡ d S )Nr‚   rƒ   r   r(   r   é   r)   )
r   r5   rz   rG   ZeraseToDisplayBeginningr   r"   rS   rN   r!   r…   r   r   r   ÚtestEraseToDisplayBeginning¢  s    
ÿÿ
þþz'BufferTests.testEraseToDisplayBeginningc                 C   sh   d}d}| j  d ||f¡¡ | j  dd¡ | j  ¡  |  | j  ¡ |d d | d dtd   ¡ d S )Nr‚   rƒ   r   rC   r   r4   )r   r5   rz   rG   Z
insertLiner   r"   r!   r…   r   r   r   ÚtestLineInsertion°  s"    
ÿþþ
ýþzBufferTests.testLineInsertionc                 C   sj   d}d}d}| j  d |||f¡¡ | j  dd¡ | j  ¡  |  | j  ¡ |d | d dtd   ¡ d S )Nr‚   s   Middle wordsrƒ   r   rF   r   r)   )r   r5   rz   rG   Z
deleteLiner   r"   r!   r{   r   r   r   ÚtestLineDeletion¿  s     
ÿÿ
þþzBufferTests.testLineDeletionN)%Ú__name__Ú
__module__Ú__qualname__r   r$   r'   r0   r2   r6   r9   r:   r;   r>   r@   rE   rH   rL   rP   rQ   rR   rT   rW   rY   rZ   r\   rc   rk   rw   ry   r|   r~   r€   r   r†   rˆ   r‰   rŠ   r   r   r   r   r      sD   
			' 
r   c                   @   s4   e Zd ZdZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚFakeDelayedCallFc                 C   s"   || _ || _|| _|| _|| _d S r   )ÚfsÚtimeoutÚfÚaÚkw)r   r   r   r‘   r’   r“   r   r   r   Ú__init__Ò  s
    zFakeDelayedCall.__init__c                 C   s   | j p
| j S r   )Ú	cancelledÚcalledr   r   r   r   ÚactiveÚ  s    zFakeDelayedCall.activec                 C   s
   d| _ d S ©NT)r•   r   r   r   r   ÚcancelÞ  s    zFakeDelayedCall.cancelc                 C   s   d| _ | j| j| jŽ d S r˜   )r–   r‘   r’   r“   r   r   r   r   Úcallã  s    zFakeDelayedCall.callN)	r‹   rŒ   r   r–   r•   r”   r—   r™   rš   r   r   r   r   rŽ   Ï  s   rŽ   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚFakeSchedulerc                 C   s
   g | _ d S r   )Úcallsr   r   r   r   r”   ê  s    zFakeScheduler.__init__c                 O   s"   | j  t| ||||ƒ¡ | j d S )Néÿÿÿÿ)rœ   ÚappendrŽ   )r   r   r‘   r’   r“   r   r   r   Ú	callLaterî  s    zFakeScheduler.callLaterN)r‹   rŒ   r   r”   rŸ   r   r   r   r   r›   é  s   r›   c                   @   sT   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚExpectTestsc                 C   s    t  ¡ | _| j ¡  tƒ | _d S r   )r   ZExpectableBufferr   r   r›   r   r   r   r   r   r   õ  s    

zExpectTests.setUpc                 C   s’   g }| j jdd| jd}| |j¡ | j  d¡ |  |¡ | j  d¡ |  |¡ |  |d  	¡ d¡ |  t
| jjƒd¡ |  | jjd  ¡ ¡ d S )Nó   hello worldr   ©r   Z	schedulers   greeting puny earthlings
s   hello world
r   )r   Úexpectr   ÚaddCallbackrž   r5   rv   rq   r   ÚgrouprN   rœ   r—   ©r   ÚresultÚdr   r   r   ÚtestSimpleStringû  s    

zExpectTests.testSimpleStringc                 C   s€   g }| j  d¡}| |j¡ |  |¡ | j  d¡ |  |¡ | j  d¡ |  |¡ | j  d¡ |  |¡ |  |d  ¡ d¡ d S )Nr¡   ó   hello s   worló   dr   )	r   r£   r¤   rž   rv   r5   rq   r   r¥   r¦   r   r   r   ÚtestBrokenUpString	  s    



zExpectTests.testBrokenUpStringc                 C   s¸   g }| j  d¡}| |j¡ | j  d¡}| |j¡ |  |¡ | j  d¡ |  |¡ | j  d¡ |  t|ƒd¡ | j  d¡ |  t|ƒd¡ |  |d  ¡ d¡ |  |d  ¡ d¡ d S )Nrª   ó   worlds   helloó    r   r?   r   )	r   r£   r¤   rž   rv   r5   r   rN   r¥   ©r   r§   Zd1Zd2r   r   r   ÚtestMultiple  s    

zExpectTests.testMultiplec                 C   sJ   | j  d¡ g }| j  d¡}| |j¡ |  |¡ |  |d  ¡ d¡ d S )Nr¡   r   )r   r5   r£   r¤   rž   rq   r   r¥   r¦   r   r   r   ÚtestSynchronous*  s    
zExpectTests.testSynchronousc                 C   s|   | j  d¡ g }| j  d¡}| |j¡ | j  d¡}| |j¡ |  t|ƒd¡ |  |d  ¡ d¡ |  |d  ¡ d¡ d S )Ns   goodbye worlds   byer­   r?   r   r   )r   r5   r£   r¤   rž   r   rN   r¥   r¯   r   r   r   ÚtestMultipleSynchronous4  s    z#ExpectTests.testMultipleSynchronousc                 C   s$   |   t|dƒ¡ |  |jtj¡ d S )NÚtype)rq   Úhasattrr   r³   r   ZExpectationTimeout)r   Úresr   r   r   Ú_cbTestTimeoutFailureB  s    z!ExpectTests._cbTestTimeoutFailurec                 C   s4   | j jdd| jd}| | j¡ | jjd  ¡  d S )Nr¡   r   r¢   r   )r   r£   r   ÚaddBothr¶   rœ   rš   )r   r¨   r   r   r   ÚtestTimeoutFailureG  s    zExpectTests.testTimeoutFailurec                 C   s€   | j  d¡ g }| j jdd| jd}| | j¡ | j  d¡}| |j¡ | jjd  	¡  |  
t|ƒd¡ |  
|d  ¡ d¡ d S )Ns   not zoomtasticr¡   r   r¢   s   zoomr   )r   r5   r£   r   r·   r¶   r¤   rž   rœ   rš   r   rN   r¥   r¯   r   r   r   ÚtestOverlappingTimeoutM  s    z"ExpectTests.testOverlappingTimeoutN)r‹   rŒ   r   r   r©   r¬   r°   r±   r²   r¶   r¸   r¹   r   r   r   r   r    ô  s   
r    c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚCharacterAttributeTestszG
    Tests for L{twisted.conch.insults.helper.CharacterAttribute}.
    c              
   C   s”   |   t ¡ t ¡ ¡ |   t ¡ tjtd¡ |   tjddddtjdtjddddtjd¡ |  t ¡ tjtd¡ |  tjddtjdd¡ dS )z±
        L{CharacterAttribute}s must have matching character attribute values
        (bold, blink, underline, etc) with the same values to be considered
        equal.
        )r`   TF)rr   rs   rt   ru   rx   ©rr   N)r   r   ZCharacterAttributer   ZBLUEZassertNotEqualr   r   r   r   r   Útest_equalitya  s@    þ
þ   þ   þü
þ

þz%CharacterAttributeTests.test_equalityc                 C   sl   t  ¡ jdd |  | jg¡}|  t|ƒd¡ |  |d d t¡ trLd}nd}|  |d d d	| ¡ d
S )z~
        L{twisted.conch.insults.helper.CharacterAttribute.wantOne} emits
        a deprecation warning when invoked.
        Tr»   r   r   Úcategoryz5twisted.conch.insults.helper._FormattingState.wantOnez$twisted.conch.insults.helper.wantOneÚmessagez#%s was deprecated in Twisted 13.1.0N)	r   Z_FormattingStateZwantOneZflushWarningsÚtest_wantOneDeprecatedr   rN   ÚDeprecationWarningr   )r   ZwarningsShownZdeprecatedClassr   r   r   r¿   €  s    ÿ
þz.CharacterAttributeTests.test_wantOneDeprecatedN)r‹   rŒ   r   Ú__doc__r¼   r¿   r   r   r   r   rº   ]  s   rº   N)Ztwisted.conch.insultsr   Ztwisted.conch.insults.insultsr   r   r   r   r   r   r	   r
   r   r   r   Ztwisted.python.compatr   Ztwisted.trialr   r    r!   ZTestCaser   rŽ   r›   r    rº   r   r   r   r   Ú<module>   s      Ai