o
    0c;                     @   s   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mZ d dl	m
Z
mZmZmZmZmZmZmZmZ d dl	mZmZmZ d dlmZmZmZmZmZmZ G dd dZdS )	    N)Path)NamedTemporaryFileTemporaryFile)	memmapsumaverageproductndarrayisscalaraddsubtractmultiply)arangeallcloseasarray)assert_assert_equalassert_array_equalsuppress_warningsIS_PYPYbreak_cyclesc                   @   s   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ejjejdkdd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.S )/
TestMemmapc                 C   s:   t dd| _d| _d| _td| jd| _| j| j d S )Nmmap)prefix)      float32   dtype)r   tmpfpshaper   r   dataresizeself r&   R/var/www/html/gps/gps/lib/python3.10/site-packages/numpy/core/tests/test_memmap.pysetup_method   s
   zTestMemmap.setup_methodc                 C   s(   | j   d | _trt  t  d S d S )N)r    closer"   r   r   r$   r&   r&   r'   teardown_method   s   

zTestMemmap.teardown_methodc                 C   sr   t | j| jd| jd}| jd d  |d d < ~t | j| jd| jd}tt| j| t| j| t|j	j
d d S )Nw+r   moder!   rF)r   r    r   r!   r"   r   r   r   r   flags	writeable)r%   fpnewfpr&   r&   r'   test_roundtrip    s   zTestMemmap.test_roundtripc                 C   s8   |d }t || jd| jd}| jd d  |d d < ~d S )Nr   r+   r,   )r   r   r!   r"   )r%   tmp_pathtmpnamer1   r&   r&   r'   test_open_with_filename.   s   
z"TestMemmap.test_open_with_filenamec                 C   s@   t  }t|| j| jd}~W d    d S 1 sw   Y  d S Nr   r!   )r   r   r   r!   )r%   fr1   r&   r&   r'   test_unnamed_file5   s   "zTestMemmap.test_unnamed_filec                 C   s>   d}d}t | j| j|| j|d}t||j t||j ~d S )N   r+   )r   r-   r!   offset)r   r    r   r!   r   r<   r-   )r%   r<   r-   r1   r&   r&   r'   test_attributes:   s   zTestMemmap.test_attributesc                 C   sn   |d }t || jd| jd}ttj|}| jd d  |d d < t||j	 |d d }t||j	 ~~d S Nr   r+   r,   r;   )
r   r   r!   r   ospathabspathr"   r   filenamer%   r4   r5   r1   rA   br&   r&   r'   test_filenameC   s   
zTestMemmap.test_filenamec                 C   s   |d }t t|| jd| jd}tt| }| jd d  |d d < t|t|j  |d d }t|t|j  ~~d S r>   )	r   r   r   r!   strresolver"   r   rB   rC   r&   r&   r'   	test_pathO   s   zTestMemmap.test_pathc                 C   s*   t | j| jd| jd}t|j| jj d S )Nr+   r,   )r   r    r   r!   r   rB   namer%   r1   r&   r&   r'   test_filename_fileobj^   s   z TestMemmap.test_filename_fileobjgnu0zKnown to fail on hurd)reasonc                 C   sL   t | j| jd| jd}| jd d  |d d < t|d | jd  |  d S )Nr+   r,   r   )r   r    r   r!   r"   r   flushrJ   r&   r&   r'   
test_flushc   s   zTestMemmap.test_flushc                 C   sb   t | j| jd| jd}d|d< |dd }t|d d ~t|d d d|d< t|d d d S )Nr+   r,      r   r;      )r   r    r   r!   r   )r%   fp_basefp_viewr&   r&   r'   test_dell   s   zTestMemmap.test_delc                 C   s@   t | j| jd| jd}|d }t|t rt|j|ju d S d S )Nr+   r,   
   r   r    r   r!   
isinstancer   _mmapr%   r1   tmpr&   r&   r'    test_arithmetic_drops_referencesz      
z+TestMemmap.test_arithmetic_drops_referencesc                 C   s@   t | j| jd| jd}|d }t|t rt|j|ju d S d S )Nr+   r,   ))r;      )r]   r   rV   rY   r&   r&   r'   test_indexing_drops_references   r\   z)TestMemmap.test_indexing_drops_referencesc                 C   s:   t | j| jd| jd}t|d dd df j|ju  d S )Nr+   r,   r]   )r   r    r   r!   r   rX   rJ   r&   r&   r'   test_slicing_keeps_references   s   $z(TestMemmap.test_slicing_keeps_referencesc                 C   sZ   t | j| j| jd}| }| }t|j|u  t|j|u  t|}t|j|u  d S r7   )r   r    r   r!   viewr   baser   )r%   r1   new1new2	new_arrayr&   r&   r'   	test_view   s   zTestMemmap.test_viewc                 C   s@  t | j| j| jd}| j|d d < t A}|td tt	t
fD ]-}||}tt| t|j| jd ju  t||ddjtu  t||ddjtu  q W d    n1 sXw   Y  tttfD ]"}t||| jjtu  t|| j|jtu  t|||jtu  qb|d7 }|jt u sJ t|d|d |jt u sJ d S )Nr8   z&np.average currently does not preserve)r   r   r   axisr;   )out)r   r    r   r!   r"   r   filterFutureWarningr   r   r   r   r
   	__class__r	   r   r   r   )r%   r1   supunary_opresult	binary_opr&   r&   r'   test_ufunc_return_ndarray   s(   
z$TestMemmap.test_ufunc_return_ndarrayc                 C   sZ   t | j| j| jd}| j|d d < t|dd d df jt u  t|ddg jtu  d S )Nr8   r;   r   )r   r    r   r!   r"   r   rk   r	   rJ   r&   r&   r'   test_getitem   s   zTestMemmap.test_getitemc                 C   s   G dd dt }|| j| j| jd}| j|d d < tt|ddj|u  tt|j|u  t|dd d df j|u  |ddg j|u sGJ d S )Nc                   @   s   e Zd ZdS )z7TestMemmap.test_memmap_subclass.<locals>.MemmapSubClassN)__name__
__module____qualname__r&   r&   r&   r'   MemmapSubClass   s    rv   r8   r   rf   r;   rq   )r   r    r   r!   r"   r   r   rk   )r%   rv   r1   r&   r&   r'   test_memmap_subclass   s   zTestMemmap.test_memmap_subclassc                 C   s8   dt j }t jd }t| j|d|d}t|j|k d S )NrP   r;   r+   )r!   r-   r<   )r   ALLOCATIONGRANULARITYr   r    r   r<   )r%   sizer<   r1   r&   r&   r'   4test_mmap_offset_greater_than_allocation_granularity   s   

z?TestMemmap.test_mmap_offset_greater_than_allocation_granularityc                 C   s*   | j d t| j dd}t|jd d S )Ns   aaaaaaaaaaaaaaaafloat64r   )r]   )r    writer   r   r!   )r%   mmr&   r&   r'   test_no_shape   s   zTestMemmap.test_no_shapec                 C   s^   t jtdd t| jddd W d    n1 sw   Y  | jd t| jddd d S )Nz
empty file)match)r   r   r+   )r!   r-       )pytestraises
ValueErrorr   r    r|   r$   r&   r&   r'   test_empty_array   s
   zTestMemmap.test_empty_arrayN)rs   rt   ru   r(   r*   r3   r6   r:   r=   rE   rH   rK   r   markskipifsysplatformrO   rT   r[   r^   r_   re   rp   rr   rw   rz   r~   r   r&   r&   r&   r'   r      s2    	
	r   )r   r?   r   r   pathlibr   tempfiler   r   numpyr   r   r   r   r	   r
   r   r   r   r   r   r   numpy.testingr   r   r   r   r   r   r   r&   r&   r&   r'   <module>   s    , 