B
    Y0d                 @   s   d dl Z d dlZ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
 ejdd Zejdd Zejdd Zejd	d
 Zejdd Zejdddd Ze dd ZdS )    N)read_csvc             C   s   | ddddS )zPath to the tips datasetiodatacsvztips.csv )datapathr   r   J/var/www/html/venv/lib/python3.7/site-packages/pandas/tests/io/conftest.py	tips_file   s    r	   c             C   s   | ddddS )zPath to a JSONL datasetr   parserr   zitems.jsonlr   )r   r   r   r   
jsonl_file   s    r   c             C   s   t | ddddddS )z#DataFrame with the salaries datasetr   r
   r   zsalaries.csv	)sep)r   )r   r   r   r   salaries_table   s    r   c             C   s   | ddddS )Nr   r   Zfeatherzfeather-0_3_1.featherr   )r   r   r   r   feather_file    s    r   c             C   s*   | dkrdn|  d} ddd|  diiS )Nmaster5gwclient_kwargsendpoint_urlzhttp://127.0.0.1:555/)lstrip)	worker_idr   r   r   s3so%   s    r   session)scopec          	   c   s*  t d t d t d}dtd_t  tj	dd tj	dd t jd	d
d t d | dkrtdn| 
d} d|  }d| d}tjtd| tjtjd}d}xL|dkry||}|jrP W n tk
r   Y nX |d8 }td qW |V  |  |  W dQ R X dS )zZ
    Fixture for mocking S3 interaction.

    Sets up moto server in separate process
    s3fsboto3requestsTZAWS_ACCESS_KEY_IDZ
foobar_keyZAWS_SECRET_ACCESS_KEYZfoobar_secretZmotoz1.3.14)Z
minversionZflaskr   r   r   Z555zhttp://127.0.0.1:r   zmoto_server s3 -p )stdoutstderr   r   g?N)pytestZimportorskiplogging	getLoggerdisabledtmZ!ensure_safe_environment_variablesosenviron
setdefaultr   
subprocessPopenshlexsplitDEVNULLgetok	Exceptiontimesleep	terminatewait)r   r   Zendpoint_portZendpoint_uriproctimeoutrr   r   r   s3_base+   s:    







r8   c             #   s  ddl }ddl}d|fd|fd|d fd|d fd	|fd
|fg fdd}d}|jd| d}|jd| d y j|d W n   Y nX y jddd W n   Y nX d}	x*  d s|	dkrtd |	d8 }	qW || |d |j	  |V  |jd| id}
y|
j
|dd W n   Y nX y|
j
ddd W n   Y nX d}	x0  d r|	dkrtd |	d8 }	qRW dS )a0  
    Sets up S3 bucket with contents

    The primary bucket name is "pandas-test". The following datasets
    are loaded.

    - tips.csv
    - tips.csv.gz
    - tips.csv.bz2
    - items.jsonl

    A private bucket "cant_get_it" is also created. The boto3 s3 resource
    is yielded by the fixture.
    r   Nz
tips#1.csvztips.csvztips.csv.gzz.gzztips.csv.bz2z.bz2zitems.jsonlzsimple_dataset.featherc          
      s<   x6D ].\}}t |d} j| ||d W d Q R X qW d S )Nrb)BucketKeyZBody)openZ
put_object)Zbucket_nameZs3_key	file_namef)clitest_s3_filesr   r   add_tips_files{   s    z#s3_resource.<locals>.add_tips_fileszpandas-tests3)r   )r:   Zcant_get_itprivate)r:   ZACL   ZBucketsg?r   )r   T)	recursive)r   r   resourceclientZcreate_bucketZlist_bucketsr1   r2   ZS3FileSystemZclear_instance_cacheZrm)r8   r	   r   r   r   r   rA   Zbucketconnr6   rB   r   )r?   r@   r   s3_resource_   sR    





rI   )r"   r&   r+   r)   r1   r!   Zpandas._testingZ_testingr%   Zpandas.io.parsersr   Zfixturer	   r   r   r   r   r8   rI   r   r   r   r   <module>   s   4