
    ݑfWu                         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 d dlmZ  G d dej                        Z	e
dk(  r ej                          yy)    N)FileChunkIO)SEEK_CUR)SEEK_ENDc                   l    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zy)FileChunkIOTestc                    t        j                         d   | _        t        | j                  d      5 }|j	                  dt
        j                  z         |j	                  dt
        j                  z         |j	                  dt
        j                  z         |j	                  dt
        j                  z         |j	                  d       d d d        y # 1 sw Y   y xY w)N   wz123456789%sz234567891%sz345678912%sz456789123%s56789)tempfilemkstemptfopenwriteoslinesep)selffs     1lib/python3.12/site-packages/filechunkio/tests.pysetUpzFileChunkIOTest.setUp   s    ""$Q'$''3 	1GGMBJJ./GGMBJJ./GGMBJJ./GGMBJJ./GGG	 	 	s   BCCc                     t         j                  j                  | j                        r t        j                  | j                         y y )N)r   pathexistsr   remover   s    r   tearDownzFileChunkIOTest.tearDown   s+    77>>$''"IIdgg #    c                 P    | j                  t        t        | j                  d       y )Nr
   )assertRaises
ValueErrorr   r   r   s    r   !test_open_write_raises_valueerrorz1FileChunkIOTest.test_open_write_raises_valueerror   s    *k477C@r   c                     t        | j                        5 }| j                  |j                  d       d d d        y # 1 sw Y   y xY w)N-   r   r   assertEqualbytesr   cs     r   test_init_autosets_bytesz(FileChunkIOTest.test_init_autosets_bytes   s9    ! 	*QQWWb)	* 	* 	*s	   <Ac                     t        | j                  d      5 }| j                  |j                  d       d d d        y # 1 sw Y   y xY w)Nr	   offset,   r$   r'   s     r   ,test_init_autosets_bytes_and_respects_offsetz<FileChunkIOTest.test_init_autosets_bytes_and_respects_offset"   s;    + 	*qQWWb)	* 	* 	*s	   >Ac                     t        | j                  d      5 }| j                  |j                         d       | j                  |j	                  d      d       d d d        y # 1 sw Y   y xY wNr	   r+   r      2r   r   r%   tellreadr'   s     r   test_init_seeks_to_offsetz)FileChunkIOTest.test_init_seeks_to_offset&   U    + 	.qQVVXq)QVVAY-	. 	. 	.   AA##A,c                     t        | j                  d      5 }|j                  d       | j                  |j	                  d      d       d d d        y # 1 sw Y   y xY w)Nr	   r+      3)r   r   seekr%   r4   r'   s     r   test_seek_respects_offsetz)FileChunkIOTest.test_seek_respects_offset+   sJ    + 	.qFF1IQVVAY-	. 	. 	.s   3AAc                     t        | j                  dd      5 }|j                  d       |j                  dt               | j	                  |j                         d       d d d        y # 1 sw Y   y xY w)N   
   r,   r&         )r   r   r:   r   r%   r3   r'   s     r   test_seek_curzFileChunkIOTest.test_seek_cur0   sX    26 	*!FF1IFF2x QVVXq)	* 	* 	*s   AA**A3c                     t        | j                  dd      5 }|j                  dt               | j	                  |j                  d      d       d d d        y # 1 sw Y   y xY w)Nr>   r?      s   789)r   r   r:   r   r%   r4   r'   s     r   test_seek_endzFileChunkIOTest.test_seek_end6   sO    26 	0!FF2x QVVAY/	0 	0 	0s   8AA#c                     t        | j                  d      5 }| j                  |j                         d       | j                  |j	                  d      d       d d d        y # 1 sw Y   y xY wr0   r2   r'   s     r   test_tell_respects_offsetz)FileChunkIOTest.test_tell_respects_offset;   r6   r7   c                      t         j                        5 } fd}||_        |j                  d        j	                   j
                         d d d        y # 1 sw Y   y xY w)Nc                      d_         y )NT)_readall_called)argskwargsr   s     r   mocked_readallzNFileChunkIOTest.test_read_with_minus_one_calls_readall.<locals>.mocked_readallB   s    '+$r   )r   r   readallr4   
assertTruerL   )r   r(   rO   s   `  r   &test_read_with_minus_one_calls_readallz6FileChunkIOTest.test_read_with_minus_one_calls_readall@   sO    ! 	2Q,&AIFF2JOOD001	2 	2 	2s   9AA"c                     t        | j                  dd      5 }| j                  |j                         d       d d d        y # 1 sw Y   y xY w)Nr	   rF   r?   s   234)r   r   r%   r4   r'   s     r   #test_read_respects_offset_and_bytesz3FileChunkIOTest.test_read_respects_offset_and_bytesI   s?    !4 	/QVVXv.	/ 	/ 	/s   !AAc                     t        | j                  dd      5 }d}t        |j                               }|j	                  |       | j                  |d       d d d        y # 1 sw Y   y xY w)Nr	   rB   r?   rF   s   23 )r   r   	bytearray	__index__readintor%   )r   r(   nbs       r   test_readintozFileChunkIOTest.test_readintoM   sY    !4 	+A!++-(AJJqMQ	*		+ 	+ 	+s   ?A!!A*c                     t        | j                  dd      5 }g }	 |j                         }|sn|j                  |       %| j	                  |g d       d d d        y # 1 sw Y   y xY wNr	   r=   r?   )	   23456789
s
   234567891
r9   )r   r   readlineappendr%   )r   r(   lineslines       r   test_readlinezFileChunkIOTest.test_readlineT   sj    "5 	KEzz|T"	 
 U$IJ	K 	K 	Ks   =AA(c                     t        | j                  dd      5 }| j                  |j                         ddg       d d d        y # 1 sw Y   y xY w)Nr	      r?   r_   s   234567)r   r   r%   	readlinesr'   s     r   test_readlineszFileChunkIOTest.test_readlines^   sH    "5 	HQ[[]]I,FG	H 	H 	Hs   #AAc                     t        | j                  dd      5 }g }	 	 |j                  t        |             # t        $ r Y nw xY w| j                  |g d       d d d        y # 1 sw Y   y xY wr^   )r   r   ra   nextStopIterationr%   )r   r(   rb   s      r   	test_nextzFileChunkIOTest.test_nextb   st    "5 	KELLa)  % U$IJ	K 	K 	Ks+   A%9A%	AA%AA%%A.N)__name__
__module____qualname__r   r   r!   r)   r.   r5   r;   rC   rG   rI   rS   rU   r\   rd   rh   rl    r   r   r   r      sV    A**.
.
*0
.
2/+KHKr   r   __main__)ior   r   unittestfilechunkior   r   r   TestCaser   rm   mainrp   r   r   <module>rw      sK    	 	   #    _Kh'' _KD zHMMO r   