B
    u9aS  ã               @   sª   d Z ddlZddlZddlZddlZddlmZmZmZm	Z	 ddl
Z
ddlZdZG dd„ dƒZdd„ ZG d	d
„ d
eejƒZG dd„ deejƒZdd„ Zedkr¦e ¡  dS )z9Test largefile support on system where this makes sense.
é    N)ÚTESTFNÚrequiresÚunlinkÚ
bigmemtestl    y* c               @   sb   e Zd ZdZdd„ Zedd„ ƒZeedddd	d
„ ƒZ	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )ÚLargeFileTestzWTest that each file function works as expected for large
    (i.e. > 2 GiB) files.
    c          	   C   s®   t j t¡rd}nd}|  t|¡‚}t  | ¡ ¡tj }|t	d krHd S |dkrZ| 
d¡ | d¡ | t	¡ | 
d¡ | ¡  |  t  | ¡ ¡tj t	d ¡ W d Q R X d S )Nzr+bzw+bé   r   ó   zó   a)ÚosÚpathÚexistsr   ÚopenÚfstatÚfilenoÚstatÚST_SIZEÚsizeÚwriteÚseekÚflushÚassertEqual)ÚselfÚmodeÚfZcurrent_size© r   ú$/usr/lib/python3.7/test_largefile.pyÚsetUp   s    



zLargeFileTest.setUpc          	   C   s:   |   td¡ W d Q R X t t¡tj dks6|  d¡‚d S )NÚwbr   z0File was not truncated by opening with mode "wb")r   r   r
   r   r   ZfailureException)Úclsr   r   r   ÚtearDownClass(   s    
zLargeFileTest.tearDownClassé   F)r   ZmemuseZdry_runc          	   C   sH   |   td¡2}|  t| ¡ ƒtd ¡ |  | ¡ td ¡ W d Q R X d S )NÚrbr   )r   r   r   ÚlenÚreadr   Útell)r   Z_sizer   r   r   r   Útest_large_read2   s    zLargeFileTest.test_large_readc             C   s    |   t t¡tj td ¡ d S )Nr   )r   r
   r   r   r   r   )r   r   r   r   Útest_osstat9   s    zLargeFileTest.test_osstatc          	   C   s¾  |   td¡¦}|  | ¡ d¡ |  | d¡d¡ |  | ¡ d¡ | d¡ |  | ¡ d¡ | dd¡ |  | ¡ d¡ | d¡ |  | ¡ d¡ | dd¡ |  | ¡ d¡ | dd¡ |  | ¡ d¡ | dd¡ |  | ¡ d¡ | dd¡ |  | ¡ td d ¡ | dd¡ |  | ¡ td d	 ¡ | t d d¡ |  | ¡ d¡ | t¡ |  | ¡ t¡ |  | d¡d
¡ | t d d¡ |  | d¡d¡ |  | ¡ d¡ W d Q R X d S )Nr!   r   r   r   é*   éT   r    iöÿÿÿé
   r	   )r   r   r   r$   r#   r   r   )r   r   r   r   r   Útest_seek_read<   s8    


zLargeFileTest.test_seek_readc          	   C   s  |   td¡þ}|  t | ¡ dd¡d¡ |  t | ¡ dd¡d¡ |  t | ¡ dd¡d¡ |  t | ¡ dd¡d¡ |  t | ¡ dd¡td d ¡ |  t | ¡ dd¡td d ¡ |  t | ¡ t d d¡d¡ |  t | ¡ td¡t¡ |  | d¡d	¡ W d Q R X d S )
Nr!   r   r'   r   r(   r    iöÿÿÿr)   r	   )r   r   r   r
   Úlseekr   r   r#   )r   r   r   r   r   Ú
test_lseek[   s    "" zLargeFileTest.test_lseekc          	   C   s"  |   td¡
}t|dƒs$t d¡‚| dd¡ |  | ¡ td ¡ td }| |¡ | 	¡  |  | ¡ |¡ | dd¡ |  | ¡ |¡ |d8 }| d¡ | 	|¡ |  | ¡ d¡ | dd¡ |  | ¡ |¡ | d¡ | 	d¡ |  | ¡ d¡ | d¡ |  t
| ¡ ƒd¡ W d Q R X d S )	Nzr+bÚtruncatez.open().truncate() not available on this systemr   r    r   r)   r'   )r   r   ÚhasattrÚunittestÚSkipTestr   r   r$   r   r-   r"   r#   )r   r   Znewsizer   r   r   Útest_truncateh   s,    







zLargeFileTest.test_truncatec          
   C   sB   x<dD ]4}|   td¡}| |¡ |  | ¡ ¡ W d Q R X qW d S )N)iÿÿÿl        l       r!   )r   r   r   Z
assertTrueÚseekable)r   Úposr   r   r   r   Útest_seekable‡   s    

zLargeFileTest.test_seekableN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr   r   r   r%   r&   r*   r,   r1   r4   r   r   r   r   r      s   
r   c           	   C   sÔ   ydd l } |   | j| j¡ W n ttfk
r4   Y nX tjd d… dksRtjdkrftddtt	ƒ ƒ njt
tddd}zHy | d	¡ | d
¡ | ¡  W n" ttfk
r¸   t d¡‚Y nX W d | ¡  ttƒ X d S )Nr   é   ÚwinÚdarwinZ	largefilez-test requires %s bytes and a long time to runr   )Ú	bufferingl       ó   xz*filesystem does not have largefile support)ÚsignalÚSIGXFSZÚSIG_IGNÚImportErrorÚAttributeErrorÚsysÚplatformr   Ústrr   r   r   r   r   r   ÚOSErrorÚOverflowErrorr/   r0   Úcloser   )r?   r   r   r   r   ÚsetUpModule   s"    

rJ   c               @   s   e Zd ZeejƒZdS )ÚCLargeFileTestN)r5   r6   r7   ÚstaticmethodÚior   r   r   r   r   rK   ³   s   rK   c               @   s   e Zd ZeejƒZdS )ÚPyLargeFileTestN)r5   r6   r7   rL   Úpyior   r   r   r   r   rN   ¶   s   rN   c               C   s   t tƒ d S )N)r   r   r   r   r   r   ÚtearDownModule¹   s    rP   Ú__main__)r8   r
   r   rD   r/   Ztest.supportr   r   r   r   rM   Z_pyiorO   r   r   rJ   ZTestCaserK   rN   rP   r5   Úmainr   r   r   r   Ú<module>   s     $