o 6a@sdZddlZddlmZddlmZddlZddlm Z m Z m Z ej dfej dfejdfejd fejd fejd fejd fejd fejdfejdfejdfejdfejdfejdfejdfejdfejdfejdfgZee\Z Z!GdddZ"dS)z2 Test scalar buffer interface adheres to PEP 3118 N)rational)get_buffer_info)assert_ assert_equal assert_raises?bhilqBHILQefdgZfZdZgc @seZdZejjdeedddZejjdeedddZ ejjde eddd Z ejjdeedd d Z d d Z ddZddZejdejdddejdddejdddgddZddZdS)TestScalarPEP3118scalar)idscCs<|}tjgt|d}t|}t|}t|j|jdS)Ndtype)nparrayr memoryviewrformat)selfrxamv_xmv_ar'D/usr/lib/python3/dist-packages/numpy/core/tests/test_scalarbuffer.pytest_scalar_match_array%s z)TestScalarPEP3118.test_scalar_match_arraycCsV|}t|}t|jt|jt|jdt|jdt|jdt|jddS)Nrr') r ritemsizerrndimshapestrides suboffsets)r"rr#r%r'r'r(test_scalar_dim-s   z!TestScalarPEP3118.test_scalar_dimz scalar, codecCsN|}td|jjdd|dd}t|}t|j|||||ks%JdS)Nr'rTr-r*r+r,r!readonly)dictrr*r printr1_as_dict)r"rcoder#expectedr%r'r'r(test_scalar_code_and_properties7s z1TestScalarPEP3118.test_scalar_code_and_propertiescCsF|}tjtddt|dgWddS1swYdS)Nscalar buffer is readonlymatchWRITABLE)pytestraises BufferErrorr)r"rr#r'r'r(test_scalar_buffers_readonlyAs"z.TestScalarPEP3118.test_scalar_buffers_readonlycCs6tdtjdfdtjdfg}tjd|dd}tt|tjt|}dttjdfj }|d ttjj 7}t |j |t |j d t |j dt |j dt |jdtjd d g|d}tt|tjt|}t |j |j t |j|jtjtd dt|dgWddS1swYdS)Nnamegrades))ndarray_scalar)g333333?g@rr'rCr)Sarah)g @@)John)g@rGr8r9r;)rrunicode_float64rr isinstancevoidr r*rr+r,r-r.ndarrayr!r<r=r>r)r"dtr#r% expected_sizer$r&r'r'r( test_void_scalar_structured_dataGs&     "z2TestScalarPEP3118.test_void_scalar_structured_datacCs t|j|j|j|j|j|jdS)N)r-r,r*r+r!r1)r2r-r,r*r+r!r1)r"mr'r'r(r4`s zTestScalarPEP3118._as_dictcCstd}td}tddddddd}t|}|||ks!Jt||}|||ks0Jtd d g}td|}ttt ft|d t j t d d t |dgWddS1s`wYdS)Nz 2016-01-01z 2017-01-01)rErE)r Tr0)r$uint16)rzM8[s]rr8r9r;) r datetime64r2r r4remptyr ValueErrorr>r<r=r)r"dt1dt2r6vrNr$r'r'r(test_datetime_memoryviewds     "z*TestScalarPEP3118.test_datetime_memoryviews22ascii)idu️️zbasic multilingualu💻💻znon-BMPcCst|}tddddddd}t|}|||ksJtj|dd}t|d d |Dtjt d d t |d gWddS1sFwYdS)Nr'rRr2wTr0i4rcSsg|]}t|qSr')ord).0cr'r'r( sz3TestScalarPEP3118.test_str_ucs4..r8r9r;) rstr_r2r r4 frombufferrr<r=r>r)r"r[r6rY code_pointsr'r'r( test_str_ucs4{s  "zTestScalarPEP3118.test_str_ucs4cCsxtd}tt t|Wdn1swYtjtddt|dgWddS1s5wYdS)NrEr8r9r;)rr TypeErrorr r<r=r>r)r"rr'r'r(test_user_scalar_fails_buffers  "z/TestScalarPEP3118.test_user_scalar_fails_bufferN)__name__ __module__ __qualname__r<mark parametrize scalars_only codes_onlyr)r/scalars_and_codesr7r?rPr4rZparamrhrkr'r'r'r(r#s&         r)#__doc__numpyrnumpy.core._rational_testsrnumpy.core._multiarray_testsrr< numpy.testingrrrbool_byteshortintcint_longlongubyteushortuintcuint ulonglonghalfsingledouble longdoublecsinglecdouble clongdoublersziprqrrrr'r'r'r(s6