a
    ze3                     @   s   d Z ddlmZ ddlZddlmZ ddlZddlZddlZddl	m
Z
 G dd dZe ZejZejZG dd	 d	ej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edkrejdd dS )zTest calltip, coverage 76%    )calltipN)Mock)Textc                   @   s   e Zd ZdZdZd"ddZde_dd Zd	e_d#d
dZde_dd Zde_dd Z	de	_d$ddZ
de
_dd Zde_dd Zde_dd Zedd Zed d! ZdS )%TCdocz(ai=None, *b)Nc                 G   s   dS r   N selfaibr   r   4/usr/lib/python3.9/idlelib/idle_test/test_calltip.py__init__       zTC.__init__z(self, ai=None, *b)c                 C   s   dS r   r   r
   r   r   r   t1   r   zTC.t1(self)c                 C   s   dS r   r   r	   r   r   r   t2   r   zTC.t2z(self, ai, b=None)c                 G   s   dS r   r   )r
   r   argsr   r   r   t3   r   zTC.t3z(self, ai, *args)c                 G   s   dS r   r   r
   r   r   r   r   t4   r   zTC.t4z(self, *args)c                 O   s   dS r   r   )r
   r   r   r   kwr   r   r   t5   r   zTC.t5z(self, ai, b=None, *args, **kw)c                 C   s   dS r   r   )nor
   r   r   r   t6   r   zTC.t6z
(no, self)c                 C   s   dS r   r   r
   Zcir   r   r   __call__   r   zTC.__call__z
(self, ci)c                 C   s   d S Nr   r   r   r   r   nd    r   zTC.ndc                 C   s   dS r   r   )clsar   r   r   cm"   s    zTC.cmc                 C   s   dS r   r   )r   r   r   r   sm$   s    zTC.sm)N)N)N)__name__
__module____qualname____doc__tipr   r   r   r   r   r   r   r   r   classmethodr"   staticmethodr#   r   r   r   r   r      s.   



r   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S ) Get_argspecTestc                    s    fdd}G dd dt }G dd d}|jd urF||d|j  |t jd |t jd	 d
}|t jd|  ||jd|  |g jd|  |tjd || t t	d}|tj
d ||j
d d S )Nc                    s     t| | d S r   )assertEqualget_spec)objoutr   r   r   tiptest7   s    z.Get_argspecTest.test_builtins.<locals>.tiptestc                   @   s   e Zd ZdZdS )z+Get_argspecTest.test_builtins.<locals>.Listz
List() docN)r$   r%   r&   r'   r   r   r   r   List;   r   r1   c                   @   s   e Zd ZdZdS )z)Get_argspecTest.test_builtins.<locals>.SBNr$   r%   r&   r   r   r   r   r   SB>   r   r3   z(iterable=(), /)
zY(*args, **kwargs)
Create and return a new object.  See help(type) for accurate signature.zY(self, /, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.z&
Append object to the end of the list.z(self, object, /)z(object, /)zmethod(function, instance) aO  (pattern, repl, string, count=0, flags=0)
Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl.  repl can be either a string or a callable;
if a string, backslash escapes in it are processed.  If it is
a callable, it's passed the Match object and must returnzm(repl, string, count=0)
Return the string obtained by replacing the leftmost non-overlapping occurrences o...)listr'   __new__r   appendtypes
MethodTypedefault_tiprecompilesub)r
   r0   r1   r3   Z
append_docpr   r   r   test_builtins5   s0    

zGet_argspecTest.test_builtinsc                 C   s"   t jjd ur| tt jd d S )Na6  (width=70, initial_indent='', subsequent_indent='', expand_tabs=True,
    replace_whitespace=True, fix_sentence_endings=False, break_long_words=True,
    drop_whitespace=True, break_on_hyphens=True, tabsize=8, *, max_lines=None,
    placeholder=' [...]')
Object for wrapping/filling text.  The public interface consists of
the wrap() and fill() methods; the other methods are just there for
subclasses to override in order to tweak the default behaviour.
If you want to completely replace the main wrapping algorithm,
you'll probably have to override _wrap_chunks().)textwrapZTextWrapperr'   r,   r-   r   r   r   r   test_signature_wrap`   s    z#Get_argspecTest.test_signature_wrapc           
   	   C   s   ddd}ddd}ddd}t j}d	| d
 }d	| d }d	| d | d }||f||f||ffD ]F\}}	| j||	d  | t||	 W d    qf1 s0    Y  qfd S )Ndaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac                 S   s   d S r   r   sr   r   r   fooo   s    z4Get_argspecTest.test_properly_formatted.<locals>.fooc                 S   s   dS )zHello GuidoNr   rC   r   r   r   barr   s    z4Get_argspecTest.test_properly_formatted.<locals>.bardbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc                 S   s   d S r   r   )rD   zr   r   r   bazv   s    z4Get_argspecTest.test_properly_formatted.<locals>.bazzV(s='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
zaaaaaaaaaaaaaaaaaaa')z!aaaaaaaaaaaaaaaaaaa')
Hello GuidozRaaaaaaaaaaaaaaaaaaa', z='bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
z.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'))funcr   )rB   )rB   )rB   rG   )r   Z_INDENTsubTestr,   r-   )
r
   rE   rF   rI   indentZsfooZsbarZsbazrJ   r   r   r   r   test_properly_formattedm   s4    


z'Get_argspecTest.test_properly_formattedc                 C   s6   dd }d|_ | t|ddtjd  d   d S )Nc                   S   s   d S r   r   r   r   r   r   f   r   z2Get_argspecTest.test_docline_truncation.<locals>.fA,  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()
r!      z...)r'   r,   r-   r   Z	_MAX_COLSr
   rN   r   r   r   test_docline_truncation   s    z'Get_argspecTest.test_docline_truncationc                 C   sL   |  ttd |  ttd dd }d|_|  t|ddtj   d S )NzFrange(stop) -> range object
range(start, stop[, step]) -> range objectzbytes(iterable_of_ints) -> bytes
bytes(string, encoding[, errors]) -> bytes
bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
bytes(int) -> bytes object of size given by the parameter initialized with null bytes
bytes() -> empty bytes objectc                   S   s   d S r   r   r   r   r   r   rN      r   z3Get_argspecTest.test_multiline_docstring.<locals>.fza
a
a
a
a
a
a
a
a
a
a
a
a
a
a
()z
a)r,   r-   rangebytesr'   r   Z
_MAX_LINESrP   r   r   r   test_multiline_docstring   s    
z(Get_argspecTest.test_multiline_docstringc              	   C   s   dd }d|_ ddd}d|_ dd }d	|_ d
d }d|_ ddd}d|_ |jd urXdnd}|||||tfD ]F}| j|d& | t||j |  W d    ql1 s0    Y  qld S )Nc                   S   s   dS r   r   r   r   r   r   r      r   z*Get_argspecTest.test_functions.<locals>.t1rR   c                 S   s   dS r   r   )r!   r   r   r   r   r      r   z*Get_argspecTest.test_functions.<locals>.t2z(a, b=None)c                 W   s   dS r   r   )r!   r   r   r   r   r      r   z*Get_argspecTest.test_functions.<locals>.t3z
(a, *args)c                  W   s   dS r   r   r   r   r   r   r      r   z*Get_argspecTest.test_functions.<locals>.t4(*args)c                 _   s   dS r   r   )r!   r   r   r   r   r   r   r      r   z*Get_argspecTest.test_functions.<locals>.t5z(a, b=None, *args, **kw)
docr4   )rJ   )N)N)r(   r'   r   rK   r,   r-   )r
   r   r   r   r   r   r   rJ   r   r   r   test_functions   s    

zGet_argspecTest.test_functionsc              	   C   s   t jd urdnd}t jt jt jt jt jt jt jfD ]F}| j	|d& | 
t||j|  W d    q21 sn0    Y  q2| 
tt jd|  | 
tt jd|  d S )NrX   r4   )meth(a)z(b))r   r'   r   r   r   r   r   r   r   rK   r,   r-   r(   r"   r#   )r
   r   rZ   r   r   r   test_methods   s    $6zGet_argspecTest.test_methodsc              	   C   s   t jd urdnd}tjdftjdftjdftjdftdft jdffD ]J\}}| j||d$ | 	t
|||  W d    qD1 s0    Y  qDd S )	NrX   r4   rR   rW   r   (ci)r[   rZ   mtip)r   r'   tcr   r   r   r   r"   rK   r,   r-   )r
   r   rZ   r_   r   r   r   test_bound_methods   s    z"Get_argspecTest.test_bound_methodsc              	   C   st   G dd d}| }|j df|j dffD ]F\}}| j||d  | t|| W d    q(1 sd0    Y  q(d S )Nc                   @   s   e Zd Zdd ZdS )z1Get_argspecTest.test_starred_parameter.<locals>.Cc                  W   s   d S r   r   rV   r   r   r   m1   r   z4Get_argspecTest.test_starred_parameter.<locals>.C.m1N)r$   r%   r&   rb   r   r   r   r   C   s   rc   rW   r^   )rb   rK   r,   r-   )r
   rc   crZ   r_   r   r   r   test_starred_parameter   s
    z&Get_argspecTest.test_starred_parameterc                 C   sL   G dd d}G dd d}t j}| t| j| | t| | d S )Nc                   @   s   e Zd Zdd ZdS )z7Get_argspecTest.test_invalid_method_get_spec.<locals>.Cc                  [   s   d S r   r   )kwargsr   r   r   m2   r   z:Get_argspecTest.test_invalid_method_get_spec.<locals>.C.m2N)r$   r%   r&   rg   r   r   r   r   rc      s   rc   c                   @   s   e Zd Zdd ZdS )z:Get_argspecTest.test_invalid_method_get_spec.<locals>.Testc                 S   s   d S r   r   )r!   r   r   r   r      r   zCGet_argspecTest.test_invalid_method_get_spec.<locals>.Test.__call__Nr2   r   r   r   r   Test   s   rh   )r   Z_invalid_methodr,   r-   rg   )r
   rc   rh   r_   r   r   r   test_invalid_method_get_spec   s
    z,Get_argspecTest.test_invalid_method_get_specc                 C   s   d}d S )Nu   (AΑАאاअḀあ, a)r   )r
   Zunir   r   r   test_non_ascii_name   s    z#Get_argspecTest.test_non_ascii_namec              	   C   s`   t jdftjdffD ]F\}}| j||d  | t|| W d    q1 sP0    Y  qd S )Nr   rR   r^   )r   r   r`   rK   r,   r-   )r
   rZ   r_   r   r   r   test_no_docstring   s    z!Get_argspecTest.test_no_docstringc              	   C   s   G dd d}G dd d|}G dd d|}|t f|t f| df| df| d	ffD ]F\}}| j||d
  | t|| W d    qV1 s0    Y  qVd S )Nc                   @   s   e Zd Zdd ZdS )z8Get_argspecTest.test_buggy_getattr_class.<locals>.NoCallc                 S   s   t d S r   )
IndexError)r
   namer   r   r   __getattr__   s    zDGet_argspecTest.test_buggy_getattr_class.<locals>.NoCall.__getattr__N)r$   r%   r&   rn   r   r   r   r   NoCall   s   ro   c                   @   s   e Zd Zdd ZdS )z7Get_argspecTest.test_buggy_getattr_class.<locals>.CallAc                 S   s   d S r   r   r   r   r   r   r      s    z@Get_argspecTest.test_buggy_getattr_class.<locals>.CallA.__call__Nr2   r   r   r   r   CallA   s   rp   c                   @   s   e Zd Zdd ZdS )z7Get_argspecTest.test_buggy_getattr_class.<locals>.CallBc                 S   s   d S r   r   )Zouir!   r   rd   r   r   r   r      s    z@Get_argspecTest.test_buggy_getattr_class.<locals>.CallB.__call__Nr2   r   r   r   r   CallB   s   rq   r4   r]   z	(a, b, c)r^   )r:   rK   r,   r-   )r
   ro   rp   rq   rZ   r_   r   r   r   test_buggy_getattr_class   s    z(Get_argspecTest.test_buggy_getattr_classc              	   C   s   G dd dt }G dd d|d}|tt f|tf| dffD ]F\}}| j||d  | t|| W d    q>1 sz0    Y  q>d S )Nc                   @   s   e Zd Zei ji jZdS )z2Get_argspecTest.test_metaclass_class.<locals>.TypeN)r$   r%   r&   property__getitem____setitem__	__class__r   r   r   r   Type   s   rw   c                   @   s   e Zd ZdZdS )z4Get_argspecTest.test_metaclass_class.<locals>.Objectrv   N)r$   r%   r&   	__slots__r   r   r   r   Object   s   ry   )	metaclassr4   r^   )typer-   r:   rK   r,   )r
   rw   ry   rZ   r_   r   r   r   test_metaclass_class   s    z$Get_argspecTest.test_metaclass_classc              	   C   sV   ddddg i fD ]@}| j |d  | t|d W d    q1 sF0    Y  qd S )Nr   g        0   0)r.   r4   )rK   r,   r-   )r
   r.   r   r   r   test_non_callables   s    z"Get_argspecTest.test_non_callablesN)r$   r%   r&   r?   rA   rM   rQ   rU   rY   r\   ra   re   ri   rj   rk   rr   r|   r   r   r   r   r   r+   -   s   +		

r+   c                   @   s   e Zd Zdd Zdd ZdS )Get_entityTestc                 C   s   |  td d S )Nz1/0)assertIsNoner   
get_entityr   r   r   r   test_bad_entity  s    zGet_entityTest.test_bad_entityc                 C   s   |  tdt d S )Nint)assertIsr   r   r   r   r   r   r   test_good_entity  s    zGet_entityTest.test_good_entityN)r$   r%   r&   r   r   r   r   r   r   r     s   r   c                   @   s   e Zd ZdZdd ZdS )
mock_Shellz.Return mock sufficient to pass to hyperparser.c                 C   s(   t d d|_|| _d| _d| _d| _d S )N)Zreturn_valuez>>>       )r   Ztag_prevrangetextZprompt_last_lineZindentwidthZtabwidth)r
   r   r   r   r   r     s
    zmock_Shell.__init__N)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 )mock_TipWindowc                 C   s   d S r   r   r   r   r   r   r     s    zmock_TipWindow.__init__c                 C   s&   ||f| _ tt|d\| _| _d S )N.)r   mapr   splitZ	parenlineZparencol)r
   r   Z	parenleftZ
parenrightr   r   r   showtip  s    
zmock_TipWindow.showtipN)r$   r%   r&   r   r   r   r   r   r   r     s   r   c                   @   s&   e Zd Zdd ZdddZdd ZdS )	WrappedCalltipc                 C   s   t  S r   )r   r   r   r   r   _make_tk_calltip_window#  s    z&WrappedCalltip._make_tk_calltip_windowNc                 C   s   | j rd | _ |  jd7  _d S )N   )active_calltiptips_removed)r
   eventr   r   r   remove_calltip_window&  s    z$WrappedCalltip.remove_calltip_windowc                 C   s   dS )Nr(   r   )r
   Z
expressionr   r   r   	fetch_tip+  s    zWrappedCalltip.fetch_tip)N)r$   r%   r&   r   r   r   r   r   r   r   r   "  s   
r   c                   @   sH   e Zd Zedd Zdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dS )CalltipTestc                 C   s   t  | _tt| j| _d S r   )r   r   r   r   ct)r    r   r   r   
setUpClass1  s    zCalltipTest.setUpClassc                 C   s"   | j dd d | j_d| j_d S )Nz1.0endr   )r   deleter   r   r   r   r   r   r   setUp6  s    zCalltipTest.setUpc                 C   sZ   | j j}| jdd |d | j j| _||  | jdd |d | | j jd  d S )Ng      ?zf(Finsert))r   open_calltipr   r   r   r(   r   )r
   ZtestfuncZopentipr   r   r   
open_close<  s    
zCalltipTest.open_closec                 C   s   dd }|  | d S )Nc                 S   s   |  | jjd d S )N)z1.1z1.end)r,   r(   r   r   r   r   r   r   H  s    z)CalltipTest.test_open_close.<locals>.argsr   r   r   r   r   test_open_closeG  s    zCalltipTest.test_open_closec                 C   s   dd }|  | d S )Nc                 S   sF   dD ]*}| j dd | jd | jd q| | jj| j d S )Nabcr   r!   T)r   r   r   r   r   r   r(   r
   charr   r   r   forceM  s
    z.CalltipTest.test_repeated_force.<locals>.forcer   )r
   r   r   r   r   test_repeated_forceL  s    zCalltipTest.test_repeated_forcec                 C   s   dd }|  | d S )Nc              	   S   s   dD ]h}| j |dH | jd| dD ]}| jd| q(| | jj| j W d    q1 sb0    Y  q| jdd d S )N)r!   ')contextr   (()())r   )rK   r   r   r   r   r   r(   )r
   r   r   r   r   r   parensV  s    2z0CalltipTest.test_repeated_parens.<locals>.parensr   )r
   r   r   r   r   test_repeated_parensU  s    z CalltipTest.test_repeated_parensc                 C   s   dd }|  | d S )Nc                 S   sJ   | j dd dD ]}| j d| q| | jj| j | j dd d S )Nr   z# r   
)r   r   r   r   r   r(   r   r   r   r   commenta  s
    z0CalltipTest.test_comment_parens.<locals>.commentr   )r
   r   r   r   r   test_comment_parens`  s    zCalltipTest.test_comment_parensN)r$   r%   r&   r)   r   r   r   r   r   r   r   r   r   r   r   r   /  s   
	r   __main__   )	verbosity)r'   Zidlelibr   ZunittestZunittest.mockr   r@   r8   r;   Zidlelib.idle_test.mock_tkr   r   r`   Z_default_callable_argspecr:   Zget_argspecr-   ZTestCaser+   r   r   r   ZCalltipr   r   r$   mainr   r   r   r   <module>   s(    X
	;