o
    û›hk>  ã                   @   sX  d Z ddlmZ ddlmZmZmZ ddlZddlZddlZddl	Z	ddl
Z
ddlmZ ddlmZ ddlmZmZ dd	lmZ dad
d„ ZG dd„ dƒ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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*ƒZ%G d+d,„ d,e ƒZ&d-d.„ Z'd/d0„ Z(d1d2„ Z)d3d4„ Z*d5d6„ Z+dmd7d8„Z,d9d:„ Z-d;d<„ Z.d=d>„ Z/d?d@„ Z0dAdB„ Z1dCdD„ Z2dEdF„ Z3dGdH„ Z4edIdJ„ ƒZ5dKdL„ Z6dMdN„ Z7dOdP„ Z8dQdR„ Z9dSdT„ Z:dUdV„ Z;dWdX„ Z<dYdZ„ Z=d[d\„ Z>ej?j@e
jAjBd]vd^d_d`�dadb„ ƒZCdcdd„ ZDdedf„ ZEdgdh„ ZFdidj„ ZGdkdl„ ZHdS )nz/Tests for the object inspection functionality.
é    )Úcontextmanager)Ú	signatureÚ	SignatureÚ	ParameterNé   )Úoinspect)Ú	decorator)ÚAssertPrintsÚAssertNotPrints)Úcompress_userc                   C   s   t  ¡ ad S ©N)r   Z	InspectorÚ	inspector© r   r   úVc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/tests/test_oinspect.pyÚsetup_module   s   r   c                   @   s   e Zd ZdZdS )ÚSourceModuleMainTestÚ__main__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   #   s    r   é/   c                   C   sR   t  t¡td ksJ ‚t  t¡d u sJ ‚t  t¡d u sJ ‚t  tƒ ¡d u s'J ‚d S )Né   )r   Zfind_source_linesÚtest_find_source_linesÚTHIS_LINE_NUMBERÚtyper   r   r   r   r   r   2   s   r   c                   C   s<   t  t¡d u s	J ‚t  t¡d u sJ ‚t  tƒ ¡d u sJ ‚d S r   )r   Ú	getsourcer   r   r   r   r   r   Útest_getsource9   s   r   c                   C   sn   t  t¡� t t¡ W d  ƒ n1 sw   Y  t  t¡� t t¡ W d  ƒ dS 1 s0w   Y  dS )zACheck oinspect.find_file/getsource/find_source_lines expectationsN)ÚpytestZraisesÚ	TypeErrorÚinspectÚgetfiler   ÚOSErrorr   r   r   r   r   Ú%test_inspect_getfile_raises_exception?   s   ÿ"ÿr"   c                 C   s   t j t dd| ¡¡S )Nz.py[co]$z.py)ÚosÚpathÚnormcaseÚreÚsub)Úfnamer   r   r   ÚpyfileI   s   r)   c                 C   s   t | ƒt |ƒks
J ‚d S r   )r)   )Úf1Úf2r   r   r   Úmatch_pyfilesM   s   r,   c                   C   sT   t t t¡tj t¡ƒ t t¡d u sJ ‚t t	¡d u sJ ‚t t	ƒ ¡d u s(J ‚d S r   )
r,   r   Ú	find_fileÚtest_find_filer#   r$   ÚabspathÚ__file__r   r   r   r   r   r   r.   Q   s   r.   c                  C   sB   t dd„ ƒ} | dd„ ƒ}tt |¡tj t¡ƒ |jdksJ ‚d S )Nc                    s   ‡ fdd„}|S )Nc                     s   ˆ | i |¤ŽS r   r   )ÚaÚkw©Úfr   r   Úwrapper\   s   z9test_find_file_decorated1.<locals>.noop1.<locals>.wrapperr   )r4   r5   r   r3   r   Únoop1Z   s   z(test_find_file_decorated1.<locals>.noop1c                 S   ó   dS )úMy docstringNr   ©Úxr   r   r   r4   `   ó    z$test_find_file_decorated1.<locals>.fr8   ©	r   r,   r   r-   r#   r$   r/   r0   Ú__doc__)r6   r4   r   r   r   Útest_find_file_decorated1X   s   

r>   c                  C   sJ   t dd„ ƒ} | | | dd„ ƒƒƒ}tt |¡tj t¡ƒ |jdks#J ‚d S )Nc                 _   s   | |i |¤ŽS r   r   )r4   r1   r2   r   r   r   Únoop2j   s   z(test_find_file_decorated2.<locals>.noop2c                 S   r7   )úMy docstring 2Nr   r9   r   r   r   r4   n   r;   z$test_find_file_decorated2.<locals>.fr@   r<   )r?   r4   r   r   r   Útest_find_file_decorated2h   s   
rA   c                  C   s    t  d¡} t | ¡d usJ ‚d S )NÚrun)ÚipZfind_line_magicr   r-   )rB   r   r   r   Útest_find_file_magicx   s   
rD   c                   @   s,   e Zd ZdZddd„Zdd„ Zddd	„Zd
S )ÚCallúThis is the class docstring.é   c                 C   r7   )z"This is the constructor docstring.Nr   )Úselfr:   Úyr   r   r   Ú__init__‚   r;   zCall.__init__c                 O   r7   )zThis is the call docstring.Nr   )rH   r1   r2   r   r   r   Ú__call__…   r;   zCall.__call__r   c                 C   r7   ©zSome method's docstringNr   ©rH   r:   Úzr   r   r   Úmethodˆ   r;   zCall.methodN©rG   ©r   )r   r   r   r=   rJ   rK   rO   r   r   r   r   rE      s
    
rE   c                   @   s*   e Zd ZdZeedejƒgƒZdd„ ZdS )ÚHasSignaturerF   Útestc                 G   r7   )zThis is the init docstringNr   )rH   Úargsr   r   r   rJ   �   r;   zHasSignature.__init__N)	r   r   r   r=   r   r   ÚPOSITIONAL_OR_KEYWORDÚ__signature__rJ   r   r   r   r   rR   ‹   s    rR   c                   @   s   e Zd Zddd„ZdS )ÚSimpleClassr   c                 C   r7   rL   r   rM   r   r   r   rO   ”   r;   zSimpleClass.methodNrQ   )r   r   r   rO   r   r   r   r   rW   “   s    rW   c                   @   s   e Zd Zdd„ ZdS )ÚAwkwardc                 C   s   t |ƒ‚r   )Ú	Exception)rH   Únamer   r   r   Ú__getattr__™   ó   zAwkward.__getattr__N)r   r   r   r[   r   r   r   r   rX   ˜   s    rX   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú
NoBoolCallzH
    callable with `__bool__` raising should still be inspect-able.
    c                 C   r7   )zdoes nothingNr   ©rH   r   r   r   rK   ¡   ó   zNoBoolCall.__call__c                 C   ó   t dƒ‚)zjust raise NotImplementedzMust be implemented)ÚNotImplementedErrorr^   r   r   r   Ú__bool__¥   ó   zNoBoolCall.__bool__N)r   r   r   r=   rK   rb   r   r   r   r   r]   œ   s    r]   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )	Ú
SerialLiarzáAttribute accesses always get another copy of the same class.

    unittest.mock.call does something similar, but it's not ideal for testing
    as the failure mode is to eat all your RAM. This gives up after 10k levels.
    r   c                 C   s2   |dkrt dƒ‚|| _|| _t|d |ƒ|d< d S )Ni'  z)Nose too long, honesty is the best policyr   )ÚRuntimeErrorÚmax_fibbing_twigÚ	lies_toldÚmax)rH   rf   rg   r   r   r   rJ   °   s
   zSerialLiar.__init__c                 C   s   t | j| jd ƒS )NrG   )rd   rf   rg   )rH   Úitemr   r   r   r[   ·   s   zSerialLiar.__getattr__N)r   )r   r   r   r=   rJ   r[   r   r   r   r   rd   ª   s    
rd   c                  C   sŽ  t jtdd�} | d dksJ ‚tttƒƒ}| d |ksJ ‚t d| d ¡s'J ‚t}| d¡r4|d	d
… }| d  	¡ t
|ƒ 	¡ ksBJ ‚| d d	ksJJ ‚| d tjksSJ ‚| d d	ks[J ‚| d du scJ ‚| d dkskJ ‚| d tjjksuJ ‚t jtdd�} | d d	us„J ‚| d d	ksŒJ ‚tdƒ}d|_t  |¡} | d dks J ‚| d dks¨J ‚| d tjks±J ‚| d tjjks»J ‚| d tjjksÅJ ‚d	S )z?Check that Inspector.info fills out various fields as expected.rE   ©ZonameÚ	type_namer   Z
base_classzE<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>Zstring_formz.pycNéÿÿÿÿÚfileÚ
definitionÚ	docstringÚsourceÚisclassTÚinit_definitionzCall(x, y=1)Úinit_docstringrG   ©Zdetail_levelzModified instance docstringZclass_docstringZcall_docstring)r   ÚinforE   Ústrr   r&   Úsearchr0   ÚendswithÚlowerr   r=   rJ   rK   )ÚiZexpected_classr(   Úcr   r   r   Ú	test_info¾   s:   þ

r|   c                  C   s4   t  td¡} | d dksJ ‚| d tjjksJ ‚d S )NrR   rr   zHasSignature(test)rs   )r   ru   rR   rJ   r=   )ru   r   r   r   Útest_class_signatureã   s   r}   c                   C   ó   t  tƒ ¡ d S r   )r   ru   rX   r   r   r   r   Útest_info_awkwardé   s   r   c                   C   r~   r   )r   ru   r]   r   r   r   r   Útest_bool_raiseí   s   r€   c                  C   s(   dg} t  t| ƒ¡ | d dk sJ ‚d S )Nr   i(#  )r   ru   rd   )Zfib_trackerr   r   r   Útest_info_serialliarð   s   r�   c                 O   r7   )zA simple function.Nr   )r:   rI   r1   r2   r   r   r   Úsupport_function_oneø   r;   r‚   c                  C   s6   t tƒ jttjfD ]} t | ¡}|d d u sJ ‚q	d S )NZcall_def)r‚   rW   rO   Úanyrv   Úupperr   ru   )Úobjrz   r   r   r   Útest_calldef_noneû   s   
þr†   c                C   ó   d S r   r   )ÚposÚkwonlyr   r   r   Úf_kwarg  ó   rŠ   c                  C   s"   t jtdd�} | d dksJ ‚d S )NrŠ   rj   rn   zf_kwarg(pos, *, kwonly))r   ru   rŠ   ©rz   r   r   r   Útest_definition_kwonlyargs  s   r�   c                  C   s|   G dd„ dt ƒ} G dd„ dt ƒ}G dd„ dt ƒ}| ƒ }|ƒ }|ƒ }t |¡dks*J ‚t |¡dks3J ‚t |¡dks<J ‚d S )	Nc                   @   s   e Zd ZdZdS )ztest_getdoc.<locals>.Aústandard docstringN)r   r   r   r=   r   r   r   r   ÚA  s    r�   c                   @   ó   e Zd ZdZdd„ ZdS )ztest_getdoc.<locals>.BrŽ   c                 S   r7   )Núcustom docstringr   r^   r   r   r   Úgetdoc  r‹   ztest_getdoc.<locals>.B.getdocN©r   r   r   r=   r’   r   r   r   r   ÚB  ó    r”   c                   @   r�   )ztest_getdoc.<locals>.CrŽ   c                 S   r‡   r   r   r^   r   r   r   r’     r‹   ztest_getdoc.<locals>.C.getdocNr“   r   r   r   r   ÚC  r•   r–   rŽ   r‘   )Úobjectr   r’   )r�   r”   r–   r1   Úbr{   r   r   r   Útest_getdoc
  s   r™   c                  C   s$   t jtƒ dd�} | d d u sJ ‚d S )NrG   rt   rp   )r   ru   ÚpropertyrŒ   r   r   r   Ú!test_empty_property_has_no_source"  s   r›   c                     s�   dd„ ‰ G ‡ fdd„dt ƒ} tj| jdd�}d|d v sJ ‚d	|d v s&J ‚tj| jdd�}d
|d v s6J ‚tj| jdd�}d|d v sFJ ‚d S )Nc                 S   s   | | S )zAdds two numbersr   )r1   r˜   r   r   r   Ú
simple_add*  rc   z)test_property_sources.<locals>.simple_addc                       s8   e Zd Zedd„ ƒZe dd„ ¡ZeejƒZe” ƒZ	dS )z test_property_sources.<locals>.Ac                 S   r7   ©NÚbarr   r^   r   r   r   Úfoo/  r_   z$test_property_sources.<locals>.A.fooc                 S   s   t | d|ƒS r�   )Úsetattr)rH   Úvr   r   r   Ú<lambda>3  s    z)test_property_sources.<locals>.A.<lambda>N)
r   r   r   rš   rŸ   Úsetterr   r’   ÚdnameÚadderr   ©rœ   r   r   r�   .  s    

r�   rG   rt   zdef foo(self):rp   zlambda self, v:zdef getdoc(obj)zdef simple_add(a, b))r—   r   ru   rŸ   r¤   r¥   )r�   rz   r   r¦   r   Útest_property_sources'  s   
r§   c                  C   s^   G dd„ dt ƒ} | ƒ tjd< dtjddd�d ksJ ‚| tjd	< dtjd
dd�d ks-J ‚d S )Nc                   @   s   e Zd Zedd„ ƒZdS )z@test_property_docstring_is_in_info_for_detail_level_0.<locals>.Ac                 S   r7   )úThis is `foobar` property.Nr   r^   r   r   r   ÚfoobarE  s   zGtest_property_docstring_is_in_info_for_detail_level_0.<locals>.A.foobarN)r   r   r   rš   r©   r   r   r   r   r�   D  s    r�   Za_objr¨   za_obj.foobarr   rt   ro   Za_clsza_cls.foobar)r—   rC   Úuser_nsZobject_inspect)r�   r   r   r   Ú5test_property_docstring_is_in_info_for_detail_level_0C  s   ÿ
ÿr«   c                  C   s   dd„ } t  | d¡ d S )Nc                   S   r‡   r   r   r   r   r   r   rŸ   Y  r;   ztest_pdef.<locals>.foorŸ   )r   Zpdef©rŸ   r   r   r   Ú	test_pdefW  s   r­   c               	   k   st   � z%t tj ¡ ƒ}tj | ¡ dV  W t tj ¡ ƒ| }|D ]}tj|= qdS t tj ¡ ƒ| }|D ]}tj|= q2w )zÅ
    On exit delete all the keys that were not in user_ns before entering.

    It does not restore old values !

    Parameters
    ----------

    **kwargs
        used to update ip.user_ns

    N)ÚsetrC   rª   ÚkeysÚupdate)ÚkwargsZknownÚaddedÚkr   r   r   Úcleanup_user_ns]  s   €
ÿÿ
ÿr´   c                  C   sT   G dd„ dƒ} | ƒ }t |d�� tjdddd� W d  ƒ dS 1 s#w   Y  dS )	z8
    Test that bool method is not called on parent.
    c                   @   s   e Zd ZdZdd„ ZdS )z(test_pinfo_bool_raise.<locals>.RaiseBoolNc                 S   r`   )Nz#pinfo should not access this method)Ú
ValueErrorr^   r   r   r   rb   }  r\   z1test_pinfo_bool_raise.<locals>.RaiseBool.__bool__)r   r   r   Úattrrb   r   r   r   r   Ú	RaiseBoolz  s    r·   )Ú
raise_boolÚpinfozraise_bool.attrr   rt   N)r´   rC   Ú_inspect)r·   r¸   r   r   r   Útest_pinfo_bool_raiseu  s
   "ÿr»   c               	   C   s†   dd„ } | g}t |d��$ tdƒ� tjdddd� W d   ƒ n1 s$w   Y  W d   ƒ n1 s3w   Y  d	tj ¡ vsAJ ‚d S )
Nc                   S   r7   )z
        MARKER
        Nr   r   r   r   r   Údummy‡  r;   z"test_pinfo_getindex.<locals>.dummy©Ú	containerÚMARKERr¹   zcontainer[0]r   rt   r¾   )r´   r	   rC   rº   rª   r¯   ©r¼   r¾   r   r   r   Útest_pinfo_getindex†  s   
ÿ€ÿrÁ   c               	   C   ó€   dd„ } | g}t |d��! tdƒ� t d¡ W d   ƒ n1 s!w   Y  W d   ƒ n1 s0w   Y  dtj ¡ vs>J ‚d S )Nc                   S   r7   )z
        MARKER 2
        Nr   r   r   r   r   r¼   ”  r;   z"test_qmark_getindex.<locals>.dummyr½   zMARKER 2zcontainer[0]?r¾   ©r´   r	   rC   Úrun_cellrª   r¯   rÀ   r   r   r   Útest_qmark_getindex“  ó   
ÿ€ÿrÅ   c               	   C   rÂ   )Nc                   S   r7   )z
        MARKER 3
        Nr   r   r   r   r   r¼   ¡  r;   z*test_qmark_getindex_negatif.<locals>.dummyr½   zMARKER 3zcontainer[-1]?r¾   rÃ   rÀ   r   r   r   Útest_qmark_getindex_negatif   rÆ   rÇ   c                  C   s*   ddl m}  | tjd< tjdddd� d S )NrG   ©Ú	nonascii2rÉ   r¹   rt   )Ú rÉ   rC   rª   rº   rÈ   r   r   r   Útest_pinfo_nonascii®  s   
rË   c                   C   s   t  dd¡ dS )zO
    type can fail in various edge case, for example `type.__subclass__()`
    r¹   r   N)rC   rº   r   r   r   r   Útest_pinfo_type´  s   rÌ   c                   C   sv   t dƒ� tjdddd� W d  ƒ n1 sw   Y  t dƒ� tjdddd� W d  ƒ dS 1 s4w   Y  dS )zFDocstring should be included with detail_level=1 if there is no sourceú
Docstring:r¹   z
str.formatr   rt   NrG   ©r	   rC   rº   r   r   r   r   Útest_pinfo_docstring_no_source»  s   
ÿ
"ÿrÏ   c                  C   sÀ   dd„ } | t jd< tdƒ� t jdddd� W d  ƒ n1 s w   Y  td	ƒ� t jddd
d� W d  ƒ n1 s<w   Y  tdƒ� t jddd
d� W d  ƒ dS 1 sYw   Y  dS )zGDocstring should not be included with detail_level=1 if source is foundc                   S   r7   )zfoo has a docstringNr   r   r   r   r   rŸ   Å  r;   z.test_pinfo_no_docstring_if_source.<locals>.foorŸ   rÍ   r¹   r   rt   NúSource:rG   )rC   rª   r	   rº   r
   r¬   r   r   r   Ú!test_pinfo_no_docstring_if_sourceÃ  s   

ÿ
ÿ
"ÿrÑ   c               	   C   s^  d} t  | ¡ t  d¡ tdƒ�\ tdƒ� t jdddd� W d	  ƒ n1 s(w   Y  tdƒ� t jddd
d� W d	  ƒ n1 sDw   Y  tdƒ� t jdddd� W d	  ƒ n1 s`w   Y  W d	  ƒ n1 sow   Y  tdƒ�- tdƒ� t jddd
d� W d	  ƒ n1 s�w   Y  W d	  ƒ d	S W d	  ƒ d	S 1 s¨w   Y  d	S )z< Docstring should be displayed if source info not available zÑclass Foo(object):
                  """ This is a docstring for Foo """
                  def bar(self):
                      """ This is a docstring for Foo.bar """
                      pass
              zfoo = Foo()rÐ   rÍ   r¹   rŸ   r   rt   NrG   zfoo.bar)rC   rÄ   r
   r	   rº   )Úobj_defr   r   r   Ú,test_pinfo_docstring_if_detail_and_no_sourceÒ  s,   



ÿ
ÿ
ÿ€û

ÿÿ"ÿrÓ   )ÚfinalÚ	candidatezfails on 3.13.devT)ÚreasonÚstrictc                 C   sÔ   d}t  |¡ t  d¡ t  dd¡ |  ¡ }t d|j¡sJ ‚t  dd¡ |  ¡ }t d|j¡s2J ‚t  d¡ |  ¡ }t d|j¡sDJ ‚t  d	¡ |  ¡ }t d|j¡sVJ ‚t  d
¡ |  ¡ }t d|j¡shJ ‚d S )Na2  class Bar:
    __custom_documentations__ = {
     "prop" : "cdoc for prop",
     "non_exist" : "cdoc for non_exist",
    }
    @property
    def prop(self):
        '''
        Docstring for prop
        '''
        return self._prop
    
    @prop.setter
    def prop(self, v):
        self._prop = v
    z	b = Bar()r¹   zb.propzDocstring:\s+cdoc for propzb.non_existzDocstring:\s+cdoc for non_existzb.prop?zb.non_exist?zb.undefined?zType:\s+NoneType)rC   rÄ   Zrun_line_magicZ
readouterrr&   rw   Úout)ZcapsysrÒ   Zcapturedr   r   r   Útest_pinfo_docstring_dynamicë  s$   




rÙ   c                   C   sv   t dƒ� tjdddd� W d   ƒ n1 sw   Y  t dƒ� tjdddd� W d   ƒ d S 1 s4w   Y  d S )NrÍ   r¹   Zlsmagicr   rt   rÐ   rG   rÎ   r   r   r   r   Útest_pinfo_magic  s   
ÿ
"ÿrÚ   c                  C   s"   t  t¡} | d }d|vsJ ‚d S )Nrr   z[0m)r   ru   rR   ©ru   Zinit_defr   r   r   Útest_init_colors"  s   
rÜ   c                  C   s"   t  t¡} | d }|d usJ ‚d S )Nrr   )r   ru   ÚlistrÛ   r   r   r   Útest_builtin_init)  s   
rÞ   c                  C   s,   ddd„} t  t| ƒ| j¡}|dksJ ‚d S )NrG   c                 S   r‡   r   r   )r1   r   r   r   Ú	short_fun0  r;   z.test_render_signature_short.<locals>.short_funzshort_fun(a=1)rP   )r   Ú_render_signaturer   r   )rß   Úsigr   r   r   Útest_render_signature_short/  s   
þrâ   c               	   C   sV   ddl m}  		 ddtdtd| t dtfdd	„}t t|ƒ|j¡}d
}||ks)J ‚d S )Nr   )ÚOptionalFÚa_really_long_parameterÚand_another_long_oneÚlet_us_make_sure_this_is_looongÚreturnc                 S   r‡   r   r   )rä   rå   ræ   r   r   r   Úlong_function;  s   z1test_render_signature_long.<locals>.long_functionz�long_function(
    a_really_long_parameter: int,
    and_another_long_one: bool = False,
    let_us_make_sure_this_is_looong: Optional[str] = None,
) -> bool)FN)	Útypingrã   ÚintÚboolrv   r   rà   r   r   )rã   rè   rá   Úexpectedr   r   r   Útest_render_signature_long8  s$   ýÿþý
üþrí   rQ   )Ir=   Ú
contextlibr   r   r   r   r   r#   r   r&   ÚsysrÊ   r   r   ZIPython.testing.toolsr	   r
   ZIPython.utils.pathr   r   r   r   r   r   r   r"   r)   r,   r.   r>   rA   rD   r—   rE   rR   rW   rX   r]   rd   r|   r}   r   r€   r�   r‚   r†   rŠ   r�   r™   r›   r§   r«   r­   r´   r»   rÁ   rÅ   rÇ   rË   rÌ   rÏ   rÑ   rÓ   ÚmarkZxfailÚversion_infoÚreleaselevelrÙ   rÚ   rÜ   rÞ   râ   rí   r   r   r   r   Ú<module>   s†    
%


ý
*	