o
    Zh9                     @   s  d Z ddlmZmZ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ZddlZddlmZ ddlm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eZG dd deZde_G dd deZG dd deZG dd deZdd Zdd Zdd Zej !de"e# e$ e#dge$dge#dd ge$dd ge#g d!gg d"d#d$ Z%d%d& Z&d'd( Z'd)d* Z(d+d, Z)d-d. Z*G d/d0 d0e+Z,G d1d2 d2eZ-d3d4 Z.G d5d6 d6eZ/G d7d8 d8e/Z0G d9d: d:ej1Z2G d;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 ZAG dVdW dWeeZBG dXdY dYe#ZCdZd[ ZDdS )\zTests for IPython.lib.pretty.    )CounterdefaultdictdequeOrderedDictUserListNpretty)StringIOc                   @      e Zd Zdd Zdd ZdS )MyListc                 C   s
   || _ d S N)content)selfr    r   T/var/www/html/lang_env/lib/python3.10/site-packages/IPython/lib/tests/test_pretty.py__init__      
zMyList.__init__c                 C   s   |r	| d d S |ddd) t| jD ]\}}|r&| d |  n|d || qW d    d S 1 s<w   Y  d S )NzMyList(...)   zMyList(), )textgroup	enumerater   Z	breakabler   )r   pcycleichildr   r   r   _repr_pretty_   s   


"zMyList._repr_pretty_N)__name__
__module____qualname__r   r   r   r   r   r   r      s    r   c                   @      e Zd Zdd ZdS )MyDictc                 C      | d d S )NMyDict(...)r   r   r   r   r   r   r   r   )      zMyDict._repr_pretty_Nr   r    r!   r   r   r   r   r   r#   (       r#   c                   @   r"   )MyObjc                 C   s   d S r   r   r   r   r   r   
somemethod-      MyObj.somemethodN)r   r    r!   r-   r   r   r   r   r+   ,   r*   r+   c                   @   r"   )Dummy1c                 C   r$   )NDummy1(...)r&   r'   r   r   r   r   2   r(   zDummy1._repr_pretty_Nr)   r   r   r   r   r0   1   r*   r0   c                   @   s   e Zd ZdZdS )Dummy2Nr)   r   r   r   r   r2   5   s    r2   c                   @      e Zd ZdS )NoModuleNr   r    r!   r   r   r   r   r4   8       r4   c                   @   r"   )Breakingc                 C   sP   | ddd |d |  |d W d    d S 1 s!w   Y  d S )N   zTG: :z	Breaking(r   )r   r   Zbreak_r'   r   r   r   r   >   s
   
"zBreaking._repr_pretty_Nr)   r   r   r   r   r7   =   r*   r7   c                   @   r"   )BreakingReprc                 C      dS )NzBreaking(
)r   r,   r   r   r   __repr__E   r.   zBreakingRepr.__repr__Nr   r    r!   r<   r   r   r   r   r:   D   r*   r:   c                   @   r"   )BadReprc                 C   s   dd S )N   r   r   r,   r   r   r   r<   I   s   zBadRepr.__repr__Nr=   r   r   r   r   r>   H   r*   r>   c                  C   sF   d} t  tt| }dddd t| D  d }||ks!J dS )z"Test correct indentation in groups(   zMyList(
z,
c                 s   s    | ]}d | V  qdS )z   %dNr   .0r   r   r   r   	<genexpr>Q       z#test_indentation.<locals>.<genexpr>r   N)r   r   rangejoin)count	gotoutputexpectedoutputr   r   r   test_indentationM   s    rJ   c                  C       t  t } d}| |ksJ dS )z
    Test correct dispatching: The _repr_pretty_ method for MyDict
    must be found before the registered printer for dict.
    r%   N)r   r#   rH   rI   r   r   r   test_dispatchV      rM   c                  C   rK   )z^
    Test that the _repr_pretty_ method is tested for callability and skipped if
    not.
    r1   N)r   r2   rL   r   r   r   test_callability_checkinga   rN   rO   zobj,expected_outputr?      ))zset()zfrozenset()z{1}zfrozenset({1})z{1, 2}zfrozenset({1, 2})z{-3, -2, -1}c                 C   s   t  | }||ksJ dS )z>
    Test that set and frozenset use Python 3 formatting.
    Nr   )objexpected_outputZ
got_outputr   r   r   	test_setsl   s   
rV   c                  C   s<   d} t jdk r	dnd}t| }t|j}||ksJ dS )z:
    Test that pprint works for heap allocated types.
    Zxxlimited_35)r   
      zxxlimited.Nullzxxlimited_35.NullN)sysversion_infopytestZimportorskipr   ZNull)module_namerU   Z	xxlimitedoutputr   r   r   test_pprint_heap_allocated_type   s   
r^   c                  C   s   t  t} | dksJ dS )z@
    Test that pprint works for classes with no __module__.
    r4   N)r   r4   r]   r   r   r   test_pprint_nomod   s   
r`   c                  C   rK   )z5
    Test that p.break_ produces expected output
    zTG: Breaking(
    ):N)r   r7   r]   expectedr   r   r   test_pprint_break   s   rc   c                  C   sH   t  t gg} d}| |ksJ t  t gd g} d}| |ks"J dS )z,
    Test that p.break_ is used in repr
    z[[Breaking(
  )]]rP   z"[[Breaking(
  ),
  Breaking(
  )]]N)r   r:   ra   r   r   r   test_pprint_break_repr   s   rd   c                   C   s<   t t tt  W d   dS 1 sw   Y  dS )zDon't catch bad repr errorsN)r[   raisesZeroDivisionErrorr   r>   r   r   r   r   test_bad_repr   s   "rg   c                   @   r"   )BadExceptionc                 C   r;   )NrQ   r   r,   r   r   r   __str__   r.   zBadException.__str__N)r   r    r!   ri   r   r   r   r   rh      r*   rh   c                   @   s$   e Zd ZdZedd Zdd ZdS )ReallyBadReprr?   c                 C   s   t d)NzI am horrible)
ValueErrorr,   r   r   r   	__class__   s   zReallyBadRepr.__class__c                 C   s   t  r   )rh   r,   r   r   r   r<      s   zReallyBadRepr.__repr__N)r   r    r!   propertyrl   r<   r   r   r   r   rj      s
    
rj   c                   C   s<   t t tt  W d    d S 1 sw   Y  d S r   )r[   re   rh   r   rj   r   r   r   r   test_really_bad_repr   s   "rn   c                   @   r3   )SANr5   r   r   r   r   ro      r6   ro   c                   @   r3   )SBNr5   r   r   r   r   rp      r6   rp   c                       sD   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Z  Z	S )TestsPrettyc                    s@   t  tt}| |d t }t  tt|}| |d d S )Nz<super: \S+.SA, None>z$<super: \S+.SA,\s+<\S+.SB at 0x\S+>>)r   superro   assertRegexrp   )r   r]   sbrl   r   r   test_super_repr   s
   zTestsPretty.test_super_reprc                 C   >   t td}t|}|dddd  }| |ddg d S )N'  
rP   rR    999,z ...])listrE   r   rsplitassertEqual)r   Zlisr   last2r   r   r   test_long_list      
zTestsPretty.test_long_listc                 C   rw   )Nrx   ry   rP   rR   rz    ...})setrE   r   r|   r}   )r   sr   r~   r   r   r   test_long_set   r   zTestsPretty.test_long_setc                 C   rw   )Nrx   ry   rP   rR   rz   z ...))tuplerE   r   r|   r}   )r   tupr   r~   r   r   r   test_long_tuple   r   zTestsPretty.test_long_tuplec                 C   sD   dd t dD }t|}|dddd  }| |ddg d S )	Nc                 S   s   i | ]}||qS r   r   )rB   nr   r   r   
<dictcomp>   s    z.TestsPretty.test_long_dict.<locals>.<dictcomp>rx   ry   rP   rR   z
 999: 999,r   )rE   r   r|   r}   )r   dr   r~   r   r   r   test_long_dict   s   
zTestsPretty.test_long_dictc                 C   s   t  tj}| d| d S )Nr/   )r   r+   r-   ZassertIn)r   r]   r   r   r   test_unbound_method   s   zTestsPretty.test_unbound_method)
r   r    r!   rv   r   r   r   r   r   __classcell__r   r   ru   r   rq      s    rq   c                   @   r
   )	MetaClassc                 C   s   t | |tfd|iS )Nname)type__new__object)clsr   r   r   r   r      s   zMetaClass.__new__c                 C   s
   d| j  S )Nz[CUSTOM REPR FOR CLASS %s])r   r,   r   r   r   r<      r   zMetaClass.__repr__N)r   r    r!   r   r<   r   r   r   r   r      s    r   ClassWithMetac                  C   s   t  t} | dksJ d S )Nz%[CUSTOM REPR FOR CLASS ClassWithMeta])r   r   r_   r   r   r   test_metaclass_repr  s   
r   c                     sX   d} |  G  fdddt }| }t|}|| ksJ t|g}|d|  ks*J d S )Nu
   üniçodéc                       s   e Zd Z fddZdS )ztest_unicode_repr.<locals>.Cc                    s    S r   r   r,   Zustrr   r   r<     r.   z%test_unicode_repr.<locals>.C.__repr__Nr=   r   r   r   r   C  s    r   z[%s])r   r   )ur   cr   r   r   r   test_unicode_repr  s   
r   c                     sh    fdd d _ t } t| } |jt< |t |  |  }|dt	 ks+J  j du s2J d S )Nc                    s   | t u rd _t| ||S )NT)r+   calledr   Z_type_pprint)rT   r   r   type_pprint_wrapperr   r   r     s   z-test_basic_class.<locals>.type_pprint_wrapperFz%s.MyObjT)
r   r	   r   ZRepresentationPrinterZtype_pprintersr   r+   flushgetvaluer   )streamprinterr]   r   r   r   test_basic_class  s   


r   c                  C   `   t  } | |  t  dft dd tddD df| dfg}|D ]\}}t||ks-J q d S )NzUserList([])c                 s       | ]}|V  qd S r   r   rA   r   r   r   rC   4      z,test_collections_userlist.<locals>.<genexpr>    a@  UserList([1000,
          1001,
          1002,
          1003,
          1004,
          1005,
          1006,
          1007,
          1008,
          1009,
          1010,
          1011,
          1012,
          1013,
          1014,
          1015,
          1016,
          1017,
          1018,
          1019])zUserList([UserList(...)]))r   appendrE   r   acasesrT   rb   r   r   r   test_collections_userlist,  s   
r   c                  C   sj   t  } | | _t t}||d< t tdft tddidf| df|dfg}|D ]\}}t||ks2J q%d S )Nkeyzdefaultdict(list, {})z2--------------------------------------------------z\defaultdict(list,
            {'key': '--------------------------------------------------'})z!defaultdict(defaultdict(...), {})z,defaultdict(list, {'key': defaultdict(...)}))r   default_factoryr{   r   )r   br   rT   rb   r   r   r   test_collections_defaultdictQ  s   
r   c                  C   s^   t  } | | d< t  dft dd tddD df| dfg}|D ]\}}t||ks,J qd S )	Nr   zOrderedDict()c                 s   s    | ]}||fV  qd S r   r   rA   r   r   r   rC   m  rD   z/test_collections_ordereddict.<locals>.<genexpr>r   i  a  OrderedDict([(1000, 1000),
             (1001, 1001),
             (1002, 1002),
             (1003, 1003),
             (1004, 1004),
             (1005, 1005),
             (1006, 1006),
             (1007, 1007),
             (1008, 1008),
             (1009, 1009)])z(OrderedDict([('key', OrderedDict(...))]))r   rE   r   r   r   r   r   test_collections_ordereddictf  s   r   c                  C   r   )Nz	deque([])c                 s   r   r   r   rA   r   r   r   rC     r   z)test_collections_deque.<locals>.<genexpr>r   r   a  deque([1000,
       1001,
       1002,
       1003,
       1004,
       1005,
       1006,
       1007,
       1008,
       1009,
       1010,
       1011,
       1012,
       1013,
       1014,
       1015,
       1016,
       1017,
       1018,
       1019])zdeque([deque(...)]))r   r   rE   r   r   r   r   r   test_collections_deque  s   
r   c                  C   sf   G dd dt } t  dft dddf| dddft ddd	d
fg}|D ]\}}t||ks0J q#d S )Nc                   @   r3   )z+test_collections_counter.<locals>.MyCounterNr5   r   r   r   r   	MyCounter  r6   r   z	Counter()r?   )r   zCounter({'a': 1})zMyCounter({'a': 1})   )r   r   zCounter({'c': 22, 'a': 1}))r   r   )r   r   rT   rb   r   r   r   test_collections_counter  s   r   c                  C   s   t j} i }| |}||d< ||d< | i df| d | i idf| dd tjD df|df|d	fg}|D ]\}}t||ksAJ q4d S )
NrP   r   zmappingproxy({})z&mappingproxy({None: mappingproxy({})})c                 S   s   i | ]}||  qS r   )upper)rB   kr   r   r   r     s    z%test_mappingproxy.<locals>.<dictcomp>ap  mappingproxy({'a': 'A',
              'b': 'B',
              'c': 'C',
              'd': 'D',
              'e': 'E',
              'f': 'F',
              'g': 'G',
              'h': 'H',
              'i': 'I',
              'j': 'J',
              'k': 'K',
              'l': 'L',
              'm': 'M',
              'n': 'N',
              'o': 'O',
              'p': 'P',
              'q': 'Q',
              'r': 'R',
              's': 'S',
              't': 'T',
              'u': 'U',
              'v': 'V',
              'w': 'W',
              'x': 'X',
              'y': 'Y',
              'z': 'Z'})z1mappingproxy({2: {...}, 3: {2: {...}, 3: {...}}})z1{2: mappingproxy({2: {...}, 3: {...}}), 3: {...}})typesMappingProxyTypestringascii_lowercaser   )ZMPZunderlying_dictZmp_recursiver   rT   rb   r   r   r   test_mappingproxy  s$   
"r   c                  C   sx   t j} |  }||_||_|  df| |  ddf| | tjdgd d ddf|dfg}|D ]\}}t||ks9J q,d S )	Nznamespace())xznamespace(x=namespace()))r   r   )Za_long_nameZa_short_nameznamespace(a_long_name=[namespace(s='abcdefghijklmnopqrstuvwxyz'),
                       namespace(s='abcdefghijklmnopqrstuvwxyz'),
                       namespace(s='abcdefghijklmnopqrstuvwxyz')],
          a_short_name=None)z6namespace(first=namespace(...), second=namespace(...)))r   SimpleNamespacefirstsecondr   r   r   )ZSNZsn_recursiver   rT   rb   r   r   r   test_simplenamespace  s   
r   c                  C   sH   t  ttj} | dddtd  }t  tj}|d| ks"J d S )Nry    environ)r   dictosr   replacelen)Z	dict_reprZdict_indentedZenv_reprr   r   r   test_pretty_environ  s   r   c                  C   s<   ddl } t| jdksJ ddd}dt|v sJ dS )zTest pretty print of functionr   Nz <function posixpath.join(a, *p)>c                 S   s   | rdS dS )N*   zDon't panicr   )questionr   r   r   meaning_of_life  s   z-test_function_pretty.<locals>.meaning_of_lifezmeaning_of_life(question=None)r   )	posixpathr   rF   )r   r   r   r   r   test_function_pretty  s   
r   c                   @   s    e Zd ZdZdd Zdd ZdS )OrderedCounterz?Counter that remembers the order elements are first encounteredc                 C   s   d| j jt| f S )Nz%s(%r))rl   r   r   r,   r   r   r   r<     s   zOrderedCounter.__repr__c                 C   s   | j t| ffS r   )rl   r   r,   r   r   r   
__reduce__  s   zOrderedCounter.__reduce__N)r   r    r!   __doc__r<   r   r   r   r   r   r   
  s    r   c                   @   r"   )MySetc                 C   r;   )Nminer   r,   r   r   r   r<     r.   zMySet.__repr__Nr=   r   r   r   r   r     r*   r   c                  C   s2   t d} dt| v sJ tt dksJ dS )z@A custom repr should override a pretty printer for a parent typeZabracadabrazOrderedCounter(OrderedDictr   N)r   r   r   )ocr   r   r   test_custom_repr  s   r   )Er   collectionsr   r   r   r   r   r   r[   r   r   rY   ZunittestZIPython.libr   ior	   r   r   r   r#   r+   r0   r2   r4   r    r7   r:   r>   rJ   rM   rO   markZparametrizezipr   	frozensetrV   r^   r`   rc   rd   rg   	Exceptionrh   rj   rn   ro   rp   ZTestCaserq   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s   	


	
	*%#.	