o
    Ph@                     @   s8  d Z ddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZ ddlZddlZddl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S );z6Tests for Terminal() sequences and sequence-awareness.    N   )	all_termsas_subprocessTestTerminalunicode_parmmany_columnsunicode_capc                  C      t dd } |   dS )z#Check that capability lookup works.c                  S   s.   t  } td}| j|ksJ | j|ksJ d S )Nsc)r   r   save)tr
    r   W/var/www/html/env_mimamsha/lib/python3.10/site-packages/blessed/tests/test_sequences.pychild   s   ztest_capability.<locals>.childNr   r   r   r   r   test_capability   s   

r   c                  C   r	   )z<Assert capability templates are '' when stream is not a tty.c                  S   s.   t t d} | jdksJ | jdksJ d S )N)stream )r   sixStringIOr   redr   r   r   r   r   )   s   z*test_capability_without_tty.<locals>.childNr   r   r   r   r   test_capability_without_tty'      

r   c                  C   r	   )z8force styling should return sequences even for non-ttys.c                  S   s&   t t dd} | jtdksJ d S )NTr   force_stylingr
   )r   r   r   r   r   r   r   r   r   r   4   s   z.test_capability_with_forced_tty.<locals>.childNr   r   r   r   r   test_capability_with_forced_tty2   s   

r   c                  C   r	   )z!Test parameterizing a capability.c                   S   s"   t  ddtdddksJ d S )N      cup)r   r    r   r   r   r   r   r   >   s   "z#test_parametrization.<locals>.childNr   r   r   r   r   test_parametrization<      

r!   c                  C   r	   )z9Assert that ``height_and_width()`` returns full integers.c                  S   s*   t  } t| jtsJ t| jtsJ d S N)r   
isinstanceheightintwidthr   r   r   r   r   G   s   z$test_height_and_width.<locals>.childNr   r   r   r   r   test_height_and_widthE   r   r(   c                  C   r	   )z3Make sure Terminal ``stream`` is stdout by default.c                   S   s   t  jtjks	J d S r#   )r   r   sys
__stdout__r   r   r   r   r   R   s   ztest_stream_attr.<locals>.childNr   r   r   r   r   test_stream_attrP   r"   r+   c                 C      t dd }||  dS )z0Make sure ``location()`` works on all terminals.c                 S   s   t | t dd}|dd |jd W d    n1 s w   Y  dtdp,dtd	dddtd
p7df}|j	 |ksCJ d S )NTkindr   r   r   r   hir   r
   [sr    rc[u)
r   r   r   locationr   writejoinr   r   getvaluer.   r   expected_outputr   r   r   child_with_styling[   s   


z6test_location_with_styling.<locals>.child_with_stylingNr   )r   r9   r   r   r   test_location_with_stylingY   s   
r:   c                  C   r	   )z9Make sure ``location()`` silently passes without styling.c                  S   s^   t t dd} | dd | jd W d   n1 sw   Y  | j dks-J dS )zANo side effect for location as a context manager without styling.Nr   r   r   r/   )r   r   r   r3   r   r4   r6   r   r   r   r   child_without_stylingl   s
   z<test_location_without_styling.<locals>.child_without_stylingNr   )r;   r   r   r   test_location_without_stylingj      

	r<   c                 C   r,   )DMake sure we can move the cursor horizontally without changing rows.c                 S   s   t | t dd}|jdd W d    n1 sw   Y  tdd}|s2| ds0| dr2d}d	td
p9d|tdp?df}|j	 |ksVJ t
|j	 t
|fd S )NTr-      xhpascreenansiz[6Gr   r
   r0   r1   r2   )r   r   r   r3   r   
startswithr5   r   r   r6   repr)r.   r   _hpar8   r   r   r   r   {   s$   



z'test_horizontal_location.<locals>.childNr   r   r   r   r   r   test_horizontal_locationy      
rI   c                 C   r,   )r>   c                 S   s   t | t dd}|jdd W d    n1 sw   Y  tdd}|s2| ds0| dr2d}d	td
p9d|tdp?df}|j	 |ksKJ d S )NTr-   r?   yvparC   rD   z[6dr   r
   r0   r1   r2   )
r   r   r   r3   r   rE   r5   r   r   r6   )r.   r   _vpar8   r   r   r   r      s    


z%test_vertical_location.<locals>.childNr   rH   r   r   r   test_vertical_location   rJ   rO   c                  C   (   t dd } | d | d | d dS )z<Test injection of hpa attribute for screen/ansi (issue #55).c                 S      t | t dd}d}|j|d W d    n1 sw   Y  dtdp(dd|d	 td
p3df}|j |ks?J |	|d|d	 ksMJ d S )NTr-   r?   r@   r   r
   r0   z[{0}Gr   r1   r2   )
r   r   r   r3   r5   r   formatr   r6   move_x)r.   r   COLr8   r   r   r   r         

 z!test_inject_move_x.<locals>.childrC   screen-256colorrD   Nr   r   r   r   r   test_inject_move_x   
   
rW   c                  C   rP   )z<Test injection of vpa attribute for screen/ansi (issue #55).c                 S   rQ   )NTr-   r?   rK   r   r
   r0   z[{0}dr   r1   r2   )
r   r   r   r3   r5   r   rR   r   r6   move_y)r.   r   ROWr8   r   r   r   r      rU   z!test_inject_move_y.<locals>.childrC   rV   rD   Nr   r   r   r   r   test_inject_move_y   rX   r[   c                  C      t dd } | d dS )z*Test injection of cvis attribute for ansi.c                 S   T   t | t dd}|  W d    n1 sw   Y  d}|j |ks(J d S )NTr-   z[?25l[?25h)r   r   r   hidden_cursorr   r6   r7   r   r   r   r         
z3test_inject_civis_and_cnorm_for_ansi.<locals>.childrD   Nr   r   r   r   r   $test_inject_civis_and_cnorm_for_ansi      
r`   c                  C   r\   )z?Test injection of sc and rc (save and restore cursor) for ansi.c                 S   r]   )NTr-   z[s[u)r   r   r   r3   r   r6   r7   r   r   r   r      r_   z-test_inject_sc_and_rc_for_ansi.<locals>.childrD   Nr   r   r   r   r   test_inject_sc_and_rc_for_ansi   ra   rb   c                 C   r,   )z9Make sure ``location()`` pays attention to 0-valued args.c                 S   s|   t | t dd}|dd W d    n1 sw   Y  dtdp&dtdddtdp0d	f}|j |ks<J d S )
NTr-   r   r   r
   r0   r    r1   r2   )	r   r   r   r3   r5   r   r   r   r6   r7   r   r   r   r      s   


z!test_zero_location.<locals>.childNr   rH   r   r   r   test_zero_location   s   

rc   c                 C   r,   )zMake sure color shortcuts work.c                 S   s   dd }dd }t | d}|j||dksJ |j||dks!J |j||dks+J |j||dks5J |j||d	ks?J |j||d
ksIJ |j||d	ksSJ |j||d
ks]J d S )Nc                 S      | j rtd|p	dS )Nsetafr   number_of_colorsr   r   numr   r   r   color      z2test_mnemonic_colors.<locals>.child.<locals>.colorc                 S   rd   )Nsetabr   rf   rh   r   r   r   on_color   rk   z5test_mnemonic_colors.<locals>.child.<locals>.on_colorr.         r      
   )	r   whitegreenon_blackon_greenbright_blackbright_greenon_bright_blackon_bright_green)r.   rj   rm   r   r   r   r   r      s   
z#test_mnemonic_colors.<locals>.childNr   rH   r   r   r   test_mnemonic_colors   s   
r{   c                 C   r,   )z0``color(n)`` should return a formatting wrapper.c                 S   s`  t | d}|jr|dd|jd |j ksJ n|dddks%J |jr:|dd|jd |j ks9J n|dddksEJ |dr^|dd|dd |j ks]J n|dddksiJ |jr~|dd|jd |j ks}J n|dddksJ |dr|dd|dd |j ksJ d S |dddksJ d S )Nrn   r?   smoor   rp      )r   magentarj   normal
on_magentarm   rv   r.   r   r   r   r   r     s    
$$
($
*z+test_callable_numeric_colors.<locals>.childNr   rH   r   r   r   test_callable_numeric_colors  s   
r   c                 C   r,   )z1``color(n)`` should be a no-op on null terminals.c                 S   s@   t t | d}|dddksJ |dddksJ d S )Nr   r.   r?   r|   r}   )r   r   r   rj   rm   r   r   r   r   r   1  s   z0test_null_callable_numeric_colors.<locals>.childNr   rH   r   r   r   !test_null_callable_numeric_colors/  s   
r   c                 C   r,   )z5``term.color`` should return a stringlike capability.c                 S   s&   t | d}|jd |jd ksJ d S )Nrn   r   )r   rj   re   r   r   r   r   r   <  s   
z#test_naked_color_cap.<locals>.childNr   rH   r   r   r   test_naked_color_cap:  s   
r   c                 C   r,   )-Test simple and compound formatting wrappers.c                 S   s   t | d}|jrd|jd|jf}nd}|d|ksJ |jr,d|jd|jf}nd}|d|ks7J |jrEd|jd|jf}nd}|d|ksPJ |jr^d|jd|jf}nd}|d|ksiJ d S )Nrn   r   r/      boöz[1])r   boldr5   r   rt   	underline	subscriptr7   r   r   r   r   F  s"   
z(test_formatting_functions.<locals>.childNr   rH   r   r   r   test_formatting_functionsD  s   
r   c                 C   r,   )r   c                 S   s   t | d}t|j|jfrd|j|jd|jf}nd}|d|ks%J t|j|j|j|j	frBd|j|j|j|j	d|jf}nd}|
d|ksMJ d S )Nrn   r   r   meh)r   anyr   rt   r5   r   
bold_greenon_bright_redrx   r   )on_bright_red_bold_bright_green_underliner7   r   r   r   r   h  s   
z'test_compound_formatting.<locals>.childNr   rH   r   r   r   test_compound_formattingf  s   
r   c                 C   s   t dd }dS )z-Test complex nested compound formatting, wow!c                 S   s   t | d}|d|d|ddd}d|jd|jd|jd|j|j|jd|j|jd|jf}||ks6J |d|d	d
|d	d}d|jd|jd	|j|jd
|jd	|j|jd|jf}||kseJ d S )Nrn   -a--b--c--d--e-r   off ON off  off)r   rt   r   r   r5   r   r.   r   givenexpectedr   r   r   r     s,   


z%test_nested_formatting.<locals>.childNr   rH   r   r   r   test_nested_formatting}  s   r   c                 C   r,   )z7Test crazy-ass formatting wrappers when there's no tty.c              	   S   s   t | t dd}|ddksJ |ddksJ |ddks$J |ddks-J |d|d|dd	d
}d}||ksDJ |d|dd|dd}d}||ks[J |ddksdJ d S )NFr-   r/   r   loor   r   r   r   r   z-a--b--c--d--e-r   r   r   r   zoff ON off ON offr   )	r   r   r   r   rt   r   bold_underline_green_on_redr   r   r   r   r   r   r     s&   
z4test_formatting_functions_without_tty.<locals>.childNr   rH   r   r   r   %test_formatting_functions_without_tty  s   
r   c                 C   r,   )zBMake sure you get nice hints if you misspell a formatting wrapper.c                 S   s^  t | d}z|d |jrJ dW n ty+   t d }d|jd v s)J Y nw z|d |jr9J dW n tyR   t d }d|jd v sPJ Y nw z|d  |jr`J dW n tyy   t d }d|jd vswJ Y nw t dkrz|d	d
 |jrJ dW d S  ty   t d }d|jd v sJ |jY d S w d S )Nrn   heyFzShould have thrown exceptionr   zprobably misspelledr   PyPyab)	r   bold_misspelledis_a_tty	TypeErrorr)   exc_infoargsplatformpython_implementation)r.   r   er   r   r   r     s>   



z*test_nice_formatting_errors.<locals>.childNr   rH   r   r   r   test_nice_formatting_errors  s   
r   c                 C   r,   )z9Make sure NullCallableString tolerates all kinds of args.c                 S   s   t t | d}|jdksJ |ddkdksJ |ddks#J | dks+J |ddddks6J |ddks?J d S )Nr   r   r   rp   rA   zhuh?zxhuh?)r   r   r   clearmoverS   r   r   r   r   r   r     s   z(test_null_callable_string.<locals>.childNr   rH   r   r   r   test_null_callable_string  s   
	r   c                  C   r	   )z Test Terminal.padd(seq). c                  S   s|   ddl m}  ddlm} |d}| d| dksJ | d| dks&J | d	| d
ks1J | d| dks<J d S )Nr   )SequenceTerminalzxterm-256colorzxyzxyzxyz-zxy-z
xxxx[3Dzzxzzz[3Dr   )blessed.sequencesr   blessedr   padd)r   r   termr   r   r   r     s   ztest_padd.<locals>.childNr   r   r   r   r   	test_padd  r=   r   c                 C   r,   )zTest Terminal.split_seqs.c                 S   s   ddl m} || }|jr1|jr1|jd |j d }|jdd|jddg}t||}||ks1J |jrM|jd	 }|jd
d
dg}t||}||ksOJ d S d S )Nr   r   ABCDABCDbbqr   q)r   r   r
   r1   list
split_seqsr   )r.   r   r   
given_textr   resultr   r   r   r     s   
ztest_split_seqs.<locals>.childNr   rH   r   r   r   test_split_seqs  s   
r   )*__doc__r   randomr)   osaccessoriesr   r   r   r   r   r   pytestmockr   r   r   r   r!   r(   r+   r:   r<   rI   rO   rW   r[   r`   rb   rc   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sH    

		!
"%