a
    ze*                    @   s  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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mZ d dlmZ ejjrdd Zndd ZG dd dZG d	d
 d
ZG dd dee	jZG dd dee	jZG dd de	jZG dd de	jZG dd dejjZG dd dee	jZG dd dee	jZ G d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!e	jZ'G d#d$ d$e!e	jZ(e)d%kre	*  dS )&    N)bigaddrspacetestMAX_Py_ssize_t)assert_python_failurec                    s   t   fdd}|S )Nc                     sB   t jdtf  | i |W  d    S 1 s40    Y  d S N testsupportZcheck_warningsBytesWarning)argskwfunc %/usr/lib/python3.9/test/test_bytes.pywrapper   s    z%check_bytes_warnings.<locals>.wrapper)	functoolswraps)r   r   r   r   r   check_bytes_warnings   s    r   c                 C   s   | S Nr   r   r   r   r   r   "   s    c                   @   s   e Zd ZdddZdd ZdS )	Indexabler   c                 C   s
   || _ d S r   value)selfr   r   r   r   __init__'   s    zIndexable.__init__c                 C   s   | j S r   r   r   r   r   r   	__index__)   s    zIndexable.__index__N)r   )__name__
__module____qualname__r   r   r   r   r   r   r   &   s   
r   c                   @   sD  e 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dd Zdd Zdd Zedd Zdd Zdd Ze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/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Z d9d: Z!d;d< Z"d=d> Z#d?d@ Z$dAdB Z%dCdD Z&dEdF Z'dGdH Z(dIdJ Z)dKdL Z*dMdN Z+dOdP Z,dQdR Z-dSdT Z.dUdV Z/dWdX Z0dYdZ Z1d[d\ Z2d]d^ Z3d_d` Z4dadb Z5dcdd Z6dedf Z7dgdh Z8didj Z9dkdl Z:dmdn Z;dodp Z<dqdr Z=dsdt Z>dudv Z?dwdx Z@dydz ZAd{d| ZBd}d~ ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdS )BaseBytesTestc                 C   s.   |   }| t|| j  | |j| j  d S r   )	type2testassertEqualtype	__class__r   br   r   r   test_basics/   s    zBaseBytesTest.test_basicsc                 C   sH   |  d}tjtjfD ],}||}| || | t|t| qd S N   abcd)r!   copydeepcopyr"   r#   r   aZcopy_methodr&   r   r   r   	test_copy4   s
    
zBaseBytesTest.test_copyc                    s   |    | t d | t fdd | t fdd | t fdd | t fdd | t fdd | t fdd | t fd	d | t fd
d | t fdd | t fdd | t fdd d S )Nr   c                      s    d S )Nr   r   r   r&   r   r   <lambda>>       z3BaseBytesTest.test_empty_sequence.<locals>.<lambda>c                      s    d S N   r   r   r/   r   r   r0   ?   r1   c                      s
    t j S r   sysmaxsizer   r/   r   r   r0   @   r1   c                      s    t jd  S r2   r4   r   r/   r   r   r0   A   r1   c                      s    dd  S N
   d   r   r   r/   r   r   r0   B   r1   c                      s    d S Nr   r   r/   r   r   r0   C   r1   c                      s    d S )Nr   r   r/   r   r   r0   D   r1   c                      s    t j  S r   r4   r   r/   r   r   r0   E   r1   c                      s    t j d  S r2   r4   r   r/   r   r   r0   F   r1   c                      s    t j d  S )N   r4   r   r/   r   r   r0   G   r1   c                      s    dd   S r7   r   r   r/   r   r   r0   H   r1   )r!   r"   lenassertRaises
IndexErrorr   r   r/   r   test_empty_sequence;   s    z!BaseBytesTest.test_empty_sequencec                 C   s  |  td}| t|d | t|ttd |  dh}| |d |  ddh}| t|ddh |  ttd}| t|d | t|ttd |  dd	 tdD }| t|d
 | t|ttddd d  G dd d}|  | }| |d d S )N   *      *+   -   )rE   rF   )rF   rE   c                 s   s   | ]}|d  r|V  qdS )r=   Nr   .0ir   r   r   	<genexpr>[   r1   z3BaseBytesTest.test_from_iterable.<locals>.<genexpr>   r3   r=   c                   @   s   e Zd Zdd ZdS )z+BaseBytesTest.test_from_iterable.<locals>.Sc                 S   s   d| S )Nr3   r=      r   )r   rI   r   r   r   __getitem__a   s    z7BaseBytesTest.test_from_iterable.<locals>.S.__getitem__N)r   r   r   rN   r   r   r   r   S`   s   rO      )r!   ranger"   r>   listassertIntupleiter)r   r&   rO   r   r   r   test_from_iterableJ   s     "z BaseBytesTest.test_from_iterablec                 C   sT   |  ttd}| t|d | t|ttd |  d}| |d d S NrB   rL   rP   )r!   rT   rQ   r"   r>   rR   r%   r   r   r   test_from_tuplef   s
    
zBaseBytesTest.test_from_tuplec                 C   sX   |  ttd}| t|d | t|ttd |  g d}| |d d S rW   )r!   rR   rQ   r"   r>   r%   r   r   r   test_from_listn   s
    zBaseBytesTest.test_from_listc                    s\   G  fddd}| | g |  t d G  fddd}| g |  t d d S )Nc                       s   e Zd Z fddZdS )z0BaseBytesTest.test_from_mutating_list.<locals>.Xc                    s       dS NrC   )clearr   r-   r   r   r   y   s    z:BaseBytesTest.test_from_mutating_list.<locals>.X.__index__Nr   r   r   r   r   r\   r   r   Xx   s   r^   rD   c                       s   e Zd Z fddZdS )z0BaseBytesTest.test_from_mutating_list.<locals>.Yc                    s   t  dk r |  dS )N  rC   )r>   appendr   r\   r   r   r      s    
z:BaseBytesTest.test_from_mutating_list.<locals>.Y.__index__Nr]   r   r\   r   r   Y   s   ra   s  ****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************r"   bytes)r   r^   ra   r   r\   r   test_from_mutating_listv   s    z%BaseBytesTest.test_from_mutating_listc                 C   sd   |  t tdtdtdg}| t|g d | t| j tdg | t| j tdg d S )Nr3         r   r3   re   rf   r;   rB   )r!   r   r"   rR   r?   
ValueErrorr%   r   r   r   test_from_index   s    zBaseBytesTest.test_from_indexc                 C   sb   |  tdg d}| |d |  d}| |d G dd dt}| |  |dd d S )NBrL   rP   c                   @   s   e Zd Zdd ZdS )z)BaseBytesTest.test_from_buffer.<locals>.Bc                 S   s   t d S r   )	TypeErrorr   r   r   r   r      s    z3BaseBytesTest.test_from_buffer.<locals>.B.__index__Nr]   r   r   r   r   rj      s   s   foobar)r!   arrayr"   rc   )r   r-   rj   r   r   r   test_from_buffer   s    
zBaseBytesTest.test_from_bufferc                 C   s   |  | dd |  | dd |  | dd | t| jd |  | dd	d
 |  | d
d
 | t| jtjd  d S )Nr   r1   r3          s        r;   0ascii   0)r"   r!   r?   rh   OverflowErrorr5   r6   r   r   r   r   test_from_ssize   s    zBaseBytesTest.test_from_ssizec                 C   s&  |  t| jd G dd d}|  t| jdg |  t| jdg |  t| jd g |  t| j| g | j t| jdd | j t| jdd |  t| jd	d |  t| jd
d | j t| jd	dd | j t| jd
dd |  t| jd | j t| jddd |  t| jdd |  t| jddd d S )Ng        c                   @   s   e Zd ZdS )z5BaseBytesTest.test_constructor_type_errors.<locals>.CNr   r   r   r   r   r   r   C   s   rv   rp   rq   )encodingignore)errorsr   r1   r   s   asciis   ignore)r?   rk   r!   )r   rv   r   r   r   test_constructor_type_errors   s     z*BaseBytesTest.test_constructor_type_errorsc                 C   s   |  t| jdg |  t| jtj g |  t| jtj d g |  t| jtj d g |  t| jdd  g |  t| jdg |  t| jdg |  t| jtjg |  t| jtjd g |  t| jdd g d S )Nr;   r3   r=   r8   r9   rB   i  )r?   rh   r!   r5   r6   r   r   r   r   test_constructor_value_errors   s    z+BaseBytesTest.test_constructor_value_errorsc              	   C   sD   t }| ttf| j| zt|d  W n ttfy>   Y n0 d S )N   )r   r?   rs   MemoryErrorr!   	bytearray)r   sizer   r   r   test_constructor_overflow   s    z'BaseBytesTest.test_constructor_overflowc                 C   sX   G dd d}|  t| j|  |  t| j| g G dd d}|  t| j|  d S )Nc                   @   s   e Zd Zdd ZdS )z9BaseBytesTest.test_constructor_exceptions.<locals>.BadIntc                 S   s   dd  d S Nr3   r   r   r   r   r   r   r      s    zCBaseBytesTest.test_constructor_exceptions.<locals>.BadInt.__index__Nr]   r   r   r   r   BadInt   s   r   c                   @   s   e Zd Zdd ZdS )z>BaseBytesTest.test_constructor_exceptions.<locals>.BadIterablec                 S   s   dd  d S r   r   r   r   r   r   __iter__   s    zGBaseBytesTest.test_constructor_exceptions.<locals>.BadIterable.__iter__N)r   r   r   r   r   r   r   r   BadIterable   s   r   )r?   ZeroDivisionErrorr!   )r   r   r   r   r   r   test_constructor_exceptions   s
    z)BaseBytesTest.test_constructor_exceptionsc                 C   s  |  g d}|  g d}|  ddg}| || | ||k | ||k | ||k | ||k  | ||k | ||k | ||k | ||k | ||k | ||k | ||k | ||k | ||k  | ||k  | ||k d S )NrL   r3   rM   )r!   r"   
assertTrueassertFalse)r   b1b2b3r   r   r   test_compare   s&    zBaseBytesTest.test_comparec                 C   s   |  | ddkd |  | ddkd |  | ddkd |  | ddkd |  |  t kd |  |  t kd d S )Ns    a b cabcFs      a   b   cs   a b c s   a   b   c   T)r"   r!   strr   r   r   r   test_compare_to_str   s    z!BaseBytesTest.test_compare_to_strc                 C   s<   t ttd}| |}t t|}|  | || d S )NHello)rR   mapordr!   reversedreverser"   )r   inputr&   outputr   r   r   test_reversed  s
    
zBaseBytesTest.test_reversedc                    sP   fdd}|d}  |d d |d   |dd |d   |dd |d	   |dd  |d
   |dd |d
   |dd |d
   |d d |d   |dd |d   |dd |d	   |dd  |d
   |dd |d
   |dd |d
   |dd |d d S )Nc                    s     tt| S r   )r!   r   r   sr   r   r   by  s    z'BaseBytesTest.test_getslice.<locals>.byHello, worldro   r   r3   Zello   z, world   r9   i)r"   r   r   r&   r   r   r   test_getslice
  s    zBaseBytesTest.test_getslicec                 C   s   t td}| |}dd ddddtjddd	d
f}|D ]F}|D ]<}|dd  D ]*}| |||| | ||||  qNq>q6d S )Nrf   r   r3   rM      r9   r;   r<   r   )rR   rQ   r!   r5   r6   r"   )r   Lr&   indicesstartstopstepr   r   r   test_extended_getslice  s    
z$BaseBytesTest.test_extended_getslicec              	   C   sr   d}dD ](}|  ||}| ||  || q| t| j |d |  |dd}| ||  |d d d d S )N   Hello world
ሴ噸骼utf-8zutf-16latin-1rx   r   )r!   r"   encoder?   UnicodeEncodeErrorr   sampleencr&   r   r   r   test_encoding)  s    zBaseBytesTest.test_encodingc                 C   s   d}dD ]"}|  ||}| ||| qd}|  |d}| t|jd | |ddd | |jdddd | |  d	 d
 d S )Nr   r   u   Hello world
þÿr   r   rx   zHello world
)ry   rw   s   ☃u   ☃)r!   r"   decoder?   UnicodeDecodeErrorr   r   r   r   test_decode2  s    zBaseBytesTest.test_decodec                 C   sd   d}d}t d| jj d|d|d|d|d|d	|d
}tddd|}| |jd| d S )NzBoom, Shaka Laka, Boom!)rq   utf8latin1z0
            import sys
            type2test = z
            encodings = zr

            for data in ('', 'short string'):
                try:
                    type2test(data, encoding=z)
                except LookupError:
                    pass
                else:
                    sys.exit(21)

                for encoding in encodings:
                    try:
                        type2test(data, encoding=encoding, errors=a>  )
                    except LookupError:
                        pass
                    else:
                        sys.exit(22)

            for data in (b'', b'short string'):
                data = type2test(data)
                print(repr(data))
                try:
                    data.decode(encoding=z)
                except LookupError:
                    sys.exit(10)
                else:
                    sys.exit(23)

                try:
                    data.decode(errors=z)
                except LookupError:
                    pass
                else:
                    sys.exit(24)

                for encoding in encodings:
                    try:
                        data.decode(encoding=encoding, errors=z)
                    except LookupError:
                        pass
                    else:
                        sys.exit(25)

            sys.exit(10)
        z-Xdevz-cr8   )textwrapdedentr!   r   r   r"   rc)r   invalid	encodingscodeprocr   r   r   test_check_encoding_errors@  s&     (
0z(BaseBytesTest.test_check_encoding_errorsc                 C   sb   |  d}| ||    |  d}| ||  dgd  |  d}| ||  dgd  d S )Nr   r8   i'  )r!   r"   r%   r   r   r   test_from_intx  s    


zBaseBytesTest.test_from_intc                    sx   |  d |  d|   d |  td d | td  d | t fdd | tfdd d S )N   abc   def   abcdefs   defabcc                      s    d S )Ndefr   r   )r   r   r   r0     r1   z+BaseBytesTest.test_concat.<locals>.<lambda>c                      s   d  S )Nr   r   r   )r   r   r   r0     r1   )r!   r"   rc   r?   rk   r   r   )r   r   r   test_concat  s    

zBaseBytesTest.test_concatc              	      s   d|  dfD ]̉ |  d d |  d d |  d d | t fdd | t fd	d | ttf  tj }W d    n1 s0    Y  | ttf  tj9  W d    q1 s0    Y  qd S )
Nr   rM   	   abcabcabcr   r1   r;   c                      s    d S NgQ	@r   r   r/   r   r   r0     r1   z+BaseBytesTest.test_repeat.<locals>.<lambda>c                      s   d  S r   r   r   r/   r   r   r0     r1   )r!   r"   r?   rk   rs   r}   r5   r6   r   cr   r/   r   test_repeat  s    (zBaseBytesTest.test_repeatc                 C   s*   |  | dd | tdgd  d S )N   xr9   x)r"   r!   r   r   r   r   r   test_repeat_1char  s    zBaseBytesTest.test_repeat_1charc                    st  |  d | td  | ttd  | d  | t fdd | t fdd | t fdd | t fdd | t fd	d | t fd
d tt	fD ]}| |d  | |d  | |d  | |d  | |d  | |d  | |d  | |d  | |d  | |d  | |d  qd S )Nr   r-      c                      s   d v S )N,  r   r   r/   r   r   r0     r1   z-BaseBytesTest.test_contains.<locals>.<lambda>c                      s   d v S r:   r   r   r/   r   r   r0     r1   c                      s   t jd  v S r2   r4   r   r/   r   r   r0     r1   c                      s   d  v S r   r   r   r/   r   r   r0     r1   c                      s   t td v S Nr-   )floatr   r   r/   r   r   r0     r1   c                      s   d v S r   r   r   r/   r   r   r0     r1   r1      a   b   c   ab   bc   ac   ds   dabs   abd)
r!   rS   r   intZassertNotInr?   rh   rk   rc   r~   r   fr   r/   r   test_contains  s,    
zBaseBytesTest.test_containsc              	   C   s  |  t| jj |  t| jjd | | jd|   tg d}| | jd| | | jd| | | jd| dD ]}| | j||   qdD ]}|  t| jj| q| | jd	d
 |  t| jjd |  t| jjd |  t| jjd |  t| jjd |  t| jjd |  t| jjd dD ]X\}}|  t}| j| W d    n1 sz0    Y  | d| t|j	 qDd S )Nr3   r      rE   0   1a2B30z  1A 2B  30   z
 1A
2B	30z	
 u       Z0000s     s   1Br-   Zrtz1a b cd z12       34))z12 x4 56rM   )z12 3x 56r|   )z12 xy 56rM   )u	   12 3ÿ 56r|   zat position %s)
r?   rk   r!   fromhexr"   r~   rh   rS   r   	exception)r   r&   r   dataposcmr   r   r   test_fromhex  s,    
,zBaseBytesTest.test_fromhexc                 C   s~   |  t| jj |  t| jjd | | d d | tg d d | | d d | td d d S )Nr3   r1   r   r   Z1a2b30   +0)r?   rk   r!   hexr"   r~   
memoryviewr   r   r   r   test_hex  s    zBaseBytesTest.test_hexc                 C   s  |  d}| | d | t |d W d    n1 sD0    Y  | t |d W d    n1 sx0    Y  | |ddd | t |d d W d    n1 s0    Y  | t |d W d    n1 s0    Y  | t |d W d    n1 s,0    Y  | t |d	 W d    n1 sb0    Y  | t |td
 W d    n1 s0    Y  | |ddd | |dd | |dd | |dd | |dd | |ddd | |ddd | |ddd | |dd | |dd | |ddd | |ddd | |ddd | |ddd | |ddd d}| |dd d! d S )"Ns   Zb901efr   xx:r      ÿ      rB   rn   zb9 01 efr      zb901efrM   r|   zb9:01:ef   $zb9$01$efr3   r;   r=   zb9:01ef*r<   zb901*efs    {s   worldi   s   helloi   0.   zC7b7305000000776f.726c646902000000.730500000068656c.6c6f690100000030)r!   r"   r   r?   rh   rk   chr)r   Zthree_bytesr   r   r   r   test_hex_separator_basics  sD    
((*(**.z'BaseBytesTest.test_hex_separator_basicsc                 C   s$   |  tdd}| | d d S )NZ   _   Z
5a5b5c5d5er!   rQ   r"   r   )r   Z
five_bytesr   r   r   test_hex_separator_five_bytes  s    z+BaseBytesTest.test_hex_separator_five_bytesc                 C   s  |  dd tddD }| | d | |ddd | |dd	d
 | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd | |ddd d S )Nc                 s   s   | ]}|d  V  qdS )rM   Nr   rH   r   r   r   r   rJ     r1   z=BaseBytesTest.test_hex_separator_six_bytes.<locals>.<genexpr>r3   r   Z0306090c0f12r   z03.06.09.0c.0f.12 r=   z0306 090c 0f12-rM   z030609-0c0f12r   r|   z0306:090c0f12ro   z03:06090c0f12   r   _r   Z030609_0c0f12r   z0306090c:0f12   @r   z0306090c0f@12iir  )r   Z	six_bytesr   r   r   test_hex_separator_six_bytes  s    z*BaseBytesTest.test_hex_separator_six_bytesc                 C   s  |  | dg d |  | ddgd dgddgddgg dfD ]d}tt| j|}|  | d|d |  | dt|d |  | dt|d qL| dj}|  |dd	gd
 |  |tdd	gd
 |  |dtd	gd
 |  |tdd	gd
 |  |dtd	gd
 dgd }ddd  }|  ||| dgd }dd }|  | d|| | 	t
| djd  | 	t
" |tdddg W d    n1 s0    Y  | 	t
" |tdddg W d    n1 s
0    Y  d S )Nr1   r   r   r   r   r   )r   r   r   s   .:s   cds   ab.:cdi s   .:abci     Zcds   ef)r"   r!   joinrR   r   rT   rU   r   r~   r?   rk   )r   ZlstZdot_joinseqZexpectedr   r   r   	test_join  s0    

2zBaseBytesTest.test_joinc                 C   s  |  d}d}d}d}| |dd | |dd | |d	d
 | ||d | ||d
 | |ddd | |ddd | |dddd | |dddd | ||dd | ||dd | ||ddd | ||ddd d S )N   mississippii   p   w      ir|      ssr=      wr   r     pr3   rM   r   	   )r!   r"   count)r   r&   rI   pwr   r   r   
test_count5  s"    
zBaseBytesTest.test_countc                 C   s   |  d}| |   d | |d | |d | |d | |d | |d | t}|dg W d    n1 s0    Y  t|j}| d| | d| d S )	N   hello   anythings   hel   hs   hellows   harc   rT   )	r!   r   
startswithr   r?   rk   r   r   rS   r   r&   r   excr   r   r   test_startswithL  s    
*
zBaseBytesTest.test_startswithc                 C   s   |  d}| t d | |d | |d | |d | |d | |d | t}|dg W d    n1 s0    Y  t|j}| 	d| | 	d| d S )	Nr  r  s   llo   os   whellos   norc   rT   )
r!   r   r~   endswithr   r?   rk   r   r   rS   r  r   r   r   test_endswithZ  s    
*
zBaseBytesTest.test_endswithc                 C   s  |  d}d}d}| |dd | |dd | |dd | ||d	 | ||d | |dd
d | |dd	dd | |dd	d
d | ||dd | ||d	d
d	 | ||d	d
d ddtjd	 fD ]}| td|j| qd S )Nr  r  r  r  r=   r  r;      mississippianr3   rM   ro   r   r  rB   zbyte must be in range\(0, 256\))r!   r"   findr5   r6   assertRaisesRegexrh   )r   r&   rI   r  indexr   r   r   	test_findh  s&    
zBaseBytesTest.test_findc                 C   s   |  d}d}d}| |dd | |dd | |dd | ||d	 | ||d | |dd
d | |dddd | ||dd
d | ||d
dd | ||dd
d d S )Nr  r  r  r  ro   r  r;   r%  r8   rM   r   r  r=   r3   r  r   )r!   r"   rfindr   r&   rI   r  r   r   r   
test_rfind  s    
zBaseBytesTest.test_rfindc                 C   s   |  d}d}d}| |dd | t|jd | t|jd | ||d | t|j| | |dd	d
 | |dddd | t|jddd	 | ||dd | ||dd	d | t|j|dd	 d S )Nr  r  r  r  r=   r  r%  r3   rM   ro   r   r  )r!   r"   r(  r?   rh   r+  r   r   r   
test_index  s    
zBaseBytesTest.test_indexc                 C   s   |  d}d}d}| |dd | t|jd | t|jd | ||d | t|j| | |dd	d | |dd
dd | ||dd	d | ||d	dd | t|j|dd	 d S )Nr  r  r  r  ro   r  r%  r8   rM   r   r  r=   r3   r  r   )r!   r"   rindexr?   rh   r+  r   r   r   test_rindex  s    
zBaseBytesTest.test_rindexc                 C   s   |  d}|}|d }| |d | |d | ||u  |  d}|d }| |d | t|| j  |  d}|d }| |d | t|| j  d S 	Ns
   hello, %b!   worlds   hello, world!s   %s / 100 = %d%%)s   seventy-nineO   s   seventy-nine / 100 = 79%s
   hello, %b!s   hello, world!r!   r"   r   assertIsr#   )r   r&   origr-   r   r   r   test_mod  s    


zBaseBytesTest.test_modc                 C   s   |  d}|}|d; }| |d | |d | ||u  |  d}|d; }| |d | t|| j  |  d}|d; }| |d | t|| j  d S r0  r3  )r   r&   r5  r   r   r   	test_imod  s    


zBaseBytesTest.test_imodc                 C   sV   |  t  t | d  W d    n1 s00    Y  | | ddt d S )Nr   z%r)r?   rk   objectr!   r4  __rmod__NotImplementedr   r   r   r   	test_rmod  s    .zBaseBytesTest.test_rmodc                 C   s6   |  d}| |ddd | |ddd d S )Nr  r  r   s   massassappar  r   s	   mixixippi)r!   r"   replacer%   r   r   r   test_replace  s    
zBaseBytesTest.test_replacec                 C   s   |  t| djdd d S )N   a b    r1   )r?   rk   r!   r<  r   r   r   r   test_replace_int_error  s    z$BaseBytesTest.test_replace_int_errorc                 C   s0   |  t| djd |  t| djd d S Nr>  r  r?   rk   r!   splitrsplitr   r   r   r   test_split_string_error  s    z%BaseBytesTest.test_split_string_errorc                 C   s0   |  t| djd |  t| djd d S Nr>  r?  rB  r   r   r   r   test_split_int_error  s    z"BaseBytesTest.test_split_int_errorc                 C   sF   dD ] }|  |}| | |g q|  d}| | dg d S )N)s   abs   abs   abs   ab	   	
   )r!   r"   rC  r%   r   r   r   test_split_unicodewhitespace  s
    

z*BaseBytesTest.test_split_unicodewhitespacec                 C   s    |  d}| | dg d S )NrH  rI  )r!   r"   rD  r%   r   r   r   test_rsplit_unicodewhitespace  s    
z+BaseBytesTest.test_rsplit_unicodewhitespacec                 C   s2   |  d}| |dd | |dd d S )Nr  r  )s   mir  s   issippir  )r  r1   r1   )r!   r"   	partitionr%   r   r   r   test_partition  s    
zBaseBytesTest.test_partitionc                 C   sD   |  d}| |dd | |dd | |dd d S )Nr  r  )s   missir  s   ippir  )s
   mississippr  r1   r  )r1   r1   r  )r!   r"   
rpartitionr%   r   r   r   test_rpartition  s    
zBaseBytesTest.test_rpartitionc                 C   s0   |  t| djd |  t| djd d S rA  r?   rk   r!   rL  rN  r   r   r   r   test_partition_string_error  s    z)BaseBytesTest.test_partition_string_errorc                 C   s0   |  t| djd |  t| djd d S rF  rP  r   r   r   r   test_partition_int_error  s    z&BaseBytesTest.test_partition_int_errorc                 C   sN   t tjd D ]:}dD ]0}| |}t||}t|}| || qqd S Nr3   )r1   r   r   s   abs       )rQ   pickleHIGHEST_PROTOCOLr!   dumpsloadsr"   )r   protor&   Zpsqr   r   r   test_pickling  s    

zBaseBytesTest.test_picklingc                 C   s   t tjd D ]}dD ]}t| | }}t| |}t||}t|}| t	|t	| | t|| t|}|sqt
| t||}t|}| t||dd   qqd S rS  )rQ   rT  rU  rU   r!   rR   rV  rW  r"   r#   next)r   rX  r&   itZitorgr   dr   r   r   test_iterator_pickling  s    


z$BaseBytesTest.test_iterator_picklingc                 C   sX   |  | dtdd |  | dtdd |  | dtdd d S )Nr   r   r   r   r   )r"   r!   stripr   lstriprstripr   r   r   r   test_strip_bytearray*  s    z"BaseBytesTest.test_strip_bytearrayc                 C   sF   |  t| djd |  t| djd |  t| djd d S )Nr   Zacr?   rk   r!   r_  r`  ra  r   r   r   r   test_strip_string_error/  s    z%BaseBytesTest.test_strip_string_errorc                 C   sF   |  t| djd |  t| djd |  t| djd d S )Ns    abc r?  rc  r   r   r   r   test_strip_int_error4  s    z"BaseBytesTest.test_strip_int_errorc                 C   s:   |  d}ttfD ]"}| |d|d|  d qd S )Nr   r      -s   --abc--)r!   rc   r~   r"   centerr   r&   Z	fill_typer   r   r   test_center9  s
    
zBaseBytesTest.test_centerc                 C   s:   |  d}ttfD ]"}| |d|d|  d qd S )Nr   r   rf  s   abc----)r!   rc   r~   r"   ljustrh  r   r   r   
test_ljust@  s
    
zBaseBytesTest.test_ljustc                 C   s:   |  d}ttfD ]"}| |d|d|  d qd S )Nr   r   rf  s   ----abc)r!   rc   r~   r"   rjustrh  r   r   r   
test_rjustG  s
    
zBaseBytesTest.test_rjustc                 C   sL   |  t| djdd |  t| djdd |  t| djdd d S )Nr   r   r?  )r?   rk   r!   rg  rj  rl  r   r   r   r   test_xjust_int_errorN  s    z"BaseBytesTest.test_xjust_int_errorc                    s4   |  d |  fddtt D g d d S )Ns    Ac                    s    g | ]}t  ||d   qS )r3   )r   rG   r/   r   r   
<listcomp>U  r1   z*BaseBytesTest.test_ord.<locals>.<listcomp>)r   A      rK   rf   )r!   r"   rQ   r>   r   r   r/   r   test_ordS  s    
zBaseBytesTest.test_ordc                 C   s`   d}|  | jdd| d}|  | jdd| | t| jjdd | t| jjdd d S )	Ns    	
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`xyzdefghijklmnopqrstuvwxyz{|}~r      xyzs    	
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~xyzs   s   xyzqr   r   )r"   r!   	maketransr?   rh   rk   )r   Z
transtabler   r   r   test_maketransX  s    zBaseBytesTest.test_maketransc                 C   s  |  d}|  d}|  d}|  d}|  d}| d||d  | d||dd  | d||d d | d	||d d  | d||d  | d||dd  | d||d d | d	||d d  | d||d  | d||dd  | d||d d | d	||d d  | d||d  | d||dd  | d||d d | d	||d d  | d||d  | d
||dd  | d
||d d | d	||d d  | d||d  | d||dd  | d||d d | d||d d  | d||d  | d||dd  | d||d d | d||d d  d S )Nr     lr  r   r"  r=   rM   r<   r   r3   TF)	r!   r"   r&  r*  r(  r.  r  r#  r  )r   r&   lhr   or   r   r   test_none_arguments`  sB    




z!BaseBytesTest.test_none_argumentsc                 C   sV   |  d}|j|j|j|j|jfD ].}| t|d | t|d | t|d q"d S )Nr  r;   rB   i'  )r!   r  r&  r(  r*  r.  r?   rh   )r   r&   methodr   r   r   (test_integer_arguments_out_of_byte_range  s
    
z6BaseBytesTest.test_integer_arguments_out_of_byte_rangec              	   C   s   |  d}|  d}| td|j|d d d  | td|j|d d d  | td|j|d d d  | td|j|d d d  | td|j|d d d  | td|j|d d d  | td	|j	|d d d  d S )
Nr  r   z\bfind\bz	\brfind\bz	\bindex\bz
\brindex\bz	\bcount\bz\bstartswith\bz\bendswith\b)
r!   r'  rk   r&  r*  r(  r.  r  r  r#  )r   r&   r   r   r   r   *test_find_etc_raise_correct_error_messages  s.    

z8BaseBytesTest.test_find_etc_raise_correct_error_messagesc                 C   s(   t j| t| j t j| t| j d S r   )r   r	   Zcheck_free_after_iteratingrU   r!   r   r   r   r   r   test_free_after_iterating  s    z'BaseBytesTest.test_free_after_iteratingc                 C   s4  |  d}ttd}td|td< | t|j | t|jd d  | t|jttd ||d}| 	|d | 
|| j  ||}||d}| 	|| | 	|d ||d}| 	|d	 |d d
}| 	|d |j|dd}| 	|d |j|dd}| 	|d	 |jd d
d}| 	|d d S )Nr  rB   ery  rf   r1   s   hellerv  s   hee   es   hllo)delete)r!   r~   rQ   r   r?   rk   	translaterh   rc   r"   assertIsInstance)r   r&   Zrosettar   r]  r   r   r   test_translate  s.    

zBaseBytesTest.test_translatec                 C   s   t jd}| d}| t ||d W d    n1 sB0    Y  | t ||d W d    n1 sx0    Y  | ||dd d S )N	_testcapi)rC   r<   r3   r   rC   )r   r	   import_moduler!   r?   r@   Zsequence_getitemr"   )r   r  objr   r   r   test_sq_item  s    
**zBaseBytesTest.test_sq_itemN)Kr   r   r   r'   r.   rA   rV   rX   rY   rd   ri   rm   rt   rz   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r  r  r!  r$  r)  r,  r-  r/  r6  r7  r;  r=  r@  rE  rG  rJ  rK  rM  rO  rQ  rR  rZ  r^  rb  rd  re  ri  rk  rm  rn  rr  ru  rz  r|  r}  r~  r  r  r   r   r   r   r    -   s   



	8	%%+r    c                   @   s8   e Zd ZeZdd Zdd Zdd Zdd Zd	d
 Z	dS )	BytesTestc                 C   s@   d}d}|  t| |d  W d    n1 s20    Y  d S )N   pythonz'byte indices must be integers or slicesr-   )r'  rk   r   r&   msgr   r   r   test_getitem_error  s    zBytesTest.test_getitem_errorc                 C   sP   t tt j}t|ddd }| t|jd W d    n1 sB0    Y  d S )Nrbr   )	bufferingr1   )osopen__file__O_RDONLYr?   rk   readinto)r   fdr   r   r   r   test_buffer_is_readonly  s    z!BytesTest.test_buffer_is_readonlyc                 C   s  G dd d}|  t| d G dd d}| tt|  G dd d}| tt|  G dd d}|  t| d G dd dt}|  t|d	d |  t|d	d
d G dd d}|  t| d | tt| t |  t| d | tt| t d S )Nc                   @   s   e Zd Zdd ZdS ) BytesTest.test_custom.<locals>.Ac                 S   s   dS Nr   r   r   r   r   r   	__bytes__  s    *BytesTest.test_custom.<locals>.A.__bytes__Nr   r   r   r  r   r   r   r   A  s   r  r   c                   @   s   e Zd ZdS )r  Nru   r   r   r   r   r    r1   c                   @   s   e Zd Zdd ZdS )r  c                 S   s   d S r   r   r   r   r   r   r    s    r  Nr  r   r   r   r   r    s   c                   @   s   e Zd Zdd Zdd ZdS )r  c                 S   s   dS )Nr   r   r   r   r   r   r    s    r  c                 S   s   dS rZ   r   r   r   r   r   r     s    z*BytesTest.test_custom.<locals>.A.__index__N)r   r   r   r  r   r   r   r   r   r    s   r   c                   @   s   e Zd Zdd ZdS )r  c                 S   s   dS r  r   r   r   r   r   r    s    r  Nr  r   r   r   r   r    s   u   €z
iso8859-15   c                   @   s   e Zd Zdd ZdS )r  c                 S   s   t dS r  )OtherBytesSubclassr   r   r   r   r    s    r  Nr  r   r   r   r   r    s   )	r"   rc   r?   rk   r   r4  r#   r  BytesSubclass)r   r  r   r   r   test_custom  s     zBytesTest.test_customc                    sx  t jd}t jd}ddlm}m} ddlm}m}m}m	}m
}	m}
m} |j}|f|_||_| |dd | |ddd	 | |d
|dd | |d
|tdd | |d
|dd | |d|d|d|	dd | |d|d|d|	dd | |d|d|d|	dd | |d|dd | |d|d d! | |d"|d#d$ ||}tjd%krd&d|   fd'd(}nd)d( }d*}| |d+||d,|| d- | |d.|d/d0 |	dj}d1||jtfd1||jtfd2||jtfd2||jtfd3||jtfd4|
|jtfd4|
|jtfd5|	|tfd6|||ff	D ]0\}}}}| ||||||d-f q^| |d7d8d8 | |d9d:d; | |d<d= | |d>d? | |d@|tdAdB | |dCdD | |d=d= | |dE|d|ddF |  t!|dG|d |  t!|dG|dH | |dIdI | |dDdIdI d S )JNctypesr  r   )	pythonapi	py_object)c_intc_uintc_longc_ulongc_size_t	c_ssize_tc_char_ps   formats
   Hello %s !r1  s   Hello world !s   c=%cs   c= @s   c=@rf   s   c=s   d=%d ld=%ld zd=%zdr3   r=   rM   s   d=1 ld=2 zd=3r;   r<   r   s   d=-1 ld=-2 zd=-3s   u=%u lu=%lu zu=%zu{   i  i  s   u=123 lu=456 zu=789s   i=%is   i=123is   i=-123s   x=%xi
  s   x=abcntz0x%0{}Xc                    s    |  S r   r   ptrZ
ptr_formatr   r   ptr_formatter5  s    z1BytesTest.test_from_format.<locals>.ptr_formatterc                 S   s   d|  S )Nz%#xr   r  r   r   r   r  9  s    iͫ s   ptr=%pzptr=rq   s   s=%ss   cstrs   s=cstrs   %ds   %lds   %lus   %zds   %zus   %ps   %5sr   s   %.3sr   r   s   %%   %s   [%%]s   [%]s   %%%cr  s   %_s   %%ss   %ss   x=%i y=%s   x=2 y=%s   %crB   r1   )"r   r	   r  r  r  r  r  r  r  r  r  r  r  PyBytes_FromFormatargtypesZrestyper"   r   Zsizeofr  nameformatr   r   ZINT_MINr   ZINT_MAXZLONG_MINZLONG_MAXZ	ULONG_MAXZPY_SSIZE_T_MINZPY_SSIZE_T_MAXr?   rs   )r   r  r  r  r  r  r  r  r  r  r  r  r  Z
sizeof_ptrr  r  Zsize_maxZ	formatstrZctypes_typer   Zpy_formatterr   r  r   test_from_format  s    $











zBytesTest.test_from_formatc                 C   s   G dd dt }g d}| t|d | tt|| G dd dt}| tdd | tt|d G d	d
 d
t}| tdd | tt|d G dd dt}td|d }}| t|d | tt| d S )Nc                   @   s   e Zd ZdZdS )z7BytesTest.test_bytes_blocking.<locals>.IterationBlockedNr  r   r   r   r   IterationBlockedu  s   r  )r   r3   r=   rM   s    c                   @   s   e Zd ZdZdS )z1BytesTest.test_bytes_blocking.<locals>.IntBlockedNr  r   r   r   r   
IntBlocked~  s   r  rM   s      c                   @   s   e Zd ZdZdS )z;BytesTest.test_bytes_blocking.<locals>.BytesSubclassBlockedNr  r   r   r   r   BytesSubclassBlocked  s   r  r   c                   @   s   e Zd ZdZdS )z4BytesTest.test_bytes_blocking.<locals>.BufferBlockedNr  r   r   r   r   BufferBlocked  s   r  )rR   r"   rc   r?   rk   r   r~   )r   r  rI   r  r  r  babbr   r   r   test_bytes_blockingt  s    zBytesTest.test_bytes_blockingN)
r   r   r   rc   r!   r  r  r  r  r  r   r   r   r   r    s   !rr  c                   @   s2  e Zd Ze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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d%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Z d9d: Z!d;d< Z"e#j$j%d=d> Z&d?d@ Z'e#j(j)j*Z*dAdB Z+dCdD Z,dES )FByteArrayTestc                 C   sD   t d}d}| t| |d  W d    n1 s60    Y  d S )Nr  ,bytearray indices must be integers or slicesr-   r~   r'  rk   r  r   r   r   r    s    z ByteArrayTest.test_getitem_errorc                 C   sD   t d}d}| t| d|d< W d    n1 s60    Y  d S )Nr  r  Zpythonr-   r  r  r   r   r   test_setitem_error  s    z ByteArrayTest.test_setitem_errorc                 C   s   |  ttt  d S r   )r?   rk   hashr~   r   r   r   r   test_nohash  s    zByteArrayTest.test_nohashc                 C   sz  d}|ddt |   }t }z,t|d}|| W d    n1 sN0    Y  t|d"}td}||}W d    n1 s0    Y  | |t | | t|t| t|d}|| W d    n1 s0    Y  t|d }| |	 | W d    n1 s0    Y  W zt
| W n tyL   Y n0 n&zt
| W n tyr   Y n0 0 d S )Ns   Hello world
rn      wbr  )r>   tempfilemktempr  writer~   r  r"   rR   readr  removeOSError)r   Zshort_sampler   Ztfnr   r&   nr   r   r   test_bytearray_api  s.    (((2z ByteArrayTest.test_bytearray_apic                 C   s\   t d}| | d  | |d t d}|  | |d t  }|  | | d S )Nr  s   ollehs   hello1s   1olleh)r~   r"   r   r   r%   r   r   r   test_reverse  s    zByteArrayTest.test_reversec                 C   st   t d}|  | |d t d}|  | |d t d}|td |  |td | |d d S )Nr  r1   rr  r  )r~   r[   r"   r`   r   r%   r   r   r   
test_clear  s    zByteArrayTest.test_clearc                 C   s   t d}| }| |d t d}| }| |d t d}| }| || | || |td | |d | |d d S )Nr   r1   r]  r)   )r~   r*   r"   assertIsNotr`   r   )r   r&   r  r   r   r   r.     s    zByteArrayTest.test_copyc                 C   s4   dd }|d}|  td||d|dg d S )Nc                 S   s   t tt| S r   )r~   r   r   r   r   r   r   r     s    z&ByteArrayTest.test_regexps.<locals>.byr   s   \w+r   r   )r"   refindallr   r   r   r   test_regexps  s    zByteArrayTest.test_regexpsc                 C   sB  t g d}d|d< | |t g d d|d< | |t g d td|d	< | |t g d
 zd	|d< | d W n ty   Y n0 zd	|d< | d W n ty   Y n0 zd|d	< | d W n ty   Y n0 ztd|d	< | d W n ty   Y n0 zd |d	< | d W n ty<   Y n0 d S )NrL   r9   r3   )r3   r9   rM   r   r;   )r3   r9   r   r8   r   )r8   r9   r   rM   zDidn't raise IndexErrorirB   zDidn't raise ValueErrorzDidn't raise TypeError)r~   r"   r   failr@   rh   rk   r%   r   r   r   test_setitem  s@    zByteArrayTest.test_setitemc                 C   sb   t td}|d= | |t tdd |d= | |t tdd |d= | |t g d d S )Nr8   r   r3   r;   r  r|   )r3   r=   rM   r|   r  r   r   )r~   rQ   r"   r%   r   r   r   test_delitem  s    zByteArrayTest.test_delitemc              	   C   s  t td}| t|ttd t g d|dd< | |t g d |dd= | |t g d t g d|dd< | |t td t d	d
g|dd< | |t g d g d|dd< | |t td g d|dd< | |t g d d|dd < | |t g d td|d d< | |t g d g |dd< | |t g d dddtdddddgddgg gf	D ]>}| t ||dd< W d    n1 s0    Y  qg ddd gfD ]>}| t ||dd< W d    n1 s0    Y  qd S )!Nr8   )r3   r3   r3   r3   r3   r   ro   )
r3   r3   r3   r3   r3   ro   r  r   r   r  r   )ro   r  r   r   r  )r   r3   r=   rM   r|   r9   e   r   r   )r   r3   r=   r9   r  r   r   r  )rM   r|   ro   r  rM   )rC   rC   rC   )r   r3   r=   rC   rC   rC   rM   r|   ro   r  r   r   r  s   foo)r   r3   r=   f   o   r  )r  r  r  r  r  r  r|   )r  r  r  r  r  gPKDr   gffffff@r-   r&   r   r   )re   rf   rB   i i(#  )	r~   rQ   r"   rR   r   r   r?   rk   rh   )r   r&   elemr   r   r   test_setslice  s8    
0zByteArrayTest.test_setslicec                 C   sv   t td}| t|ttd |d d= | t|ttdd |tdd | t|ttdd d S )Nr9   r8   n   )r~   rQ   r"   rR   extendr%   r   r   r   test_setslice_extendD  s    
z"ByteArrayTest.test_setslice_extendc                 C   s,   t d}|  |d d= |td7 }~d S )Nr8   r3   r=   )r~   poprc   r%   r   r   r   test_fifo_overrunM  s
    
zByteArrayTest.test_fifo_overrunc                 C   s2   t d}t|}|d d= | t|| d S )Nr8   r3   )r~   r5   	getsizeofassertLessEqual)r   r&   r   r   r   r   test_del_expandV  s    

zByteArrayTest.test_del_expandc                 C   s   dd dddddd> t jddd	d
f}|D ]}|D ]}|dd  D ]}ttd}t|}|||| }|  |||||< |||||< | |t| ||||= ||||= | |t| q>q.q&d S )Nr   r3   rM   r   r   iM  r;   r<   r   irf   )r5   r6   rR   rQ   r~   r   r"   )r   r   r   r   r   r   r&   r   r   r   r   test_extended_set_del_slice]  s     z)ByteArrayTest.test_extended_set_del_slicec                 C   s@   t td}||dd < | |t ttdttd  d S )NrB   r   )r~   rQ   r"   rR   r%   r   r   r   test_setslice_trapr  s    z ByteArrayTest.test_setslice_trapc                 C   sz   t d}|}|d7 }| |d | || | || |d7 }| |d z|d7 }W n tyj   Y n0 | d d S )Nr   r   r   rs  s	   abcdefxyzr   z'bytes += unicode didn't raise TypeError)r~   r"   r4  rk   r  r   r&   r   r   r   r   test_iconcaty  s    zByteArrayTest.test_iconcatc                 C   s<   t d}|}|d9 }| |d | || | || d S )Nr   rM   r   r~   r"   r4  r  r   r   r   test_irepeat  s    zByteArrayTest.test_irepeatc                 C   s<   t d}|}|d9 }| |d | || | || d S )Nr   r9   sd   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr  r  r   r   r   test_irepeat_1char  s    z ByteArrayTest.test_irepeat_1charc                 C   sd   t  }| }| |d |g}tdD ]6}|d7 }| }| |t| ||vr(|| q(d S )Nr   r9   r   )r~   	__alloc__ZassertGreaterEqualrQ   assertGreaterr>   r`   )r   r&   allocr  rI   r   r   r   
test_alloc  s    zByteArrayTest.test_allocc                    sf   t    fdd} |  t ttdd t d   }|t  d S )Nc               	   3   s|   t ddD ]l} | V  t }|tt dt|d  t t| t |    }|t  q
d S )Nr3   r9   )rQ   rR   r"   r>   r  r  r  )rI   r-   r  r&   r   r   r   g  s    z(ByteArrayTest.test_init_alloc.<locals>.gr3   r9   c   )r~   r   r"   rR   rQ   r>   r  r  )r   r  r  r   r  r   test_init_alloc  s    	zByteArrayTest.test_init_allocc                 C   s  d}t |}|| | |||  | |dd  | t d}|tt|d  |dd |d D  | ||d  | |dd  | t d}|ttt|d  | ||d  | |dd  | t d}|ttt|d  | ||d  | |dd  | t d}| t|jg d	 | t|jg d
 | t	|d t d}|t
tdg | |d d S )Nr  ro   r1      c                 s   s   | ]}t |V  qd S r   )r   r  r   r   r   rJ     r1   z,ByteArrayTest.test_extend.<locals>.<genexpr>2   r   )r   r3   r=   rB   )r   r3   r=   r;   r   r-   r   )r~   r  r"   r   r   rU   rR   r?   rh   r>   r   r   )r   r5  r-   r   r   r   test_extend  s2    
zByteArrayTest.test_extendc                    s  t d  td |  d  td |  d | t fdd | t fdd | t fdd  td	  td
 |  d | t fdd  ttd |  d t g d}|d | |tg d |d | |tddg d S )Nr  rw  s   helos   heoc                      s     tdS )Nrw  )r  r   r   r/   r   r   r0     r1   z+ByteArrayTest.test_remove.<locals>.<lambda>c                      s
     dS )Ni  r  r   r/   r   r   r0     r1   c                      s
     dS )Nr  r  r   r/   r   r   r0     r1   ry  rx  r  c                      s
     dS )Nr  r  r   r/   r   r   r0     r1   r  r1   )~   rq  rK      rq  )r  rK   r  r  r  rK   )	r~   r  r   r"   r?   rh   rk   r   rc   r   r   r/   r   test_remove  s&    

zByteArrayTest.test_removec                    s   t d |   td |  dtd |  dtd | t fdd | td	d  | t d
 d d S )Nr1  r]  r   r  r<   r  c                      s
     dS )Nr8   )r  r   r/   r   r   r0     r1   z(ByteArrayTest.test_pop.<locals>.<lambda>c                   S   s
   t   S r   )r~   r  r   r   r   r   r0     r1   r   rf   )r~   r"   r  r   r?   r@   r   r   r/   r   test_pop  s    zByteArrayTest.test_popc                 C   s   |  tdd  d S )Nc                   S   s
   t   S r   )r~   sortr   r   r   r   r0     r1   z+ByteArrayTest.test_nosort.<locals>.<lambda>)r?   AttributeErrorr   r   r   r   test_nosort  s    zByteArrayTest.test_nosortc                    s   t d  td |  d |  dd  t    td | t d | t fdd t    ttd |  d	 d S )
Ns   hellry  r  r9   r  r3   c                      s
     dS )Nr"  )r`   r   r/   r   r   r0     r1   z+ByteArrayTest.test_append.<locals>.<lambda>   A)r~   r`   r   r"   r>   r?   rk   r   r   r   r/   r   test_append  s    zByteArrayTest.test_appendc                    s   t d  dtd  dtd  dtd  dtd |  d | t fdd	 t    d
ttd |  d d S )Ns   mssssppr3   rI   r|   r<   r_   r  c                      s     ddS )Nr      1)insertr   r/   r   r   r0     r1   z+ByteArrayTest.test_insert.<locals>.<lambda>r   r  r   )r~   r  r   r"   r?   rk   r   r   r   r/   r   test_insert  s    zByteArrayTest.test_insertc                 C   sR   t d}| ||ddd t dd tdD }t d}| ||| d S )Nr   s   cder   c                 S   s   g | ]}|qS r   r   rG   r   r   r   ro    r1   z-ByteArrayTest.test_copied.<locals>.<listcomp>rB   r1   )r~   r  r<  rQ   r  )r   r&   tr   r   r   r   test_copied  s
    zByteArrayTest.test_copiedc                 C   s   t dd\}}}| |d | |d | || |d7 }| |d t dd\}}}| |d | |d t dd\}}}| |d | |d | || |d7 }| |d t dd\}}}| |d | |d d S )Nr      yr1      !)r~   rL  r"   r  rN  )r   r-   r&   r   r   r   r   0test_partition_bytearray_doesnt_share_nullstring  s$    z>ByteArrayTest.test_partition_bytearray_doesnt_share_nullstringc                    s
  t td t } fdd}|d  d d  }| t|d |  | | t|d |  | | t|d |  | | t jd |  | | t j d  |  |  fdd	}| t| |  |  fd
d}| t| |  | d S )Nr8   c                    s"   t | d d|  d  dd< d S )Nr3   r=   r;   )rQ   )r  r/   r   r   resize6  s    z3ByteArrayTest.test_resize_forbidden.<locals>.resize   r  r   r3   c                      s
    d= d S r2   r   r   r/   r   r   delitemE  s    z4ByteArrayTest.test_resize_forbidden.<locals>.delitemc                      s   d ddd< d S )Nr1   r3   r;   r=   r   r   r/   r   r   delsliceJ  s    z5ByteArrayTest.test_resize_forbidden.<locals>.delslice)r~   rQ   r   r?   BufferErrorr"   r  r  )r   vr
  r5  r  r  r   r/   r   test_resize_forbidden/  s*    z#ByteArrayTest.test_resize_forbiddenc                 C   s    ddl m} | t|t  d S )Nr   )getbuffer_with_null_view)r  r  r?   r  r~   )r   r  r   r   r   test_obsolete_write_lockO  s    z&ByteArrayTest.test_obsolete_write_lockc           	      C   s  t d}td}ttjd D ]v}t|}t||f|}t|\}}||d d < | t	|t	| | t|| t
| t||f|}t|\}}||d d < | t	|t	| | t||dd   tdt|D ]}t
| qt||f|}t|\}}||d d < | t	|t	| | t||t|d   | tt
| t||f|}t|\}}||d d < | t|g  qd S )Nr   s   qwertyr3   )r~   rR   rQ   rT  rU  rU   rV  rW  r"   r#   r[  r>   r?   StopIteration)	r   r5  r   rX  Zitorigr]  r\  r&   rI   r   r   r   test_iterator_pickling2T  s6    
z%ByteArrayTest.test_iterator_pickling2c                 C   s4   t d}t|}t| |  | t|g  d S )Nr   )r~   rU   r[  r[   r"   rR   )r   r  r\  r   r   r   test_iterator_length_hintz  s
    z'ByteArrayTest.test_iterator_length_hintc                 C   sL   t d}d|d d< |d }|d }| |d | || | |d d S )Nr   r   r=   r3   rM   s   xcs   xcxcxcr~   r"   )r   r&   r   r   r   r   r   test_repeat_after_setslice  s    z(ByteArrayTest.test_repeat_after_setsliceN)-r   r   r   r~   r!   r  r  r  r  r  r  r.   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r   r	   Zcpython_onlyr  r  Z
list_testsZ
CommonTestZtest_exhausted_iteratorr  r  r   r   r   r   r    sJ   "	(		

 
$
	r  c                   @   s   e Zd Zedd Zedd Zdd Zejj	dd Z
d	d
 Zedd Zdd Zdd Zdd Zdd Zeejjddd ZdS )AssortedBytesTestc                 C   s   t tfD ]t}| |t d | |tdgd | |tg dd | |dd | |dd	 | |d
d qd S )Nbytearray(b'')r   zbytearray(b'\x00')rg   zbytearray(b'\x00\x01\xfe\xff')r   zb'abc'   'zb"'"s   '"zb'\'"')r   reprr"   r~   r   r   r   r   test_repr_str  s    zAssortedBytesTest.test_repr_strc              	   C   s   dt dfD ]t}| t|t| | t|dt| | tdtt|j	  t|d W d    q1 sv0    Y  qd S )Nr   r   z\b%s\br   )
r~   r"   r  r   r'  rk   r  escaper#   r   r%   r   r   r   test_format  s    zAssortedBytesTest.test_formatc                 C   s  |  dtdkd |  dtdkd |  dtdkd |  dtdk d |  dtdkd |  dtdkd |  dtdkd |  dtdkd |  dtdkd |  dtdkd |  dtdk d |  dtdkd |  tddkd |  tddkd |  tddkd |  tddk d |  tddkd |  tddkd |  tddkd |  tddkd |  tddkd |  tddkd |  tddk d |  tddkd d S )Nr   Tr   Frb   r   r   r   r   test_compare_bytes_to_bytearray  s0    z1AssortedBytesTest.test_compare_bytes_to_bytearrayc                 C   sH   |  tj | tjdtj |  tj | tjdtj d S )Nz
bytearray(zbytes()ZassertIsNotNoner~   __doc__r   r  rc   r   r   r   r   test_doc  s    zAssortedBytesTest.test_docc                 C   s,   t d}t|}t|}| |t| d S )Ns   Hello world
)rc   r   r~   r"   )r   r   bufr&   r   r   r   test_from_bytearray  s    z%AssortedBytesTest.test_from_bytearrayc                 C   sp   |  tdd |  tdd |  tdd |  ttdd |  ttdd |  ttdd	 d S )
Nr1   zb''r   zb'x'r   zb'\x80'r  zbytearray(b'x')zbytearray(b'\x80'))r"   r   r~   r   r   r   r   test_to_str  s    zAssortedBytesTest.test_to_strc                 C   sR   g d}|D ]\}}|  |t|d qtddD ]}| ttdt|  q2d S )N))s   Wonderful spamzWonderful spam)s   Wonderful spam toozWonderful spam too)s     u   ª  )s   \xaa\x00\000\200z\xaa\x00\000\200r   rK   rB   zb"%s")r"   r~   rQ   r?   SyntaxErrorevalr   )r   Ztestsr&   r   r   r   r   r   test_literal  s    
zAssortedBytesTest.test_literalc                 C   s   |  dtdddg d S Nr>  r
  r   r   )r"   rC  r   r   r   r   r   test_split_bytearray  s    z&AssortedBytesTest.test_split_bytearrayc                 C   s   |  dtdddg d S r(  )r"   rD  r   r   r   r   r   test_rsplit_bytearray  s    z'AssortedBytesTest.test_rsplit_bytearrayc                 C   s   t  }| |dd| d S )Nr1   )r~   r  r<  r%   r   r   r   test_return_self  s    z"AssortedBytesTest.test_return_selfz4BytesWarning is needed for this test: use -bb optionc                 C   sR  dd }|  ddk W d    n1 s,0    Y  |  ddk W d    n1 sZ0    Y  |  ddk W d    n1 s0    Y  |  ddk W d    n1 s0    Y  |  t ddk W d    n1 s0    Y  |  dt dk W d    n1 s0    Y  |  t ddk W d    n1 sP0    Y  |  dt dk W d    n1 s0    Y  |  ddk W d    n1 s0    Y  |  ddk W d    n1 s0    Y  |  ddk W d    n1 s0    Y  |  ddk W d    n1 sD0    Y  d S )Nc                   S   s   t jdtfS r   r   r   r   r   r   bytes_warning  s    z5AssortedBytesTest.test_compare.<locals>.bytes_warningr1   r   rn   r   r~   )r   r,  r   r   r   r     s2    &&&&*,,,(((zAssortedBytesTest.test_compareN)r   r   r   r   r  r  r  r   r	   Zrequires_docstringsr!  r#  r$  r'  r)  r*  r+  unittestZ
skipUnlessr5   flagsr,  r   r   r   r   r   r    s$   





r  c                   @   s   e Zd Zdd Zdd ZdS )BytearrayPEP3137Testc                 C   s   t |S r   r-  )r   r   r   r   r   marshal   s    zBytearrayPEP3137Test.marshalc                 C   s   |  d}dD ]4}t||}|d}| || | |||d  qdD ]*}t|}| || | |||d  qH|  d}||g}| || | || d S )Ns   1234)zfillrl  rj  rg  rM   z" returned self on a mutable object)zval.split()[0]zval.rsplit()[0]zval.partition(b".")[0]zval.rpartition(b".")[2]zval.splitlines()[0]zval.replace(b"", b"")z! returned val on a mutable objectr1   )r1  getattrr"   r  r&  r  )r   valZmethnamer{  Znewvalexprsepr   r   r   test_returns_new_copy#  s$    


z*BytearrayPEP3137Test.test_returns_new_copyN)r   r   r   r1  r7  r   r   r   r   r0    s   r0  c                       s    e Zd Z fddZdZ  ZS )FixedStringTestc                    s&   t |tr| |dS t |S )Nr   )
isinstancer   r!   r   superfixtype)r   r  r$   r   r   r;  ;  s    
zFixedStringTest.fixtypeT)r   r   r   r;  Zcontains_bytes__classcell__r   r   r<  r   r8  :  s   r8  c                   @   s   e Zd ZeZdS )ByteArrayAsStringTestN)r   r   r   r~   r!   r   r   r   r   r>  B  s   r>  c                   @   s   e Zd ZeZdS )BytesAsStringTestN)r   r   r   rc   r!   r   r   r   r   r?  E  s   r?  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )SubclassTestc                 C   s   |  t| j| j | |  | j d\}}| || | }}|  ||k |  ||k |  ||k  |  ||k |  ||k |  ||k | || | || ||  | || ||  | || ||  |  |d |d k d S )N)r)      efghro   )r   
issubclassr!   basetyper  r  r"   )r   r-   r&   Z_aZ_br   r   r   
test_basicK  s    zSubclassTest.test_basicc                 C   s`   |  d}|  |g}| || | t|| jt| |dg}| t|| j d S r(   )r!   rC  r  r  r4  r#   )r   s1s2Zs3r   r   r   r  c  s    
zSubclassTest.test_joinc                 C   s   |  d}d|_|  d|_ttjd D ]}tt||}| t	|t	| | 
|| | 
|j|j | 
|j|j | 
t|t| | 
t|jt|j q*d S )Nr)   r8   rA  r3   )r!   r   yrQ   rT  rU  rW  rV  assertNotEqualidr"   r#   )r   r-   rX  r&   r   r   r   test_picklep  s    
zSubclassTest.test_picklec                 C   s   |  d}d|_|  d|_tjtjfD ]x}||}| t|t| | || | |j|j | |j|j | t|t| | t|jt|j q(d S )Nr)   r8   rA  )	r!   r   rG  r*   r+   rH  rI  r"   r#   r,   r   r   r   r.   }  s    
zSubclassTest.test_copyc                    s    j d} |d  t| j  G  fddd j}|d} |d  t||  |jd G  fddd j}|d} |d  t||  |jd d S )Nr   r   c                       s   e Zd Z fddZdS )z%SubclassTest.test_fromhex.<locals>.B1c                    s    j | |}d|_|S Nbar)rC  __new__foo)clsr   mer   r   r   rM    s    z-SubclassTest.test_fromhex.<locals>.B1.__new__N)r   r   r   rM  r   r   r   r   B1  s   rQ  rL  c                       s   e Zd Z fddZdS )z%SubclassTest.test_fromhex.<locals>.B2c                    s.    j tur$ j j| g|R i | d| _d S rK  )rC  rc   r   rN  )rP  r   kwargsr   r   r   r     s    
z.SubclassTest.test_fromhex.<locals>.B2.__init__Nr   r   r   r   r   r   r   r   B2  s   rT  )r!   r   r"   r4  r#   rC  rN  )r   r&   rQ  rT  r   r   r   r     s    

zSubclassTest.test_fromhexN)r   r   r   rD  r  rJ  r.   r   r   r   r   r   r@  I  s
   r@  c                   @   s   e Zd ZdS )ByteArraySubclassNru   r   r   r   r   rU    s   rU  c                   @   s   e Zd ZdS )r  Nru   r   r   r   r   r    s   r  c                   @   s   e Zd ZdS )r  Nru   r   r   r   r   r    s   r  c                   @   s   e Zd ZeZeZdd ZdS )ByteArraySubclassTestc                 C   sN   G dd dt }|dd}|ddd}| |d |ddd}| |d d S )Nc                   @   s   e Zd ZdddZdS )z:ByteArraySubclassTest.test_init_override.<locals>.subclassr3   c                 _   s   t j| g|R i | d S r   )r~   r   )rP  newargr   rR  r   r   r   r     s    zCByteArraySubclassTest.test_init_override.<locals>.subclass.__init__N)r3   rS  r   r   r   r   subclass  s   rX  r|   r)   )source)rW  rY  r  )r   rX  r   r   r   r   test_init_override  s    
z(ByteArraySubclassTest.test_init_overrideN)r   r   r   r~   rC  rU  r!   rZ  r   r   r   r   rV    s   rV  c                   @   s   e Zd ZeZeZdS )BytesSubclassTestN)r   r   r   rc   rC  r  r!   r   r   r   r   r[    s   r[  __main__)+rl   r  r  r5   r*   r   rT  r  r   r.  Ztest.supportr   Ztest.string_testsZtest.list_testsr   r   Ztest.support.script_helperr   r/  r,  r   r   r    ZTestCaser  r  r  r0  Zstring_testsZBaseTestr8  r>  r?  r@  r~   rU  rc   r  r  rV  r[  r   mainr   r   r   r   <module>   s\   
       - A   ~ ]
