Format: application/x-python-code
⬇ Download File (19.2 KB)
   1  o
   2  
   3  ��hk>�@sXdZddlmZddlmZmZmZddlZddlZddlZddl	Z	ddl
   4  Z
   5  ddlmZddl
   6  m
   7  Z
   8  ddlmZmZdd	lmZdad
   9  d�ZGdd
  10  �d
  11  �ZdZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �ZGd!d"�d"e �Z!Gd#d$�d$e �Z"Gd%d&�d&e �Z#Gd'd(�d(e �Z$Gd)d*�d*�Z%Gd+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�Z4edIdJ��Z5dKdL�Z6dMdN�Z7dOdP�Z8dQdR�Z9dSdT�Z:dUdV�Z;dWdX�Z<dYdZ�Z=d[d\�Z>ej?j@e
  12  jAjBd]vd^d_d`�dadb��ZCdcdd�ZDdedf�ZEdgdh�ZFdidj�ZGdkdl�ZHdS)nz/Tests for the object inspection functionality.
  13  �)�contextmanager)�	signature�	Signature�	ParameterN�)�oinspect)�	decorator)�AssertPrints�AssertNotPrints)�
  14  compress_usercCst��adS�N)rZ	Inspector�	inspector�rr�Vc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/tests/test_oinspect.py�setup_modulesrc@seZdZdZdS)�SourceModuleMainTest�__main__N)�__name__�
  15  __module__�__qualname__rrrrr#sr�/cCsRt�t�tdksJ�t�t�dusJ�t�t�dusJ�t�t��dus'J�dS)N�)rZfind_source_lines�test_find_source_lines�THIS_LINE_NUMBER�typerrrrrr2srcCs<t�t�dus	J�t�t�dusJ�t�t��dusJ�dSr)r�	getsourcerrrrrr�test_getsource9srcCsnt�t��
  16  t�t�Wd�n1swYt�t��t�t�Wd�dS1s0wYdS)zACheck oinspect.find_file/getsource/find_source_lines expectationsN)�pytestZraises�	TypeError�inspect�getfiler�OSErrorrrrrr�%test_inspect_getfile_raises_exception?s�"�r"cCstj�t�dd|��S)Nz.py[co]$z.py)�os�path�normcase�re�sub)�fnamerrr�pyfileIsr)cCst|�t|�ks
  17  J�dSr)r))�f1�f2rrr�
  18  match_pyfilesMsr,cCsTtt�t�tj�t��t�t�dusJ�t�t	�dusJ�t�t	��dus(J�dSr)
  19  r,r�	find_file�test_find_filer#r$�abspath�__file__rrrrrrr.Qsr.cCsBtdd��}|dd��}tt�|�tj�t��|jdksJ�dS)Ncs�fdd�}|S)Ncs�|i|��Srr)�a�kw��frr�wrapper\sz9test_find_file_decorated1.<locals>.noop1.<locals>.wrapperr)r4r5rr3r�noop1Zsz(test_find_file_decorated1.<locals>.noop1cS�dS)�My docstringNr��xrrrr4`�z$test_find_file_decorated1.<locals>.fr8�	rr,rr-r#r$r/r0�__doc__)r6r4rrr�test_find_file_decorated1Xs
  20  
  21  r>cCsJtdd��}|||dd����}tt�|�tj�t��|jdks#J�dS)Nc_s||i|��Srr)r4r1r2rrr�noop2jsz(test_find_file_decorated2.<locals>.noop2cSr7)�My docstring 2Nrr9rrrr4nr;z$test_find_file_decorated2.<locals>.fr@r<)r?r4rrr�test_find_file_decorated2hs
  22  rAcCs t�d�}t�|�dusJ�dS)N�run)�ipZfind_line_magicrr-)rBrrr�test_find_file_magicxs
  23  rDc@s,eZdZdZddd�Zdd�Zddd	�Zd
  24  S)
  25  �Call�This is the class docstring.�cCr7)z"This is the constructor docstring.Nr)�selfr:�yrrr�__init__�r;z
  26  Call.__init__cOr7)zThis is the call docstring.Nr)rHr1r2rrr�__call__�r;z
  27  Call.__call__rcCr7�zSome method's docstringNr�rHr:�zrrr�method�r;zCall.methodN�rG�r)rrrr=rJrKrOrrrrrEs
  28  
  29  rEc@s*eZdZdZeedej�g�Zdd�ZdS)�HasSignaturerF�testcGr7)zThis is the init docstringNr)rH�argsrrrrJ�r;zHasSignature.__init__N)	rrrr=rr�POSITIONAL_OR_KEYWORD�
  30  __signature__rJrrrrrR�srRc@seZdZddd�ZdS)�SimpleClassrcCr7rLrrMrrrrO�r;zSimpleClass.methodNrQ)rrrrOrrrrrW�srWc@seZdZdd�ZdS)�AwkwardcCst|��r)�	Exception)rH�namerrr�__getattr__��zAwkward.__getattr__N)rrrr[rrrrrX�srXc@s eZdZdZdd�Zdd�ZdS)�
  31  NoBoolCallzH
  32      callable with `__bool__` raising should still be inspect-able.
  33      cCr7)zdoes nothingNr�rHrrrrK��zNoBoolCall.__call__cC�td��)zjust raise NotImplementedzMust be implemented)�NotImplementedErrorr^rrr�__bool__��zNoBoolCall.__bool__N)rrrr=rKrbrrrrr]�sr]c@s"eZdZdZddd�Zdd�ZdS)	�
  34  SerialLiarz�Attribute accesses always get another copy of the same class.
  35  
  36      unittest.mock.call does something similar, but it's not ideal for testing
  37      as the failure mode is to eat all your RAM. This gives up after 10k levels.
  38      rcCs2|dkrtd��||_||_t|d|�|d<dS)Ni'z)Nose too long, honesty is the best policyr)�RuntimeError�max_fibbing_twig�	lies_told�max)rHrfrgrrrrJ�s
  39  zSerialLiar.__init__cCst|j|jd�S)NrG)rdrfrg)rH�itemrrrr[�szSerialLiar.__getattr__N)r)rrrr=rJr[rrrrrd�s
  40  rdcCs�tjtdd�}|ddksJ�ttt��}|d|ksJ�t�d|d�s'J�t}|�d�r4|d	d
  41  �}|d�	�t
  42  |��	�ksBJ�|dd	ksJJ�|d
  43  tjksSJ�|dd	ks[J�|dduscJ�|ddkskJ�|dtjjksuJ�tjtdd�}|dd	us�J�|d
  44  d	ks�J�td�}d|_t�|�}|ddks�J�|d
  45  dks�J�|dtjks�J�|dtjjks�J�|dtj
  46  jks�J�d	S)z?Check that Inspector.info fills out various fields as expected.rE�Zoname�	type_namerZ
  47  base_classzE<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>Zstring_formz.pycN������file�
  48  definition�	docstring�source�isclassT�init_definitionzCall(x, y=1)�init_docstringrG�Zdetail_levelzModified instance docstringZclass_docstringZcall_docstring)r
  49  �inforE�strrr&�searchr0�endswith�lowerrr=rJrK)�iZexpected_classr(�crrr�	test_info�s:�
  50  
  51  r|cCs4t�td�}|ddksJ�|dtjjksJ�dS)NrRrrzHasSignature(test)rs)r
  52  rurRrJr=)rurrr�test_class_signature�sr}cC�t�t��dSr)r
  53  rurXrrrr�test_info_awkward�srcCr~r)r
  54  rur]rrrr�test_bool_raise�sr�cCs(dg}t�t|��|ddksJ�dS)Nri(#)r
  55  rurd)Zfib_trackerrrr�test_info_serialliar�sr�cOr7)zA simple function.Nr)r:rIr1r2rrr�support_function_one�r;r�cCs6tt�jttjfD]}t�|�}|ddusJ�q	dS)NZcall_def)r�rWrO�anyrv�upperr
  56  ru)�objrzrrr�test_calldef_none�s
  57  �r�cC�dSrr)�pos�kwonlyrrr�f_kwarg�r�cCs"tjtdd�}|ddksJ�dS)Nr�rjrnzf_kwarg(pos, *, kwonly))r
  58  rur��rzrrr�test_definition_kwonlyargssr�cCs|Gdd�dt�}Gdd�dt�}Gdd�dt�}|�}|�}|�}t�|�dks*J�t�|�dks3J�t�|�dks<J�dS)	Nc@seZdZdZdS)ztest_getdoc.<locals>.A�standard docstringN)rrrr=rrrr�Asr�c@�eZdZdZdd�ZdS)ztest_getdoc.<locals>.Br�cSr7)N�custom docstringrr^rrr�getdocr�ztest_getdoc.<locals>.B.getdocN�rrrr=r�rrrr�B�r�c@r�)ztest_getdoc.<locals>.Cr�cSr�rrr^rrrr�r�ztest_getdoc.<locals>.C.getdocNr�rrrr�Cr�r�r�r�)�objectrr�)r�r�r�r1�br{rrr�test_getdoc
  59  sr�cCs$tjt�dd�}|ddusJ�dS)NrGrtrp)r
  60  ru�propertyr�rrr�!test_empty_property_has_no_source"sr�cs�dd��G�fdd�dt�}tj|jdd�}d|dvsJ�d	|dvs&J�tj|jdd�}d
  61  |dvs6J�tj|jdd�}d|dvsFJ�dS)NcSs||S)zAdds two numbersr)r1r�rrr�
  62  simple_add*rcz)test_property_sources.<locals>.simple_addcs8eZdZedd��Ze�dd��Zeej�Ze��Z	dS)z test_property_sources.<locals>.AcSr7�N�barrr^rrr�foo/r_z$test_property_sources.<locals>.A.foocSst|d|�Sr�)�setattr)rH�vrrr�<lambda>3sz)test_property_sources.<locals>.A.<lambda>N)
  63  rrrr�r��setterrr��dname�adderr�r�rrr�.s
  64  
  65  r�rGrtzdef foo(self):rpzlambda self, v:zdef getdoc(obj)zdef simple_add(a, b))r�r
  66  rur�r�r�)r�rzrr�r�test_property_sources's
  67  r�cCs^Gdd�dt�}|�tjd<dtjddd�dksJ�|tjd	<dtjd
  68  dd�dks-J�dS)Nc@seZdZedd��ZdS)z@test_property_docstring_is_in_info_for_detail_level_0.<locals>.AcSr7)�This is `foobar` property.Nrr^rrr�foobarEszGtest_property_docstring_is_in_info_for_detail_level_0.<locals>.A.foobarN)rrrr�r�rrrrr�Dsr�Za_objr�za_obj.foobarrrtroZa_clsza_cls.foobar)r�rC�user_nsZobject_inspect)r�rrr�5test_property_docstring_is_in_info_for_detail_level_0Cs�
  69  �r�cCsdd�}t�|d�dS)NcSr�rrrrrrr�Yr;ztest_pdef.<locals>.foor�)r
  70  Zpdef�r�rrr�	test_pdefWsr�c	kst�z%ttj���}tj�|�dVWttj���|}|D]}tj|=qdSttj���|}|D]}tj|=q2w)z�
  71      On exit delete all the keys that were not in user_ns before entering.
  72  
  73      It does not restore old values !
  74  
  75      Parameters
  76      ----------
  77  
  78      **kwargs
  79          used to update ip.user_ns
  80  
  81      N)�setrCr��keys�update)�kwargsZknown�added�krrr�cleanup_user_ns]s�
  82  ��
  83  �r�cCsTGdd�d�}|�}t|d��tjdddd�Wd�dS1s#wYdS)	z8
  84      Test that bool method is not called on parent.
  85      c@seZdZdZdd�ZdS)z(test_pinfo_bool_raise.<locals>.RaiseBoolNcSr`)Nz#pinfo should not access this method)�
  86  ValueErrorr^rrrrb}r\z1test_pinfo_bool_raise.<locals>.RaiseBool.__bool__)rrr�attrrbrrrr�	RaiseBoolzsr�)�
  87  raise_bool�pinfozraise_bool.attrrrtN)r�rC�_inspect)r�r�rrr�test_pinfo_bool_raiseus
  88  "�r�c	Cs�dd�}|g}t|d��$td��tjdddd�Wd�n1s$wYWd�n1s3wYd	tj��vsAJ�dS)
  89  NcSr7)z
  90          MARKER
  91          Nrrrrr�dummy�r;z"test_pinfo_getindex.<locals>.dummy��	container�MARKERr�zcontainer[0]rrtr�)r�r	rCr�r�r��r�r�rrr�test_pinfo_getindex�s
  92  ���r�c	C�dd�}|g}t|d��!td��
  93  t�d�Wd�n1s!wYWd�n1s0wYdtj��vs>J�dS)NcSr7)z
  94          MARKER 2
  95          Nrrrrrr��r;z"test_qmark_getindex.<locals>.dummyr�zMARKER 2z
  96  container[0]?r��r�r	rC�run_cellr�r�r�rrr�test_qmark_getindex��
  97  ���r�c	Cr�)NcSr7)z
  98          MARKER 3
  99          Nrrrrrr��r;z*test_qmark_getindex_negatif.<locals>.dummyr�zMARKER 3zcontainer[-1]?r�r�r�rrr�test_qmark_getindex_negatif�r�r�cCs*ddlm}|tjd<tjdddd�dS)NrG��	nonascii2r�r�rt)�r�rCr�r�r�rrr�test_pinfo_nonascii�s
 100  r�cCst�dd�dS)zO
 101      type can fail in various edge case, for example `type.__subclass__()`
 102      r�rN)rCr�rrrr�test_pinfo_type�sr�cCsvtd��tjdddd�Wd�n1swYtd��tjdddd�Wd�dS1s4wYdS)zFDocstring should be included with detail_level=1 if there is no source�
 103  Docstring:r�z
 104  str.formatrrtNrG�r	rCr�rrrr�test_pinfo_docstring_no_source�s
 105  �
 106  "�r�cCs�dd�}|tjd<td��tjdddd�Wd�n1s wYtd	��tjddd
 107  d�Wd�n1s<wYtd��tjddd
 108  d�Wd�dS1sYwYdS)zGDocstring should not be included with detail_level=1 if source is foundcSr7)zfoo has a docstringNrrrrrr��r;z.test_pinfo_no_docstring_if_source.<locals>.foor�r�r�rrtN�Source:rG)rCr�r	r�r
 109  r�rrr�!test_pinfo_no_docstring_if_source�s
 110  
 111  �
 112  �
 113  "�r�c	Cs^d}t�|�t�d�td��\td��tjdddd�Wd	�n1s(wYtd��tjddd
 114  d�Wd	�n1sDwYtd��tjdddd�Wd	�n1s`wYWd	�n1sowYtd��-td��tjddd
 115  d�Wd	�n1s�wYWd	�d	SWd	�d	S1s�wYd	S)z< Docstring should be displayed if source info not available z�class Foo(object):
 116                    """ This is a docstring for Foo """
 117                    def bar(self):
 118                        """ This is a docstring for Foo.bar """
 119                        pass
 120                zfoo = Foo()r�r�r�r�rrtNrGzfoo.bar)rCr�r
 121  r	r�)�obj_defrrr�,test_pinfo_docstring_if_detail_and_no_source�s,
 122  
 123  
 124  
 125  �
 126  �
 127  ���
 128  
 129  ��"�r�)�final�	candidatezfails on 3.13.devT)�reason�strictcCs�d}t�|�t�d�t�dd�|��}t�d|j�sJ�t�dd�|��}t�d|j�s2J�t�d�|��}t�d|j�sDJ�t�d	�|��}t�d|j�sVJ�t�d
 130  �|��}t�d|j�shJ�dS)Na2class Bar:
 131      __custom_documentations__ = {
 132       "prop" : "cdoc for prop",
 133       "non_exist" : "cdoc for non_exist",
 134      }
 135      @property
 136      def prop(self):
 137          '''
 138          Docstring for prop
 139          '''
 140          return self._prop
 141      
 142      @prop.setter
 143      def prop(self, v):
 144          self._prop = v
 145      z	b = Bar()r�zb.propzDocstring:\s+cdoc for propzb.non_existzDocstring:\s+cdoc for non_existzb.prop?zb.non_exist?zb.undefined?zType:\s+NoneType)rCr�Zrun_line_magicZ
 146  readouterrr&rw�out)Zcapsysr�Zcapturedrrr�test_pinfo_docstring_dynamic�s$
 147  
 148  
 149  
 150  
 151  r�cCsvtd��tjdddd�Wd�n1swYtd��tjdddd�Wd�dS1s4wYdS)Nr�r�Zlsmagicrrtr�rGr�rrrr�test_pinfo_magics
 152  �
 153  "�r�cCs"t�t�}|d}d|vsJ�dS)Nrrz[0m)r
 154  rurR�ruZinit_defrrr�test_init_colors"s
 155  r�cCs"t�t�}|d}|dusJ�dS)Nrr)r
 156  ru�listr�rrr�test_builtin_init)s
 157  r�cCs,ddd�}t�t|�|j�}|dksJ�dS)NrGcSr�rr)r1rrr�	short_fun0r;z.test_render_signature_short.<locals>.short_funzshort_fun(a=1)rP)r�_render_signaturerr)r��sigrrr�test_render_signature_short/s
 158  �r�c	CsVddlm}		ddtdtd|tdtfdd	�}t�t|�|j�}d
 159  }||ks)J�dS)Nr)�OptionalF�a_really_long_parameter�and_another_long_one�let_us_make_sure_this_is_looong�returncSr�rr)r�r�r�rrr�
 160  long_function;sz1test_render_signature_long.<locals>.long_functionz�long_function(
 161      a_really_long_parameter: int,
 162      and_another_long_one: bool = False,
 163      let_us_make_sure_this_is_looong: Optional[str] = None,
 164  ) -> bool)FN)	�typingr��int�boolrvrr�rr)r�r�r��expectedrrr�test_render_signature_long8s$����
 165  ��r�rQ)Ir=�
 166  contextlibrrrrrr#rr&�sysr�rrZIPython.testing.toolsr	r
 167  ZIPython.utils.pathrr
 168  rrrrrr"r)r,r.r>rArDr�rErRrWrXr]rdr|r}rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��markZxfail�version_info�releaselevelr�r�r�r�r�r�rrrr�<module>s�
 169  %
 170  
 171  
 172  
 173  
 174  �
 175  *