a zeg0@spddlmZmZmZddlZddlZddlZGdddejZGdddZ Gddde Z Gd d d e Z dS) )findfileTESTFNunlinkNc@seZdZddZddZdS) UnseekableIOcCs tjdSNioUnsupportedOperationselfr C/opt/bitninja-python-dojo/embedded/lib/python3.9/test/audiotests.pytellszUnseekableIO.tellcOs tjdSrr)r argskwargsr r r seek szUnseekableIO.seekN)__name__ __module__ __qualname__rrr r r r rsrc@s(eZdZdZddZddZddZdS) AudioTestsFcCsd|_|_dSr)ffoutr r r r setUpszAudioTests.setUpcCs4|jdur|j|jdur(|jttdSr)rcloserrrr r r r tearDowns     zAudioTests.tearDownc Cs |||||||||||||||||||}||||||||f||j|||j |||j |||j |||j |||j |ttjdD]"} t|| } |t| |qdS)N) assertEqual getnchannels getsampwidth getframerate getnframesZ getcomptypeZ getcompname getparams nchannels sampwidth frameratenframescomptypecompnamerangepickleHIGHEST_PROTOCOLdumpsloads) r rr"r#r$r%r&r'paramsprotodumpr r r check_paramss& zAudioTests.check_paramsN)rrrclose_fdrrr0r r r r rsrc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#S)$AudioWriteTestscCsL|j|d}|_||j||j||j| |j |j |SNwb) moduleopenr setnchannelsr" setsampwidthr# setframerater$ setcomptyper&r'r testfilerr r r create_file6s    zAudioWriteTests.create_filecCs|j|dh}|||j|||j|||j|| ||| ||Wdn1s|0YdSNrb) r5r6rrr"rr#rr$r readframes)r r<r%framesrr r r check_file>s zAudioWriteTests.check_filec CsP|t}||j||j|||j|j|j |j|j |j | dSr) r=r setnframesr% writeframesrAr0r"r#r$r&r'rr rr r r test_write_paramsFs    z!AudioWriteTests.test_write_paramsc Cs||jj>|jtdWdn1s40YWdn1sR0Y||jjfttd<}|j|Wdn1s0YWdn1s0YWdn1s0YdSr3) assertRaisesr5Errorr6r)r r<r r r &test_write_context_manager_calls_closeNs< z6AudioWriteTests.test_write_context_manager_calls_closec Csfttd}|j|D}||j||j||j| |j |j Wdn1sb0Y| |j |jWdn1s0Yttd}|j|X}||j |}| |j|j| |j|j| |j|jWdn1s0Y|js2||| |j |jWdn1sX0YdS)Nr4r?)r6rr5r7r"r8r#r9r$r:r&r'rclosedr1 assertFalsegetfpr! assertIsNone)r r<rr-r r r #test_context_manager_with_open_fileYs"    .. 0z3AudioWriteTests.test_context_manager_with_open_filecCs|jtdD}||j||j||j| |j |j Wdn1sX0Y|jtX}| | j|}||j|j||j|j||j|jWdn1s0Y|js|| dSr3)r5r6rr7r"r8r#r9r$r:r&r'rKrLrJr!rr1rM)r rr-r r r "test_context_manager_with_filenamels   ..z2AudioWriteTests.test_context_manager_with_filenamecCs@|t}||j||j||t|j|jdSr)r=rrCr%rDrArrBrEr r r test_write}s    zAudioWriteTests.test_writecCsD|t}||j|t|j||t|j|jdSr) r=rrCr%rD bytearrayrArrBrEr r r test_write_bytearrays   z$AudioWriteTests.test_write_bytearraycCsH|t}||j|td|j||t|j|jdS)Nh) r=rrCr%rDarrayrArrBrEr r r test_write_arrays   z AudioWriteTests.test_write_arraycCsD|t}||j|t|j||t|j|jdSr) r=rrCr%rD memoryviewrArrBrEr r r test_write_memoryviews   z%AudioWriteTests.test_write_memoryviewcCsttdH}|d||}||jd||j|Wdn1sX0Yttd4}| | dd| ||j|jWdn1s0YdSNr4 ababagalamagarr? r6rwriter=rCr%rDrArrreadrBr;r r r test_incompleted_writes    & z&AudioWriteTests.test_incompleted_writecCsttdp}|d||}||j|j|j}||j d| ||j | d| Wdn1s0Yttd4}| | dd| ||j|j Wdn1s0YdSNr4rYr?rZ)r6rr\r=rCr%r"r#rDrArrr]rBr r<r framesizer r r test_multiple_writess     & z$AudioWriteTests.test_multiple_writescCsttdH}|d||}||jd||j|Wdn1sX0Yttd4}| | dd| ||j|jWdn1s0YdSrXr[r;r r r test_overflowed_writes    & z%AudioWriteTests.test_overflowed_writecCs|t(}||j||jWdn1s80Yttd"}|||j|jWdn1st0YdSr>)r=rrCr%rDrArrB)r rr<r r r test_unseekable_reads   * z$AudioWriteTests.test_unseekable_readc CsttdR}||(}||j||jWdn1sD0YWdn1sb0Y|t|j|jdSr3)rrr=rCr%rDrArBr;r r r test_unseekable_writes    Hz%AudioWriteTests.test_unseekable_writec Csttdx}|d||}||jdz||jWntyRYn0z | WntyrYn0Wdn1s0Yt td8}| | dd| ||jd|jWdn1s0YdSrX)rrr\r=rCr%rDrAOSErrorrr6rr]rBr;r r r !test_unseekable_incompleted_writes      $ z1AudioWriteTests.test_unseekable_incompleted_writec Csttdx}|d||}||jdz||jWntyRYn0z | WntyrYn0Wdn1s0Yt tdN}| | dd|j |j}|||jd|jd| Wdn1s0YdSrX)rrr\r=rCr%rDrArfrr6rr]r"r#rBr`r r r test_unseekable_overflowed_writes       $  z0AudioWriteTests.test_unseekable_overflowed_writeN)rrrr=rBrFrIrNrOrPrRrUrWr^rbrcrdrergrhr r r r r24s"   r2c@s@eZdZeddZddZddZddZd d Zd d Z d S)AudioTestsWithSourceFilecCst|jdd|_dS)NZ audiodata)Zsubdir)rZ sndfilename sndfilepath)clsr r r setUpClasssz#AudioTestsWithSourceFile.setUpClassc Cs:|j|j}|_|||j|j|j|j|j |j dSr) r5r6rjrr0r"r#r$sndfilenframesr&r'rEr r r test_read_paramss z)AudioTestsWithSourceFile.test_read_paramsc Cst|jdF}|j|}|_||j|||j|jWdn1sX0Ytt d~}|j|d}|_ ||j| |jj |Wdn1s0Y||j|j|Wdn1s0YdS)Nr?r4) r6rjr5rrKrJrrr1rrrGrH)r r<rrr r r test_closes .  &z#AudioTestsWithSourceFile.test_closecCs|j|j}|jdd|}|jd|d|}|j|j}|_||dd|| d||d|| | }||d||d|| }||d||d|| |||d|| |||d|| |jj | dWdn1s80Y| |jj "| |dWdn1sz0YdS)Nrr)r"r#rAr5r6rjrrr@rrewindZsetposrGrHr )r raZchunk1Zchunk2rZpos0Zpos2r r r test_reads,     *z"AudioTestsWithSourceFile.test_readcCs|j|j}|_|jtd}|_||d}|}|dkrl|d7}| | |||8}qB| |jtd}|_| | ||| | || |dS)Nr4rrr?)r5r6rjrrrZ setparamsr!r rDr@rrtr)r rrinr r r test_copy+s   z"AudioTestsWithSourceFile.test_copyc Cs>ttdT}|dt|jd}||Wdn1sF0YWdn1sd0Yttd}||dd|j|dn}|||j|| |j || |j || |j|||j|jWdn1s0YWdn1s00YdSr_)r6rr\rjr]rr5rr"rr#rr$r rmr@r%rAr;r r r test_read_not_from_start<s  J z1AudioTestsWithSourceFile.test_read_not_from_startN) rrr classmethodrlrnrorurxryr r r r ris ri) Z test.supportrrrrTrr)FileIOrrr2rir r r r s%F