Format: application/x-python-code
⬇ Download File (17.0 KB)
   1  o
   2  
   3  ��h�9�
   4  @s�dZddlmZmZmZmZmZddlZddlZddl	Z	ddl
   5  Z
   6  ddlZddlZddlZddl
   7  mZddlmZGdd�de�ZGdd	�d	e�ZGd
   8  d�de�ZGdd
   9  �d
  10  e�ZGdd�de�ZGdd�de�Zde_Gdd�de�ZGdd�de�ZGdd�de�Zdd�Zdd�Zdd�Zej �!de"e#�e$�e#dg�e$dg�e#dd g�e$dd g�e#gd!��ggd"���d#d$��Z%d%d&�Z&d'd(�Z'd)d*�Z(d+d,�Z)d-d.�Z*Gd/d0�d0e+�Z,Gd1d2�d2e�Z-d3d4�Z.Gd5d6�d6e�Z/Gd7d8�d8e/�Z0Gd9d:�d:ej1�Z2Gd;d<�d<e3�Z4e4d=�Z5d>d?�Z6d@dA�Z7dBdC�Z8dDdE�Z9dFdG�Z:dHdI�Z;dJdK�Z<dLdM�Z=dNdO�Z>dPdQ�Z?dRdS�Z@dTdU�ZAGdVdW�dWee�ZBGdXdY�dYe#�ZCdZd[�ZDdS)\zTests for IPython.lib.pretty.�)�Counter�defaultdict�deque�OrderedDict�UserListN��pretty)�StringIOc@�eZdZdd�Zdd�ZdS)�MyListcCs
  11  ||_dS�N)�content)�selfr
  12  �r�Sc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/lib/tests/test_pretty.py�__init__�
  13  zMyList.__init__cCs�|r	|�d�dS|�ddd��)t|j�D]\}}|r&|�d�|��n|�d�|�|�qWd�dS1s<wYdS)NzMyList(...)�zMyList(�)�,�)�text�group�	enumerater
  14  Z	breakabler)r�p�cycle�i�childrrr�
  15  _repr_pretty_s
  16  
  17  
  18  �"�zMyList._repr_pretty_N)�__name__�
  19  __module__�__qualname__rrrrrrrsrc@�eZdZdd�ZdS)�MyDictcC�|�d�dS)N�MyDict(...)�r�rrrrrrr)�zMyDict._repr_pretty_N�rr r!rrrrrr#(�r#c@r")�MyObjcCsdSrr�rrrr�
  20  somemethod-��MyObj.somemethodN)rr r!r-rrrrr+,r*r+c@r")�Dummy1cCr$)N�Dummy1(...)r&r'rrrr2r(zDummy1._repr_pretty_Nr)rrrrr01r*r0c@seZdZdZdS)�Dummy2Nr)rrrrr25sr2c@�eZdZdS)�NoModuleN�rr r!rrrrr48�r4c@r")�BreakingcCsP|�ddd��|�d�|��|�d�Wd�dS1s!wYdS)N�zTG: �:z	Breaking(r)rrZbreak_r'rrrr>s
  21  
  22  "�zBreaking._repr_pretty_Nr)rrrrr7=r*r7c@r")�BreakingReprcC�dS)NzBreaking(
  23  )rr,rrr�__repr__Er.zBreakingRepr.__repr__N�rr r!r<rrrrr:Dr*r:c@r")�BadReprcCsddS)N�rrr,rrrr<IszBadRepr.__repr__Nr=rrrrr>Hr*r>cCsFd}t�tt|���}dd�dd�t|�D��d}||ks!J�dS)z"Test correct indentation in groups�(zMyList(
  24  z,
  25  css�|]}d|VqdS)z   %dNr��.0rrrr�	<genexpr>Q��z#test_indentation.<locals>.<genexpr>rN)rr�range�join)�count�	gotoutput�expectedoutputrrr�test_indentationMs rJcC� t�t��}d}||ksJ�dS)z�
  26      Test correct dispatching: The _repr_pretty_ method for MyDict
  27      must be found before the registered printer for dict.
  28      r%N)rr#�rHrIrrr�
  29  test_dispatchV�rMcCrK)z^
  30      Test that the _repr_pretty_ method is tested for callability and skipped if
  31      not.
  32      r1N)rr2rLrrr�test_callability_checkingarNrOzobj,expected_outputr?�)���������������)zset()zfrozenset()z{1}zfrozenset({1})z{1, 2}zfrozenset({1, 2})z{-3, -2, -1}cCst�|�}||ksJ�dS)z>
  33      Test that set and frozenset use Python 3 formatting.
  34      Nr)�obj�expected_outputZ
  35  got_outputrrr�	test_setsls
  36  rVcCs<d}tjdkr	dnd}t�|�}t�|j�}||ksJ�dS)z:
  37      Test that pprint works for heap allocated types.
  38      Zxxlimited_35)r�
  39  �zxxlimited.Nullzxxlimited_35.NullN)�sys�version_info�pytestZimportorskiprZNull)�module_namerUZ	xxlimited�outputrrr�test_pprint_heap_allocated_type�s�
  40  r^cCst�t�}|dksJ�dS)z@
  41      Test that pprint works for classes with no __module__.
  42      r4N)rr4�r]rrr�test_pprint_nomod�s
  43  r`cCrK)z5
  44      Test that p.break_ produces expected output
  45      zTG: Breaking(
  46      ):N)rr7�r]�expectedrrr�test_pprint_break�srccCsHt�t�gg�}d}||ksJ�t�t�gdg�}d}||ks"J�dS)z,
  47      Test that p.break_ is used in repr
  48      z[[Breaking(
  49    )]]rPz"[[Breaking(
  50    ),
  51    Breaking(
  52    )]]N)rr:rarrr�test_pprint_break_repr�srdcCs<t�t��t�t��Wd�dS1swYdS)zDon't catch bad repr errorsN)r[�raises�ZeroDivisionErrorrr>rrrr�
  53  test_bad_repr�s"�rgc@r")�BadExceptioncCr;)NrQrr,rrr�__str__�r.zBadException.__str__N)rr r!rirrrrrh�r*rhc@s$eZdZdZedd��Zdd�ZdS)�
  54  ReallyBadReprr?cCstd��)Nz
  55  I am horrible)�
  56  ValueErrorr,rrr�	__class__�szReallyBadRepr.__class__cCst��r)rhr,rrrr<�szReallyBadRepr.__repr__N)rr r!�propertyrlr<rrrrrj�s
  57  
  58  rjcCs<t�t��t�t��Wd�dS1swYdSr)r[rerhrrjrrrr�test_really_bad_repr�s"�rnc@r3)�SANr5rrrrro�r6roc@r3)�SBNr5rrrrrp�r6rpcsDeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
  59  �Zdd�Z�Z	S)
  60  �TestsPrettycs@t�tt��}|�|d�t�}t�tt|��}|�|d�dS)Nz<super: \S+.SA, None>z$<super: \S+.SA,\s+<\S+.SB at 0x\S+>>)r�superro�assertRegexrp)rr]�sb�rlrr�test_super_repr�s
  61  zTestsPretty.test_super_reprcC�>ttd��}t�|�}|�dd�dd�}|�|ddg�dS)N�'�
  62  rPrR� 999,z ...])�listrEr�rsplit�assertEqual)rZlisr�last2rrr�test_long_list��
  63  zTestsPretty.test_long_listcCrw)NrxryrPrRrz� ...})�setrErr|r})r�srr~rrr�
  64  test_long_set�r�zTestsPretty.test_long_setcCrw)NrxryrPrRrzz ...))�tuplerErr|r})r�tuprr~rrr�test_long_tuple�r�zTestsPretty.test_long_tuplecCsDdd�td�D�}t�|�}|�dd�dd�}|�|ddg�dS)	NcSsi|]}||�qSrr)rB�nrrr�
  65  <dictcomp>�sz.TestsPretty.test_long_dict.<locals>.<dictcomp>rxryrPrRz
  66   999: 999,r�)rErr|r})r�drr~rrr�test_long_dict�s
  67  zTestsPretty.test_long_dictcCst�tj�}|�d|�dS)Nr/)rr+r-ZassertIn)rr]rrr�test_unbound_method�szTestsPretty.test_unbound_method)
  68  rr r!rvrr�r�r�r��
  69  __classcell__rrrurrq�srqc@r
  70  )�	MetaClasscCst�||tfd|i�S)N�name)�type�__new__�object)�clsr�rrrr��szMetaClass.__new__cCs
  71  d|jS)Nz[CUSTOM REPR FOR CLASS %s])r�r,rrrr<�rzMetaClass.__repr__N)rr r!r�r<rrrrr��sr��
  72  ClassWithMetacCst�t�}|dksJ�dS)Nz%[CUSTOM REPR FOR CLASS ClassWithMeta])rr�r_rrr�test_metaclass_reprs
  73  r�csXd}|�G�fdd�dt�}|�}t�|�}||ksJ�t�|g�}|d|ks*J�dS)Nu
  74  üniçodécseZdZ�fdd�ZdS)ztest_unicode_repr.<locals>.Ccs�Srrr,�Zustrrrr<r.z%test_unicode_repr.<locals>.C.__repr__Nr=rr�rr�Csr�z[%s])r�r)�ur��crrr�r�test_unicode_reprs
  75  r�csh�fdd��d�_t�}t�|�}�|jt<|�t�|��|��}|dt	ks+J��jdus2J�dS)Ncs|turd�_t�|||�S)NT)r+�calledrZ_type_pprint)rTrr��type_pprint_wrapperrrr�sz-test_basic_class.<locals>.type_pprint_wrapperFz%s.MyObjT)
  76  r�r	rZRepresentationPrinterZtype_pprintersr�r+�flush�getvaluer)�stream�printerr]rr�r�test_basic_classs
  77  
  78  
  79  r�cC�`t�}|�|�t�dftdd�tdd�D��df|dfg}|D]
  80  \}}t�|�|ks-J�q dS)NzUserList([])cs��|]}|VqdSrrrArrrrC4��z,test_collections_userlist.<locals>.<genexpr>����a@UserList([1000,
  81            1001,
  82            1002,
  83            1003,
  84            1004,
  85            1005,
  86            1006,
  87            1007,
  88            1008,
  89            1009,
  90            1010,
  91            1011,
  92            1012,
  93            1013,
  94            1014,
  95            1015,
  96            1016,
  97            1017,
  98            1018,
  99            1019])zUserList([UserList(...)]))r�appendrEr��a�casesrTrbrrr�test_collections_userlist,s
 100  ���r�cCsjt�}||_tt�}||d<tt�dfttddi�df|df|dfg}|D]
 101  \}}t�|�|ks2J�q%dS)N�keyzdefaultdict(list, {})z2--------------------------------------------------z\defaultdict(list,
 102              {'key': '--------------------------------------------------'})z!defaultdict(defaultdict(...), {})z,defaultdict(list, {'key': defaultdict(...)}))r�default_factoryr{r)r��br�rTrbrrr�test_collections_defaultdictQs
 103  ���r�cCs^t�}||d<t�dftdd�tdd�D��df|dfg}|D]
 104  \}}t�|�|ks,J�qdS)	Nr�z
 105  OrderedDict()css�|]}||fVqdSrrrArrrrCmrDz/test_collections_ordereddict.<locals>.<genexpr>r�i�aOrderedDict([(1000, 1000),
 106               (1001, 1001),
 107               (1002, 1002),
 108               (1003, 1003),
 109               (1004, 1004),
 110               (1005, 1005),
 111               (1006, 1006),
 112               (1007, 1007),
 113               (1008, 1008),
 114               (1009, 1009)])z(OrderedDict([('key', OrderedDict(...))]))rrErr�rrr�test_collections_ordereddictfs���r�cCr�)Nz	deque([])csr�rrrArrrrC�r�z)test_collections_deque.<locals>.<genexpr>r�r�adeque([1000,
 115         1001,
 116         1002,
 117         1003,
 118         1004,
 119         1005,
 120         1006,
 121         1007,
 122         1008,
 123         1009,
 124         1010,
 125         1011,
 126         1012,
 127         1013,
 128         1014,
 129         1015,
 130         1016,
 131         1017,
 132         1018,
 133         1019])zdeque([deque(...)]))rr�rErr�rrr�test_collections_deques
 134  ���r�cCsfGdd�dt�}t�dftdd�df|dd�dftddd	�d
 135  fg}|D]
 136  \}}t�|�|ks0J�q#dS)Nc@r3)z+test_collections_counter.<locals>.MyCounterNr5rrrr�	MyCounter�r6r�z	Counter()r?)r�zCounter({'a': 1})zMyCounter({'a': 1})�)r�r�zCounter({'c': 22, 'a': 1}))rr)r�r�rTrbrrr�test_collections_counter�s��r�cCs�tj}i}||�}||d<||d<|i�df|d|i�i�df|dd�tjD��df|df|d	fg}|D]
 137  \}}t�|�|ksAJ�q4dS)
 138  NrPrzmappingproxy({})z&mappingproxy({None: mappingproxy({})})cSsi|]}||���qSr)�upper)rB�krrrr��sz%test_mappingproxy.<locals>.<dictcomp>apmappingproxy({'a': 'A',
 139                'b': 'B',
 140                'c': 'C',
 141                'd': 'D',
 142                'e': 'E',
 143                'f': 'F',
 144                'g': 'G',
 145                'h': 'H',
 146                'i': 'I',
 147                'j': 'J',
 148                'k': 'K',
 149                'l': 'L',
 150                'm': 'M',
 151                'n': 'N',
 152                'o': 'O',
 153                'p': 'P',
 154                'q': 'Q',
 155                'r': 'R',
 156                's': 'S',
 157                't': 'T',
 158                'u': 'U',
 159                'v': 'V',
 160                'w': 'W',
 161                'x': 'X',
 162                'y': 'Y',
 163                'z': 'Z'})z1mappingproxy({2: {...}, 3: {2: {...}, 3: {...}}})z1{2: mappingproxy({2: {...}, 3: {...}}), 3: {...}})�types�MappingProxyType�string�ascii_lowercaser)ZMPZunderlying_dictZmp_recursiver�rTrbrrr�test_mappingproxy�s$
 164  ���"�r�cCsxtj}|�}||_||_|�df||�d�df||tjd�gddd�df|dfg}|D]
 165  \}}t�|�|ks9J�q,dS)	Nznamespace())�xznamespace(x=namespace()))r�r)Za_long_nameZa_short_namez�namespace(a_long_name=[namespace(s='abcdefghijklmnopqrstuvwxyz'),
 166                         namespace(s='abcdefghijklmnopqrstuvwxyz'),
 167                         namespace(s='abcdefghijklmnopqrstuvwxyz')],
 168            a_short_name=None)z6namespace(first=namespace(...), second=namespace(...)))r��SimpleNamespace�first�secondr�r�r)ZSNZsn_recursiver�rTrbrrr�test_simplenamespace�s��
 169  �r�cCsHt�ttj��}|�dddtd��}t�tj�}|d|ks"J�dS)Nry� �environ)r�dict�osr��replace�len)Z	dict_reprZ
 170  dict_indentedZenv_reprrrr�test_pretty_environ�sr�cCs<ddl}t�|j�dksJ�ddd�}dt�|�vsJ�dS)zTest pretty print of functionrNz <function posixpath.join(a, *p)>cSs|rdSdS)N�*zDon't panicr)�questionrrr�meaning_of_lifesz-test_function_pretty.<locals>.meaning_of_lifezmeaning_of_life(question=None)r)�	posixpathrrF)r�r�rrr�test_function_pretty�s
 171  r�c@s eZdZdZdd�Zdd�ZdS)�OrderedCounterz?Counter that remembers the order elements are first encounteredcCsd|jjt|�fS)Nz%s(%r))rlrrr,rrrr<
 172  szOrderedCounter.__repr__cCs|jt|�ffSr)rlrr,rrr�
 173  __reduce__szOrderedCounter.__reduce__N)rr r!�__doc__r<r�rrrrr�
 174  sr�c@r")�MySetcCr;)N�minerr,rrrr<r.zMySet.__repr__Nr=rrrrr�r*r�cCs2td�}dt�|�vs
 175  J�t�t��dksJ�dS)z@A custom repr should override a pretty printer for a parent typeZabracadabrazOrderedCounter(OrderedDictr�N)r�rr�)�ocrrr�test_custom_reprsr�)Er��collectionsrrrrrr�r[r�r�rYZunittestZIPython.libr�ior	r�rr�r#r+r0r2r4r r7r:r>rJrMrO�markZparametrize�zipr��	frozensetrVr^r`rcrdrg�	ExceptionrhrjrnrorpZTestCaserqr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>s�	
 176  
 177  
 178  �	��
 179  
 180  	*%#
 181  .