
    <e                         d Z ddlZddlmZ ddlZddlZddlmZ  G d de          Z	 G d dej
                  Zed	k    r ej                     dS dS )
z[Unit tests for the PickleBuffer object.

Pickling tests themselves are in pickletester.py.
    N)PickleBuffer)import_helperc                       e Zd ZdS )BN)__name__
__module____qualname__     -/usr/lib/python3.11/test/test_picklebuffer.pyr   r      s        Dr   r   c                   V    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )PickleBufferTestc                    t          |          5 }t          |          5 }|                     |j        |j                   |                     |j        |j                   |                     |j        |j                   |                     |j        |j                   |                     |j        |j                   |                     |j        |j                   |                     |j        |j                   |                     |j	        |j	                   |                     |
                                |
                                           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S N)
memoryviewassertEqualnbytesreadonlyitemsizeshapestridesc_contiguousf_contiguousformattobytes)selfpbequivmexpecteds        r   check_memoryviewz!PickleBufferTest.check_memoryview   s   ^^ 
	BqE"" 	Bh  8?;;;  X->???  X->???  (.999  H,<===  1FGGG  1FGGG  8?;;;  h.>.>.@.@AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	B 
	Bs5   E?D;E'E?'E+	+E?.E+	/E??FFc                    |                      t                    5  t                       d d d            n# 1 swxY w Y   |                      t                    5  t          d           d d d            n# 1 swxY w Y   t          d          }|                                 |                      t
                    5  t          |           d d d            d S # 1 swxY w Y   d S )Nfoo   foo)assertRaises	TypeErrorr   r   release
ValueError)r   r   s     r   test_constructor_failurez)PickleBufferTest.test_constructor_failure!   s   y)) 	 	NNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	y)) 	  	 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  v			z** 	 	OOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s0   6::A77A;>A;?CC #C c                 <   t          d          }|                     dt          |                     t          |          5 }|                     |j                   d d d            n# 1 swxY w Y   t          t          d                    }|                     dt          |                     t          |          5 }|                     |j                   d|d<   d d d            n# 1 swxY w Y   |                     dt          |                     d S )Nr$   0   r   s   0oo)r   r   bytesr   
assertTruer   	bytearrayassertFalse)r   r   r   s      r   test_basicszPickleBufferTest.test_basics,   sq   &!!r+++^^ 	(qOOAJ'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( )F++,,r+++^^ 	qQZ(((AaD	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	r+++++s$   A))A-0A- C..C25C2c                 F   t          d          }|                                 |                     t                    5 }t	          |           d d d            n# 1 swxY w Y   |                     dt          |j                             |                                 d S )Nr$   z3operation forbidden on released PickleBuffer object)r   r'   r%   r(   r   assertInstr	exceptionr   r   raisess      r   test_releasezPickleBufferTest.test_release9   s    &!!


z** 	frNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	K&*++	- 	- 	- 	

s   AA!Ac                     t          d          }t          |          }||_        t          j        |          }~~t          j                     |                      |                       d S Nr$   )r   r   cycleweakrefrefgccollectassertIsNone)r   br   wpbs       r   
test_cyclezPickleBufferTest.test_cycleC   s\    fII!__k"oor

##%%     r   c                    t          j        d          j        } |t          t	          d                    dd          }|                     |j                   |                     |j                   t          |          }| 
                    ||           |d d d         }|                     |j                   |                     |j                   t          |          }| 
                    ||            |t          t	          d                    ddd	          }|                     |j                   |                     |j                   t          |          }| 
                    ||           d S )
N_testbuffer         <ir   r      )rH   rG   )rG   rE   r   r   r   )r   import_modulendarraylistranger-   r   r/   r   r   r!   )r   rN   arrr   s       r   test_ndarray_2dz PickleBufferTest.test_ndarray_2dL   s_   -m<<Dgd599ooVDAAA())))***#b#&&&##A#h)***)***#b#&&&gd599ooVWTRRR())))***#b#&&&&&r   c                     t          |          }|                                5 }|                     |t                     |                     ||           d d d            d S # 1 swxY w Y   d S r   )r   rawassertIsInstancer   r!   )r   objr   r   r   s        r   	check_rawzPickleBufferTest.check_rawc   s    #VVXX 	,!!!Z000!!!U+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   2A##A'*A'c                     dt          d          fD ]F}|                     |          5  |                     ||           d d d            n# 1 swxY w Y   Gd S )Nr$   )rV   )r.   subTestrW   )r   rV   s     r   test_rawzPickleBufferTest.test_rawi   s    If--. 	) 	)C#&& ) )sC((() ) ) ) ) ) ) ) ) ) ) ) ) ) )	) 	)s   AA	A	c                    t          j        d          j        } |t          t	          d                    dd          }d}|                     ||            |t          t	          d                    dd          }d	}|                     ||            |t          t	          d                    dd
d          }d	}|                     ||            |ddd          }d}|                     ||           d S )NrD   rH   )rH   z<hrJ   s          )rK   rH   s          )rK   rG   rL   i  r
   rI   s     )r   rM   rN   rO   rP   rW   )r   rN   rQ   r   s       r   test_raw_ndarrayz!PickleBufferTest.test_raw_ndarrayn   s   -m<<Dgd588nnD>>>+sE"""gd588nnF4@@@CsE"""gd588nnFF!# # # DsE"""gcD111#sE"""""r   c                     t          |          }|                     t          d          5  |                                 d d d            d S # 1 swxY w Y   d S )Nznon-contiguous)r   assertRaisesRegexBufferErrorrT   )r   rV   r   s      r   check_raw_non_contiguousz)PickleBufferTest.check_raw_non_contiguous   s    ###K1ABB 	 	FFHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                 P   t          j        d          j        } |t          t	          d                    dd          d d d         }|                     |            |t          t	          d                    dd          d d d         }|                     |           d S )	NrD   r\   )r\   rI   rJ   rK   rE   rF   )r   rM   rN   rO   rP   ra   )r   rN   rQ   s      r   test_raw_non_contiguousz(PickleBufferTest.test_raw_non_contiguous   s    -m<<Dgd588nnD>>>sssC%%c***gd599ooVDAAA##A#F%%c*****r   c                     t          d          }|                                 |                     t                    5 }|                                 d d d            d S # 1 swxY w Y   d S r9   )r   r'   r%   r(   rT   r5   s      r   test_raw_releasedz"PickleBufferTest.test_raw_released   s    &!!


z** 	fFFHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A  A$'A$N)r   r   r	   r!   r)   r0   r7   rB   rR   rW   rZ   r]   ra   rc   re   r
   r   r   r   r      s        B B B	 	 	, , ,  ! ! !' ' '., , ,) ) )
# # #*  
+ + +    r   r   __main__)__doc__r=   pickler   r;   unittesttest.supportr   r,   r   TestCaser   r   mainr
   r   r   <module>rm      s    
 
			         & & & & & &	 	 	 	 	 	 	 	C C C C Cx( C C CL zHMOOOOO r   