3
®yb©  ã               @   s¤   d dl mZ d dlZd dlZd dlZd dlmZmZm	Z	 d dl
jZd dlmZ ejdƒdd„ ƒZejdƒdd	„ ƒZejd
ƒejdƒdd„ ƒƒZejdƒdd„ ƒZdS )é    )ÚBytesION)Ú	DataFrameÚ
date_rangeÚread_csv)Ú_test_decoratorsZgcsfsc                s€   ddl m}m} |jjƒ  tddgdtjgddgtdd	d
�dœƒ‰ G ‡ fdd„d|ƒ}| j	d|ƒ t
ddgd�}tjˆ |ƒ d S )Nr   )ÚAbstractFileSystemÚregistryé   é   g       @ÚtÚsz
2018-06-18é   )Úperiods)ÚintÚfloatÚstrÚdtc                   s   e Zd Z‡ fdd„ZdS )z,test_read_csv_gcs.<locals>.MockGCSFileSystemc                 s   t ˆ jdd�jƒ ƒS )NF)Úindex)r   Úto_csvÚencode)ÚargsÚkwargs)Údf1© ú</tmp/pip-install-4cy230dp/pandas/pandas/tests/io/test_gcs.pyÚopen   s    z1test_read_csv_gcs.<locals>.MockGCSFileSystem.openN)Ú__name__Ú
__module__Ú__qualname__r   r   )r   r   r   ÚMockGCSFileSystem   s   r   zgcsfs.GCSFileSystemzgs://test/test.csvr   )Úparse_dates)Úfsspecr   r   ÚtargetÚclearr   ÚnpÚnanr   Úsetattrr   ÚtmÚassert_frame_equal)Úmonkeypatchr   r   r   Údf2r   )r   r   Útest_read_csv_gcs   s    
r+   c                s¸   ddl m}m} |jjƒ  tddgdtjgddgtdd	d
�dœƒ‰ t	ƒ ‰dd„ ˆ_
G ‡fdd„d|ƒ}| jd|ƒ ˆ jddd� ‡ fdd„}| jd|ƒ tddgdd�}tjˆ |ƒ d S )Nr   )r   r   r	   r
   g       @r   r   z
2018-06-18r   )r   )r   r   r   r   c               S   s   dS )NTr   r   r   r   r   Ú<lambda>3   s    z!test_to_csv_gcs.<locals>.<lambda>c                   s   e Zd Z‡ fdd„ZdS )z*test_to_csv_gcs.<locals>.MockGCSFileSystemc                 s   ˆ j dƒ ˆ S )Nr   )Úseek)r   r   )r   r   r   r   6   s    
z/test_to_csv_gcs.<locals>.MockGCSFileSystem.openN)r   r   r   r   r   )r   r   r   r   5   s   r   zgcsfs.GCSFileSystemzgs://test/test.csvT)r   c                 s   t ˆ jdd�jƒ ƒd d dfS )NT)r   F)r   r   r   )r   r   )r   r   r   Úmock_get_filepath_or_buffer=   s    z4test_to_csv_gcs.<locals>.mock_get_filepath_or_bufferz'pandas.io.common.get_filepath_or_bufferr   )r    Z	index_col)r!   r   r   r"   r#   r   r$   r%   r   r   Úcloser&   r   r   r'   r(   )r)   r   r   r   r.   r*   r   )r   r   r   Útest_to_csv_gcs%   s"    

r0   Úfastparquetc                sx   ddl m}m} |jjƒ  tddgdtjgddgtdd	d
�dœƒ}G ‡ fdd„d|ƒ}| j	d|ƒ |j
ddddd� dS )zCRegression test for writing to a not-yet-existent GCS Parquet file.r   )r   r   r	   r
   g       @r   r   z
2018-06-18r   )r   )r   r   r   r   c                   s   e Zd Zd‡ fdd„	ZdS )z7test_to_parquet_gcs_new_file.<locals>.MockGCSFileSystemÚrc                s    d|krt ‚ttjjˆ dƒ|ƒS )NÚwztest.parquet)ÚFileNotFoundErrorr   ÚosÚpathÚjoin)Úselfr6   Úmoder   )Útmpdirr   r   r   Z   s    z<test_to_parquet_gcs_new_file.<locals>.MockGCSFileSystem.openN)r2   )r   r   r   r   r   )r:   r   r   r   Y   s   r   zgcsfs.GCSFileSystemzgs://test/test.csvTr1   N)r   ZengineÚcompression)r!   r   r   r"   r#   r   r$   r%   r   r&   Z
to_parquet)r)   r:   r   r   r   r   r   )r:   r   Útest_to_parquet_gcs_new_fileI   s    
r<   c           
   C   s4   t jtƒ� } tdƒ dt| jƒks&t‚W d Q R X d S )Nzgs://test/test.csvzgcsfs library is required)ÚpytestZraisesÚImportErrorr   r   ÚvalueÚAssertionError)Úer   r   r   Útest_gcs_not_present_exceptione   s    rB   )Úior   r5   Znumpyr$   r=   Zpandasr   r   r   Zpandas._testingZ_testingr'   Zpandas.utilr   ÚtdZ
skip_if_nor+   r0   r<   Zskip_if_installedrB   r   r   r   r   Ú<module>   s   
$