a :jg?@sddlZddlZddlZddlZddlmZddlmZmZddl m Z m Z m Z m Z mZmZmZmZmZddl mZmZmZddlmZmZmZmZmZmZGdddZdS) N)Path)NamedTemporaryFile TemporaryFile) memmapsumaverageprodndarrayisscalaraddsubtractmultiply)arangeallcloseasarray)assert_ assert_equalassert_array_equalsuppress_warningsIS_PYPY break_cyclesc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ e j jejdkddddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0S)1 TestMemmapcCs:tdd|_d|_d|_td|jd|_|j|jdS)Nmmap)prefix)Zfloat32 dtype)rtmpfpshaperrdataresizeselfr%G/usr/local/lib/python3.9/site-packages/numpy/_core/tests/test_memmap.py setup_methods  zTestMemmap.setup_methodcCs$|jd|_tr ttdS)N)rcloser!rrr#r%r%r&teardown_methods  zTestMemmap.teardown_methodcCsrt|j|jd|jd}|jdd|dd<~t|j|jd|jd}tt|j|t|j|t|j j ddS)Nw+rmoder rF) rrrr r!rrrrflagsZ writeable)r$fpZnewfpr%r%r&test_roundtrip s   zTestMemmap.test_roundtripcCs8|d}t||jd|jd}|jdd|dd<~dS)Nrr*r+)rrr r!)r$tmp_pathtmpnamer/r%r%r&test_open_with_filename.s  z"TestMemmap.test_open_with_filenamecCs>t$}t||j|jd}~Wdn1s00YdSNrr )rrrr )r$fr/r%r%r&test_unnamed_file5szTestMemmap.test_unnamed_filecCs>d}d}t|j|j||j|d}t||jt||j~dS)Nr*)rr,r offset)rrrr rr9r,)r$r9r,r/r%r%r&test_attributes:s   zTestMemmap.test_attributescCsn|d}t||jd|jd}ttj|}|jdd|dd<t||j |dd}t||j ~~dSNrr*r+r8) rrr rospathabspathr!rfilenamer$r1r2r/r>br%r%r& test_filenameCs    zTestMemmap.test_filenamecCs|d}tt||jd|jd}tt|}|jdd|dd<t|t|j|dd}t|t|j~~dSr;) rrrr strresolver!rr?r@r%r%r& test_pathOs zTestMemmap.test_pathcCs*t|j|jd|jd}t|j|jjdS)Nr*r+)rrrr rr?namer$r/r%r%r&test_filename_fileobj^s z TestMemmap.test_filename_fileobjZgnu0zKnown to fail on hurd)reasoncCsLt|j|jd|jd}|jdd|dd<t|d|jd|dS)Nr*r+r)rrrr r!rflushrGr%r%r& test_flushcs  zTestMemmap.test_flushcCsbt|j|jd|jd}d|d<|dd}t|dd~t|ddd|d<t|dddS)Nr*r+rr8)rrrr r)r$Zfp_baseZfp_viewr%r%r&test_dells  zTestMemmap.test_delcCs<t|j|jd|jd}|d}t|tr8t|j|judS)Nr*r+ rrrr isinstancer_mmapr$r/tmpr%r%r& test_arithmetic_drops_referenceszs   z+TestMemmap.test_arithmetic_drops_referencescCs<t|j|jd|jd}|d}t|tr8t|j|judS)Nr*r+))r8)rVrrPrSr%r%r&test_indexing_drops_referencess   z)TestMemmap.test_indexing_drops_referencescCs:t|j|jd|jd}t|ddddfj|judS)Nr*r+rV)rrrr rrRrGr%r%r&test_slicing_keeps_referencess z(TestMemmap.test_slicing_keeps_referencescCsZt|j|j|jd}|}|}t|j|ut|j|ut|}t|j|udSr4)rrrr viewrbaser)r$r/Znew1Znew2Z new_arrayr%r%r& test_viewszTestMemmap.test_viewcCsDt|j|j|jd}|j|dd<t}|tdtt t fD]Z}||}t t |t |j |jdj ut ||ddj tut ||ddj tuq@Wdn1s0YtttfD]D}t |||jj tut ||j|j tut |||j tuq|d7}|j tus"Jt|d|d|j tus@JdS)Nr5z&np.average currently does not preserve)rrrZaxisr8)out)rrrr r!rfilter FutureWarningrrrrr __class__r r r r )r$r/supZunary_opresultZ binary_opr%r%r&test_ufunc_return_ndarrays$  6z$TestMemmap.test_ufunc_return_ndarraycCsZt|j|j|jd}|j|dd<t|ddddfjtut|ddgjtudS)Nr5r8r)rrrr r!rr`r rGr%r%r& test_getitemszTestMemmap.test_getitemcCsGdddt}||j|j|jd}|j|dd<tt|ddj|utt|j|ut|ddddfj|u|ddgj|usJdS)Nc@s eZdZdS)z7TestMemmap.test_memmap_subclass..MemmapSubClassN)__name__ __module__ __qualname__r%r%r%r&MemmapSubClasssrir5rr\r8rd)rrrr r!rrr`)r$rir/r%r%r&test_memmap_subclassszTestMemmap.test_memmap_subclasscCs8dtj}tjd}t|j|d|d}t|j|kdS)NrLr8r*)r r,r9)rALLOCATIONGRANULARITYrrrr9)r$sizer9r/r%r%r&4test_mmap_offset_greater_than_allocation_granularitys  z?TestMemmap.test_mmap_offset_greater_than_allocation_granularitycCs*|jdt|jdd}t|jddS)NsaaaaaaaaaaaaaaaaZfloat64r)rV)rwriterrr )r$mmr%r%r& test_no_shapes zTestMemmap.test_no_shapecCs^tjtdd t|jdddWdn1s40Y|jdt|jddddS)Nz empty file)match)rrr*r r,)pytestZraises ValueErrorrrrnr#r%r%r&test_empty_arrays. zTestMemmap.test_empty_arraycCsRt|jdddt|j|jddt|jt|jddt|jt|jdddS)Nrr*rr)rrr listrr#r%r%r&test_shape_typeszTestMemmap.test_shape_typeN)rfrgrhr'r)r0r3r7r:rBrErHrtmarkZskipifsysplatformrKrNrUrWrXr[rcrerjrmrprvrxr%r%r%r&rs2     r)rzr<rrtpathlibrtempfilerrnumpyrrrrr r r r r rrrZ numpy.testingrrrrrrrr%r%r%r&s ,