o 6a-@sddlZddlZddlZddlZddlmZddlmZmZddl m Z m Z m Z m Z mZmZmZmZmZddl mZmZmZddlmZmZmZmZmZmZGdddZdS) N)Path)NamedTemporaryFile TemporaryFile) memmapsumaverageproductndarrayisscalaraddsubtractmultiply)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.S)/ TestMemmapcCs:tdd|_d|_d|_td|jd|_|j|jdS)Nmmap)prefix)float32 dtype)rtmpfpshaperrdataresizeselfr&>/usr/lib/python3/dist-packages/numpy/core/tests/test_memmap.pysetups zTestMemmap.setupcCs(|jd|_trttdSdS)N)r closer"rrr$r&r&r'teardowns  zTestMemmap.teardowncCsrt|j|jd|jd}|jdd|dd<~t|j|jd|jd}tt|j|t|j|t|j j ddS)Nw+rmoder!rF) rr rr!r"rrrrflags writeable)r%fpnewfpr&r&r'test_roundtrip s   zTestMemmap.test_roundtripcCs8|d}t||jd|jd}|jdd|dd<~dS)Nrr+r,)rrr!r")r%tmp_pathtmpnamer1r&r&r'test_open_with_filename.s  z"TestMemmap.test_open_with_filenamecCs@t}t||j|jd}~WddS1swYdSNrr!)rrrr!)r%fr1r&r&r'test_unnamed_file5s"zTestMemmap.test_unnamed_filecCs>d}d}t|j|j||j|d}t||jt||j~dS)Nr+)rr-r!offset)rr rr!rr<r-)r%r<r-r1r&r&r'test_attributes:s   zTestMemmap.test_attributescCsn|d}t||jd|jd}ttj|}|jdd|dd<t||j |dd}t||j ~~dSNrr+r,r;) rrr!rospathabspathr"rfilenamer%r4r5r1rAbr&r&r' test_filenameCs    zTestMemmap.test_filenamecCs|d}tt||jd|jd}tt|}|jdd|dd<t|t|j|dd}t|t|j~~dSr>) rrrr!strresolver"rrBrCr&r&r' test_pathOs zTestMemmap.test_pathcCs*t|j|jd|jd}t|j|jjdS)Nr+r,)rr rr!rrBnamer%r1r&r&r'test_filename_fileobj^s z TestMemmap.test_filename_fileobjgnu0zKnown to fail on hurd)reasoncCsLt|j|jd|jd}|jdd|dd<t|d|jd|dS)Nr+r,r)rr rr!r"rflushrJr&r&r' test_flushcs  zTestMemmap.test_flushcCsbt|j|jd|jd}d|d<|dd}t|dd~t|ddd|d<t|dddS)Nr+r,rr;)rr rr!r)r%fp_basefp_viewr&r&r'test_dells  zTestMemmap.test_delcCs@t|j|jd|jd}|d}t|trt|j|judSdS)Nr+r, rr rr! isinstancer_mmapr%r1tmpr&r&r' test_arithmetic_drops_referencesz  z+TestMemmap.test_arithmetic_drops_referencescCs@t|j|jd|jd}|d}t|trt|j|judSdS)Nr+r,))r;)r]rrVrYr&r&r'test_indexing_drops_referencesr\z)TestMemmap.test_indexing_drops_referencescCs:t|j|jd|jd}t|ddddfj|judS)Nr+r,r])rr rr!rrXrJr&r&r'test_slicing_keeps_referencess $z(TestMemmap.test_slicing_keeps_referencescCsZt|j|j|jd}|}|}t|j|ut|j|ut|}t|j|udSr7)rr rr!viewrbaser)r%r1new1new2 new_arrayr&r&r' test_viewszTestMemmap.test_viewcCs@t|j|j|jd}|j|dd<tA}|tdtt t fD]-}||}t t |t |j |jdj ut ||ddj tut ||ddj tuq Wdn1sXwYtttfD]"}t |||jj tut ||j|j tut |||j tuqb|d7}|j tusJt|d|d|j tusJdS)Nr8z&np.average currently does not preserve)rrraxisr;)out)rr rr!r"rfilter FutureWarningrrrrr __class__r r r r )r%r1supunary_opresult binary_opr&r&r'test_ufunc_return_ndarrays(   z$TestMemmap.test_ufunc_return_ndarraycCsZt|j|j|jd}|j|dd<t|ddddfjtut|ddgjtudS)Nr8r;r)rr rr!r"rrkr rJr&r&r' test_getitemszTestMemmap.test_getitemcCsGdddt}||j|j|jd}|j|dd<tt|ddj|utt|j|ut|ddddfj|u|ddgj|usGJdS)Nc@s eZdZdS)z7TestMemmap.test_memmap_subclass..MemmapSubClassN)__name__ __module__ __qualname__r&r&r&r'MemmapSubClasssrvr8rrfr;rq)rr rr!r"rrrk)r%rvr1r&r&r'test_memmap_subclassszTestMemmap.test_memmap_subclasscCs8dtj}tjd}t|j|d|d}t|j|kdS)NrPr;r+)r!r-r<)rALLOCATIONGRANULARITYrr rr<)r%sizer<r1r&r&r'4test_mmap_offset_greater_than_allocation_granularitys  z?TestMemmap.test_mmap_offset_greater_than_allocation_granularitycCs*|jdt|jdd}t|jddS)Nsaaaaaaaaaaaaaaaafloat64r)r])r writerrr!)r%mmr&r&r' test_no_shapes zTestMemmap.test_no_shapecCs^tjtddt|jdddWdn1swY|jdt|jddddS)Nz empty file)match)rrr+)r!r-)pytestraises ValueErrorrr r|r$r&r&r'test_empty_arrays  zTestMemmap.test_empty_arrayN)rsrtrur(r*r3r6r:r=rErHrKrmarkskipifsysplatformrOrTr[r^r_rerprrrwrzr~rr&r&r&r'rs2     r)rr?rrpathlibrtempfilerrnumpyrrrrr r r r r rrr numpy.testingrrrrrrrr&r&r&r's ,