o
    Ďi9                     @   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   Y/home/jeff/fluffinator/venv/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   	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   r1   1   r+   r1   c                   @   s   e Zd ZdZdS )Dummy2Nr*   r   r   r   r   r3   5   s    r3   c                   @      e Zd ZdS )NoModuleNr    r!   r"   r   r   r   r   r5   8       r5   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   break_r(   r   r   r   r   >   s
   
"zBreaking._repr_pretty_Nr*   r   r   r   r   r8   =   r+   r8   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    rL   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$   rJ   rK   r   r   r   test_dispatchV      rO   c                  C   rM   )z^
    Test that the _repr_pretty_ method is tested for callability and skipped if
    not.
    r2   N)r   r3   rN   r   r   r   test_callability_checkinga   rP   rQ   zobj,expected_outputrA      ))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_output
got_outputr   r   r   	test_setsl   s   
rY   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.
    xxlimited_35)r   
      zxxlimited.Nullzxxlimited_35.NullN)sysversion_infopytestimportorskipr   Null)module_namerW   	xxlimitedoutputr   r   r   test_pprint_heap_allocated_type   s   
re   c                  C   s   t  t} | dksJ dS )z@
    Test that pprint works for classes with no __module__.
    r5   N)r   r5   rd   r   r   r   test_pprint_nomod   s   
rg   c                  C   rM   )z5
    Test that p.break_ produces expected output
    zTG: Breaking(
    ):N)r   r8   rd   expectedr   r   r   test_pprint_break   s   rj   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(
  )]]rR   z"[[Breaking(
  ),
  Breaking(
  )]]N)r   r<   rh   r   r   r   test_pprint_break_repr   s   rk   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   "rn   c                   @   r#   )BadExceptionc                 C   r=   )NrS   r   r-   r   r   r   __str__   r/   zBadException.__str__N)r    r!   r"   rp   r   r   r   r   ro      r+   ro   c                   @   s$   e Zd ZdZedd Zdd ZdS )ReallyBadReprrA   c                 C   s   t d)NzI am horrible)
ValueErrorr-   r   r   r   	__class__   s   zReallyBadRepr.__class__c                 C   s   t  r   )ro   r-   r   r   r   r>      s   zReallyBadRepr.__repr__N)r    r!   r"   propertyrs   r>   r   r   r   r   rq      s
    
rq   c                   C   s<   t t tt  W d    d S 1 sw   Y  d S r   )r_   rl   ro   r   rq   r   r   r   r   test_really_bad_repr   s   "ru   c                   @   r4   )SANr6   r   r   r   r   rv      r7   rv   c                   @   r4   )SBNr6   r   r   r   r   rw      r7   rw   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   superrv   assertRegexrw   )r   rd   sbrs   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'  
rR   rT    999,z ...])listrG   r   rsplitassertEqual)r   lisr   last2r   r   r   test_long_list      
zTestsPretty.test_long_listc                 C   r~   )Nr   r   rR   rT   r    ...})setrG   r   r   r   )r   sr   r   r   r   r   test_long_set   r   zTestsPretty.test_long_setc                 C   r~   )Nr   r   rR   rT   r   z ...))tuplerG   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   )rD   nr   r   r   
<dictcomp>   s    z.TestsPretty.test_long_dict.<locals>.<dictcomp>r   r   rR   rT   z
 999: 999,r   )rG   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 )Nr0   )r   r,   r.   assertIn)r   rd   r   r   r   test_unbound_method   s   zTestsPretty.test_unbound_method)
r    r!   r"   r}   r   r   r   r   r   __classcell__r   r   r|   r   rx      s    rx   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   rf   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-   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   _type_pprint)rV   r   r   type_pprint_wrapperr   r   r     s   z-test_basic_class.<locals>.type_pprint_wrapperFz%s.MyObjT)
r   r	   r   RepresentationPrintertype_pprintersr   r,   flushgetvaluer    )streamprinterrd   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   rC   r   r   r   rE   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   appendrG   r   acasesrV   ri   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   rV   ri   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   rC   r   r   r   rE   m  rF   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   rG   r   r   r   r   r   test_collections_ordereddictf  s   r   c                  C   r   )Nz	deque([])c                 s   r   r   r   rC   r   r   r   rE     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   rG   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                   @   r4   )z+test_collections_counter.<locals>.MyCounterNr6   r   r   r   r   	MyCounter  r7   r   z	Counter()rA   )r   zCounter({'a': 1})zMyCounter({'a': 1})   )r   r   zCounter({'c': 22, 'a': 1}))r   r   )r   r   rV   ri   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 )
NrR   r   zmappingproxy({})z&mappingproxy({None: mappingproxy({})})c                 S   s   i | ]}||  qS r   )upper)rD   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   )MPunderlying_dictmp_recursiver   rV   ri   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   )a_long_name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   )SNsn_recursiver   rV   ri   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 )Nr    environ)r   dictosr   replacelen)	dict_reprdict_indented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   rH   )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))rs   r    r   r-   r   r   r   r>     s   zOrderedCounter.__repr__c                 C   s   | j t| ffS r   )rs   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 type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   r]   unittestIPython.libr   ior	   r   r   r   r$   r,   r1   r3   r5   r!   r8   r<   r@   rL   rO   rQ   markparametrizezipr   	frozensetrY   re   rg   rj   rk   rn   	Exceptionro   rq   ru   rv   rw   TestCaserx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s   	


	
	*%#.	