o
    z@a                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm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mZ d
dlmZ esZddlZddlmZ ddlmZ ddlZeG dd de	jZdS )zUnit tests for misc module.    )absolute_import)division)print_function)unicode_literals)	timedeltaN)raises)skip_if_pypy
using_pypy   )_mocked_session)assert_frame_equal)DataFrameClientc                   @   s  e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zeddd  Zd!d" Zd#d$ Zeed%d& Zeed'd( Zd)d* Zd+d, Zeed-d. Zd/d0 Zd1d2 Z d3d4 Z!eed5d6 Z"d7d8 Z#d9d: Z$d;d< Z%d=d> Z&eed?d@ Z'dAdB Z(eedCdD Z)dEdF Z*dGdH Z+dIdJ Z,dKdL Z-dMdN Z.dOdP Z/dQdR Z0dSdT Z1dUdV Z2dWdX Z3dYdZ Z4d[d\ Z5d]S )^TestDataFrameClientz%Set up a test DataFrameClient object.c                 C   s   t dt dS )z)Instantiate a TestDataFrameClient object.errorN)warningssimplefilterFutureWarning)self r   F/usr/lib/python3/dist-packages/influxdb/tests/dataframe_client_test.pysetUp    s   zTestDataFrameClient.setUpc                 C      t d}t jg dg dg||tdd gg dd}d}t 5}|jtjd	d
d tdd}|	|d | 
|jj| |j	|ddd | 
|jj| W d   dS 1 sZw   Y  dS )8Test write points from df in TestDataFrameClient object.1970-01-01 00:00+00:001r
         ?2          @r
   Zhours
column_one
column_twocolumn_threedataindexcolumnst   foo column_one="1",column_two=1i,column_three=1.0 0
foo column_one="2",column_two=2i,column_three=2.0 3600000000000
http://localhost:8086/write   Zstatus_codedbdatabasefooNtagspd	Timestamp	DataFramer   requests_mockMockerregister_uriPOSTr   write_pointsassertEquallast_requestbodyr   now	dataframeexpectedmclir   r   r    test_write_points_from_dataframe%   $   


"z4TestDataFrameClient.test_write_points_from_dataframec                 C      t d}t jg dg dg||tdd gg dd}d}t %}|jtjd	d
d tdd}|	|d | 
|jj| W d   dS 1 sJw   Y  dS )z7write_points should escape white space in measurements.r   r   r   r
   r!   r"   r&   s   meas\ with\ space column_one="1",column_two=1i,column_three=1.0 0
meas\ with\ space column_one="2",column_two=2i,column_three=2.0 3600000000000
r+   r,   r-   r.   r/   zmeas with spaceNr4   r@   r   r   r   7test_dataframe_write_points_with_whitespace_measurement?   s    


"zKTestDataFrameClient.test_dataframe_write_points_with_whitespace_measurementc                 C   rH   )z7write_points should escape white space in column names.r   r   r   r
   r!   )z
column onez
column twozcolumn threer&   sz   foo column\ one="1",column\ two=1i,column\ three=1.0 0
foo column\ one="2",column\ two=2i,column\ three=2.0 3600000000000
r+   r,   r-   r.   r/   r1   Nr4   r@   r   r   r   ;test_dataframe_write_points_with_whitespace_in_column_namesU   s    


"zOTestDataFrameClient.test_dataframe_write_points_with_whitespace_in_column_namesc                 C   r   )r   r   )r   Nr   r   r    r    r
   r!   r"   r&   sg   foo column_one="1",column_three=1.0 0
foo column_one="2",column_two=2.0,column_three=2.0 3600000000000
r+   r,   r-   r.   r/   r1   Nr2   r4   r@   r   r   r   *test_write_points_from_dataframe_with_nonei   rG   z>TestDataFrameClient.test_write_points_from_dataframe_with_nonec                 C   r   )r   r   NNNrK   r
   r!   r"   r&   sA   foo column_one="2",column_two=2.0,column_three=2.0 3600000000000
r+   r,   r-   r.   r/   r1   Nr2   r4   r@   r   r   r   2test_write_points_from_dataframe_with_line_of_none   s$   


"zFTestDataFrameClient.test_write_points_from_dataframe_with_line_of_nonec                 C   s   t d}t jg dg dg||tdd gg dd}d}t 5}|jtjdd	d
 tdd}|	|d | 
|jj| |j	|ddd | 
|jj| W d   dS 1 sZw   Y  dS )r   r   rM   r
   r!   r"   r&      
r+   r,   r-   r.   r/   r1   Nr2   r4   r@   r   r   r   .test_write_points_from_dataframe_with_all_none   s$   


"zBTestDataFrameClient.test_write_points_from_dataframe_with_all_nonec                 C   s   t d}t jg dg dg||tdd gg dd}t "}|jtjdd	d
 tdd}| 	|j
|ddd W d   dS 1 sEw   Y  dS )zATest write points in batch from df in TestDataFrameClient object.r   r   r   r
   r!   r"   r&   r+   r,   r-   r.   r/   r1   )Z
batch_sizeN)r5   r6   r7   r   r8   r9   r:   r;   r   Z
assertTruer<   r   rA   rB   rD   rE   r   r   r   +test_write_points_from_dataframe_in_batches   s   


"z?TestDataFrameClient.test_write_points_from_dataframe_in_batchesc                 C   s   t d}t jg dg dg||tdd gg dd}d}t <}|jtjd	d
d tdd}|j	|dddgd | 
|jj| |j	|dddgdd | 
|jj| W d   dS 1 saw   Y  dS )z>Test write points from df w/tag in TestDataFrameClient object.r   bluer
   r   r
   r   redr   r   r   r    r
   r!   tag_onetag_twor#   r$   r%   r&   s   foo,tag_one=blue,tag_two=1 column_one="1",column_two=1i,column_three=1.0 0
foo,tag_one=red,tag_two=0 column_one="2",column_two=2i,column_three=2.0 3600000000000
r+   r,   r-   r.   r/   r1   rX   rY   tag_columnsNr[   r3   r4   r@   r   r   r   1test_write_points_from_dataframe_with_tag_columns   s0   


	
"zETestDataFrameClient.test_write_points_from_dataframe_with_tag_columnsc                 C   s   t d}t jg dg dg||tdd gg dd}d}t ,}|jtjd	d
d tdd}|j	|dddgddid | 
|jj| W d   dS 1 sQw   Y  dS )z>Test write points from df w/tag + cols in TestDataFrameClient.r   rS   rU   r
   r!   rW   r&   s   foo,global_tag=value,tag_one=blue,tag_two=1 column_one="1",column_two=1i,column_three=1.0 0
foo,global_tag=value,tag_one=red,tag_two=0 column_one="2",column_two=2i,column_three=2.0 3600000000000
r+   r,   r-   r.   r/   r1   rX   rY   Z
global_tagvaluer\   Nr4   r@   r   r   r   >test_write_points_from_dataframe_with_tag_cols_and_global_tags   s*   


	
"zRTestDataFrameClient.test_write_points_from_dataframe_with_tag_cols_and_global_tagsc           	      C   s  t d}t jg dg dg||tdd gg dd}d}d	}d
}d}t ]}|jtjddd tdd}|j	|dddgdgd | 
|jj| |j	|dddgd | 
|jj| |j	|dg dd | 
|jj| |	|d | 
|jj| W d   dS 1 sw   Y  dS )z?Test default write points from df w/tag in TestDataFrameClient.r   )rT   r
   r   r
   r   Zhot)rV   r   r   r   r    Zcoldr
   r!   )rX   rY   r#   r$   r%   	tag_threer&   sk   foo,tag_one=blue column_one="1",column_two=1i 0
foo,tag_one=red column_one="2",column_two=2i 3600000000000
s   foo,tag_one=blue,tag_two=1 column_one="1",column_two=1i,column_three=1.0,tag_three="hot" 0
foo,tag_one=red,tag_two=0 column_one="2",column_two=2i,column_three=2.0,tag_three="cold" 3600000000000
s   foo,tag_one=blue,tag_three=hot,tag_two=1 column_one="1",column_two=1i,column_three=1.0 0
foo,tag_one=red,tag_three=cold,tag_two=0 column_one="2",column_two=2i,column_three=2.0 3600000000000
s   foo tag_one="blue",tag_two=1i,column_one="1",column_two=1i,column_three=1.0,tag_three="hot" 0
foo tag_one="red",tag_two=0i,column_one="2",column_two=2i,column_three=2.0,tag_three="cold" 3600000000000
r+   r,   r-   r.   r/   r1   r#   r$   rX   field_columnsr[   rY   rZ   r"   )rb   Nr4   )	r   rA   rB   Zexpected_tags_and_fieldsZexpected_tags_no_fieldsZexpected_fields_no_tagsZexpected_no_tags_no_fieldsrD   rE   r   r   r   ;test_write_points_from_dataframe_with_tag_cols_and_defaults   sJ   






"zOTestDataFrameClient.test_write_points_from_dataframe_with_tag_cols_and_defaultsc                 C   s   t d}t jg dg dg dg dg dgt j|ddd	g d
d}d}t ,}|jtjddd tdd}|j	|dddgddgd | 
|jj| W d   dS 1 sYw   Y  dS )z?Test write points from df w/escaped tag in TestDataFrameClient.r   )zblue oranger   r
   zhot=cold)z	red,greenr   r   z	cold\fire)somer   r    )rd   r   r   N)re   r   r   NH   )freqperiods)rX   r#   r$   r`   r&   sL  foo,tag_one=blue\ orange,tag_three=hot\=cold column_one="1",column_two=1i 0
foo,tag_one=red\,green,tag_three=cold\\fire column_one="2",column_two=2i 3600000000000
foo,tag_one=some column_one="2",column_two=2i 7200000000000
foo,tag_one=some column_one="2",column_two=2i 10800000000000
foo column_one="2",column_two=2i 14400000000000
r+   r,   r-   r.   r/   r1   r#   r$   rX   r`   ra   N)r5   r6   r7   Zperiod_ranger8   r9   r:   r;   r   r<   r=   r>   r?   )r   rA   rB   Zexpected_escaped_tagsrD   rE   r   r   r   1test_write_points_from_dataframe_with_tag_escapedG  s2   


"zETestDataFrameClient.test_write_points_from_dataframe_with_tag_escapedc                 C   s   t d}t jg dg dg||tdd gd}d}t (}|jtjdd	d
 tdd}|	|dddi | 
|jj| W d   dS 1 sJw   Y  dS )z,Test write points from df with numeric cols.r   r   r   r
   r!   r'   r(   sR   foo,hello=there 0="1",1=1i,2=1.0 0
foo,hello=there 0="2",1=2i,2=2.0 3600000000000
r+   r,   r-   r.   r/   r1   hellothereNr4   r@   r   r   r   :test_write_points_from_dataframe_with_numeric_column_namesr  s   


"zNTestDataFrameClient.test_write_points_from_dataframe_with_numeric_column_namesc              
   C   s   t jtg dg dg dg dg dg dg ddt jt d	d
ddd}d}t 4}|jtjddd t	dd}g d}|j
|jdd|f dg dd | |jj| W d   dS 1 sdw   Y  dS )zAwrite_points detect erroneous leading comma for null first field.)r
   NN   	   )r   NNN
   )   gffffff@NN   )ZoneNNZeightN)ZtwoNNNN)ZthreeZfourNNN)zAll columns filledzFirst two of three emptyz	All emptyzLast two of three emptyzEmpty tags with values)firstsecondthird	first_tag
second_tag	third_tagcommentz
2018-01-01Z1Drg   )startrh   ri   )r(   s  foo,first_tag=one,second_tag=two,third_tag=three comment="All columns filled",first=1.0,second=2.0,third=3.0 1514764800000000000
foo,third_tag=four comment="First two of three empty",third=4.1 1514851200000000000
foo comment="All empty" 1514937600000000000
foo,first_tag=eight comment="Last two of three empty",first=8.0 1515024000000000000
foo comment="Empty tags with values",first=9.0,second=10.0,third=11.0 1515110400000000000
r+   r,   r-   r.   r/   )rw   rx   ry   rz   rt   ru   rv   Nr1   )rw   rx   ry   rZ   )r5   r7   dictZ
date_rangeto_datetimer8   r9   r:   r;   r   r<   locr=   r>   r?   )r   rB   rC   rD   rE   Zcolnamesr   r   r   9test_write_points_from_dataframe_with_leading_none_column  s<   

	"zMTestDataFrameClient.test_write_points_from_dataframe_with_leading_none_columnzSee #902470c                 C   s6  t d}t jg dg dg||tdd gd}tjtjdkr%d}nd	}d
}d	}t	 b}|j
tjddd tdd}||dddi t| t|jj | |jj| tdd}|j|dddidd | |jj| tdd}|j|dddidd | |jj| W d   dS 1 sw   Y  dS )z1Test write points from df with numeric precision.r   )r   r
   g@q?)r   r   g@q@r
   r!   rk   z1.13.3sf   foo,hello=there 0="1",1=1i,2=1.11111111111 0
foo,hello=there 0="2",1=2i,2=2.22222222222 3600000000000
sj   foo,hello=there 0="1",1=1i,2=1.1111111111111 0
foo,hello=there 0="2",1=2i,2=2.2222222222222 3600000000000
sX   foo,hello=there 0="1",1=1i,2=1.1111 0
foo,hello=there 0="2",1=2i,2=2.2222 3600000000000
r+   r,   r-   r.   r/   r1   rl   rm      )Znumeric_precisionZfullN)r5   r6   r7   r   nplibZNumpyVersion__version__r8   r9   r:   r;   r   r<   printr>   r?   r=   )r   rA   rB   Zexpected_default_precisionZexpected_specified_precisionZexpected_full_precisionrD   rE   r   r   r   7test_write_points_from_dataframe_with_numeric_precision  sH   





"zKTestDataFrameClient.test_write_points_from_dataframe_with_numeric_precisionc                 C   s   t jg dg dgt dt dgg dd}d}t %}|jtjdd	d
 tdd}||d | 	|j
j| W d   dS 1 sFw   Y  dS )z,Test write points from df with period index.r   r   z
1970-01-01z
1970-01-02r"   r&   su   foo column_one="1",column_two=1i,column_three=1.0 0
foo column_one="2",column_two=2i,column_three=2.0 86400000000000
r+   r,   r-   r.   r/   r1   N)r5   r7   ZPeriodr8   r9   r:   r;   r   r<   r=   r>   r?   )r   rB   rC   rD   rE   r   r   r   2test_write_points_from_dataframe_with_period_index   s"   

"zFTestDataFrameClient.test_write_points_from_dataframe_with_period_indexc                 C   s  t d}t jg dg dg||tdd gg dd}t }|jtjdd	d
 tdd}d}|j	||dd | 
|jjd dg | 
d|jj |j	||dd | 
|jjd dg | 
d|jj |j	||dd | 
|jjd dg | 
d|jj |j	||dd | 
|jjd dg | 
d|jj |j	||dd | 
|jjd dg | 
d|jj |j	||dd | 
|jjd dg | 
d|jj W d   dS 1 sw   Y  dS )z.Test write points from df with time precision.r   r   r   r
   r!   r"   r&   r+   r,   r-   r.   r/   r1   hZtime_precisionZ	precisionsh   foo column_one="1",column_two=1i,column_three=1.0 0
foo column_one="2",column_two=2i,column_three=2.0 1
rD   si   foo column_one="1",column_two=1i,column_three=1.0 0
foo column_one="2",column_two=2i,column_three=2.0 60
ssk   foo column_one="1",column_two=1i,column_three=1.0 0
foo column_one="2",column_two=2i,column_three=2.0 3600
mssn   foo column_one="1",column_two=1i,column_three=1.0 0
foo column_one="2",column_two=2i,column_three=2.0 3600000
usq   foo column_one="1",column_two=1i,column_three=1.0 0
foo column_one="2",column_two=2i,column_three=2.0 3600000000
nr*   N)r5   r6   r7   r   r8   r9   r:   r;   r   r<   r=   r>   qsr?   )r   rA   rB   rD   rE   measurementr   r   r   4test_write_points_from_dataframe_with_time_precision  sb   


"zHTestDataFrameClient.test_write_points_from_dataframe_with_time_precisionc                 C   st   t jg dg dgg dd}t }|jtjddd tdd	}||d
 W d   dS 1 s3w   Y  dS )z4Test failed write points from df without time index.r   r   r"   )r'   r)   "http://localhost:8086/db/db/seriesr,   r-   r.   r/   r1   N)r5   r7   r8   r9   r:   r;   r   r<   )r   rB   rD   rE   r   r   r   9test_write_points_from_dataframe_fails_without_time_indexY  s   

"zMTestDataFrameClient.test_write_points_from_dataframe_fails_without_time_indexc                 C   s   t d}t jddg||tdd gd}t }|jtjddd	 td
d}|	|d W d   dS 1 s9w   Y  dS )z-Test failed write points from df with series.r   r   r    r
   r!   rk   r   r,   r-   r.   r/   r1   N)
r5   r6   ZSeriesr   r8   r9   r:   r;   r   r<   rQ   r   r   r   2test_write_points_from_dataframe_fails_with_seriesh  s   



"zFTestDataFrameClient.test_write_points_from_dataframe_fails_with_seriesc                 C   l   t dd}t #}|jtjddd |d | |jjd d d	 W d
   d
S 1 s/w   Y  d
S )z3Test create database for TestInfluxDBClient object.r.   r/   http://localhost:8086/query{"results":[{}]}textnew_dbqr   zcreate database "new_db"N	r   r8   r9   r:   r;   create_databaser=   r>   r   r   rE   rD   r   r   r   test_create_databasew     


"z(TestDataFrameClient.test_create_databasec                 C   r   )z<Test create db w/numeric name for TestInfluxDBClient object.r.   r/   r   r   r   123r   r   zcreate database "123"Nr   r   r   r   r   "test_create_numeric_named_database  r   z6TestDataFrameClient.test_create_numeric_named_databasec                 C   sF   t dd}t|dd |d W d   dS 1 sw   Y  dS )z8Test create database fail for TestInfluxDBClient object.r.   r/   Zpost  r   N)r   r   r   r   rE   r   r   r   test_create_database_fails  s   
"z.TestDataFrameClient.test_create_database_failsc                 C   r   )z1Test drop database for TestInfluxDBClient object.r.   r/   r   r   r   r   r   r   zdrop database "new_db"N	r   r8   r9   r:   r;   Zdrop_databaser=   r>   r   r   r   r   r   test_drop_database  r   z&TestDataFrameClient.test_drop_databasec                 C   r   )z4Test drop measurement for TestInfluxDBClient object.r.   r/   r   r   r   Znew_measurementr   r   z"drop measurement "new_measurement"N)	r   r8   r9   r:   r;   Zdrop_measurementr=   r>   r   r   r   r   r   test_drop_measurement  r   z)TestDataFrameClient.test_drop_measurementc                 C   r   )z3Test drop numeric db for TestInfluxDBClient object.r.   r/   r   r   r   r   r   r   zdrop database "123"Nr   r   r   r   r    test_drop_numeric_named_database  r   z4TestDataFrameClient.test_drop_numeric_named_databasec                 C   sH   t dddd}t|dd |  W d   dS 1 sw   Y  dS )z8Test get list of dbs fail for TestInfluxDBClient object.host  usernamepasswordgetr   N)r   r   get_list_databaser   r   r   r   test_get_list_database_fails  s   
"z0TestDataFrameClient.test_get_list_database_failsc                 C   s   t dd}ddddgdgdggd	gigi}t|d
dt| | | ddiddig W d   dS 1 s:w   Y  dS )z<Test get list of measurements for TestInfluxDBClient object.r.   r/   resultsseriesZmeasurementsnameZcpuZdiskr   r)   valuesr      N)r   r   jsondumpsassertListEqualZget_list_measurements)r   rE   r'   r   r   r   test_get_list_measurements  s    


"z.TestDataFrameClient.test_get_list_measurementsc                 C   sz   t dd}d}t (}|jtjd|d |jdddd	dd
 | |jjd d d W d   dS 1 s6w   Y  dS )z=Test create default ret policy for TestInfluxDBClient object.r.   r/   r   r   r   somename1dr   T)defaultr0   r   r   z^create retention policy "somename" on "db" duration 1d replication 4 shard duration 0s defaultN	r   r8   r9   r:   r;   Zcreate_retention_policyr=   r>   r   r   rE   Zexample_responserD   r   r   r   $test_create_retention_policy_default  s    


"z8TestDataFrameClient.test_create_retention_policy_defaultc                 C   sx   t dd}d}t '}|jtjd|d |jddddd | |jjd	 d
 d W d   dS 1 s5w   Y  dS )z;Test create retention policy for TestInfluxDBClient object.r.   r/   r   r   r   r   r   r   r   r   zVcreate retention policy "somename" on "db" duration 1d replication 4 shard duration 0sNr   r   r   r   r   test_create_retention_policy  s    

"z0TestDataFrameClient.test_create_retention_policyc                 C   s   t dd}d}t b}|jtjd|d |jdddd | |jjd	 d
 d |jdddd | |jjd	 d
 d |jdddd | |jjd	 d
 d |jdddd | |jjd	 d
 d W d   dS 1 spw   Y  dS )z:Test alter retention policy for TestInfluxDBClient object.r.   r/   r   r   r   r   Z4d)durationr   r   z5alter retention policy "somename" on "db" duration 4dr   )Zreplicationz7alter retention policy "somename" on "db" replication 4Z1h)Zshard_durationz;alter retention policy "somename" on "db" shard duration 1hT)r   z1alter retention policy "somename" on "db" defaultN)	r   r8   r9   r:   r;   alter_retention_policyr=   r>   r   r   r   r   r   test_alter_retention_policy  sJ   

"z/TestDataFrameClient.test_alter_retention_policyc                 C   L   t dddd}t|dd |dd W d	   d	S 1 sw   Y  d	S )
z<Test invalid alter ret policy for TestInfluxDBClient object.r   r   r   r   r   i  r   r.   N)r   r   r   r   r   r   r   #test_alter_retention_policy_invalid7     "z7TestDataFrameClient.test_alter_retention_policy_invalidc                 C   sr   t dd}d}t $}|jtjd|d |dd | |jjd d d	 W d
   d
S 1 s2w   Y  d
S )z9Test drop retention policy for TestInfluxDBClient object.r.   r/   r   r   r   r   r   r   z(drop retention policy "somename" on "db"N)	r   r8   r9   r:   r;   drop_retention_policyr=   r>   r   r   r   r   r   test_drop_retention_policy>  s   

"z.TestDataFrameClient.test_drop_retention_policyc                 C   r   )
z:Test failed drop ret policy for TestInfluxDBClient object.r   r   r   r   deleter   r   r.   N)r   r   r   r   r   r   r    test_drop_retention_policy_failsO  r   z4TestDataFrameClient.test_drop_retention_policy_failsc                 C   sj   t dd}d}t  }|jtjd|d | |ddddd	g W d
   d
S 1 s.w   Y  d
S )z:Test get retention policies for TestInfluxDBClient object.r.   r/   zq{"results": [{"series": [{"values": [["fsfdsdf", "24h0m0s", 2]], "columns": ["name", "duration", "replicaN"]}]}]}r   r   Z24h0m0sZfsfdsdfr   )r   r   ZreplicaNN)r   r8   r9   r:   GETr   Zget_list_retention_policiesr   r   r   r    test_get_list_retention_policiesV  s    

"z4TestDataFrameClient.test_get_list_retention_policiesc              
   C   s<  dddddiddgdd	ggd
dddiddgdd	gdd	gdd	ggd
gigi}t jd	ggdgt dgd}|jjdu rC|jd|_t jd	gd	gd	ggdgt g dd}|jjdu rd|jd|_||d}tddddd}t|dd| |d}|D ]}t	|| ||  qW d   dS 1 sw   Y  dS )z2Test query into df for TestDataFrameClient object.r   r   network	directionre   timer^   2009-11-10T23:00:00Z~[  )r   r3   r)   r   inr)   r(   NUTC)r   r   r   ))r   ))r   re   )r   ))r   r   r   r   r   r   r.   r   r   z-select value from network group by direction;)
r5   r7   r}   r(   tzinfotz_localizer   r   queryr   )r   r'   pd1pd2rC   rE   resultkr   r   r   test_query_into_dataframei  sP   


"z-TestDataFrameClient.test_query_into_dataframec                 C   s`  dddddgddgddgd	d
ggdgiddddgddggdgigi}t jdgdgd
ggdgt g dd}|jjdu rE|jd|_t jdggdgt dgd}|jjdu ra|jd|_d|id|ig}tddddd}d}ddi}t|dd|( |j||d}t	||D ]\}	}
|
D ]}t
|
| |	|  qqW d   dS 1 sw   Y  dS ) 7Test multiquery into df for TestDataFrameClient object.r   r   cpu_load_shortr   r^   2015-01-29T21:55:43.702900257Z皙?r   2015-06-11T20:46:02Z{Gz?r   count1970-01-01T00:00:00Zrr       @"2015-01-29 21:55:43.702900257+0000r   z2015-06-11 20:46:02+0000r   Nr   1970-01-01 00:00:00+00:00r   r   r   r   r.   rSELECT value FROM cpu_load_short WHERE region=$region;SELECT count(value) FROM cpu_load_short WHERE region=$regionregionus-westr   r   bind_params)r5   r7   r}   r(   r   r   r   r   r   zipr   )r   r'   r   r   rC   rE   iqlr   r   rer   r   r   r   test_multiquery_into_dataframe  sZ   

"z2TestDataFrameClient.test_multiquery_into_dataframec              
   C   sj  dddg ddddt jgddd	t jgd
ddt jggdgiddddgddggdgigi}tjddt jgdd	t jgddt jggg dtg dd}|jjdu rX|jd|_tjddgdd	gddggddgtg dd}|jjdu r}|jd|_tjdggdgtdgd}|jjdu r|jd|_d|id|ig}d|id|ig}tddddd}d }d!d"i}	d#D ]?}
t	|d$d%|. |j
||	|
d&}|
r|n|}t||D ]\}}|D ]}t|| ||  qqW d   n1 sw   Y  qt	|d$d%|* |j
||	d'}t||D ]\}}|D ]}t|| ||  qqW d   dS 1 s.w   Y  dS )(r   r   r   r   )r   r^   value2value3r   r   gK7A?r   i r   r   gOec?r   r   r   r   rr   r   )r^   r   r   r   r   Nr   r^   r   r   r   r   r   r   r.   r   r   r   )TFr   r   )r   dropnar   )r   ZNaNr5   r7   r}   r(   r   r   r   r   r   r   r   )r   r'   r   Z
pd1_dropnar   Zexpected_dropna_trueZexpected_dropna_falserE   r   r   r   r   rC   r   r   r   r   r   r   %test_multiquery_into_dataframe_dropna  s   






	$z9TestDataFrameClient.test_multiquery_into_dataframe_dropnac                 C   s`   t ddddd}t|dddi gi |d	}| |i  W d
   d
S 1 s)w   Y  d
S )z<Test query with empty results in TestDataFrameClient object.r   r   r   r   r.   r   r   r   zselect column_one from foo;N)r   r   r   r=   )r   rE   r   r   r   r   test_query_with_empty_result(  s
   
"z0TestDataFrameClient.test_query_with_empty_resultc                 C   s   ddddgdggdgdgigi}t dd	d
dd}t|ddt| | | ddiddig W d   dS 1 s=w   Y  dS )z9Test get list of databases in TestDataFrameClient object.r   r   Z	databasesZnew_db_1Znew_db_2r   )r   r   r)   r   r   r   r   r.   r   r   N)r   r   r   r   r   r   )r   r'   rE   r   r   r   test_get_list_database/  s"   	"z*TestDataFrameClient.test_get_list_databasec                 C   s   t d}tddddd}| ||d | |j|dd	d
 | |j|dd	d | |j|dd	d | |j|dd	d | |j|dd	d | |j|dd	d dS )z=Test convert datetime to epoch in TestDataFrameClient object.z2013-01-01 00:00:00.000+00:00r   r   r   r   r.   g   8Ar   r   g    ArD   g    uAr   r   g  6sBr   g  _>HCr   g ղCN)r5   r6   r   r=   Z_datetime_to_epoch)r   Z	timestamprE   r   r   r   test_datetime_to_epochA  s<   
z*TestDataFrameClient.test_datetime_to_epochc                 C   s(   t d}| |t  | d|j dS )z;Test data source name deconstructor in TestDataFrameClient.zinfluxdb://localhost:8086zhttp://localhost:8086N)r   Zfrom_dsnZassertIsInstancer=   Z_baseurl)r   Zclientr   r   r   test_dsn_constructorc  s   
z(TestDataFrameClient.test_dsn_constructorc                 C      t d}t jddtjgddtjgg||tdd gg dd}d	}t 8}|j	tj
d
dd tdd}|j|ddd | |jj| |j|dddd | |jj| W d   dS 1 saw   Y  dS )z0Test write points from dataframe with Nan lines.r   r   r
   r   r   r!   r"   r&   R   foo column_one="1",column_two=1i 0
foo column_one="2",column_two=2i 3600000000000
r+   r,   r-   r.   r/   r1   lineprotocolNr3   r   r5   r6   r7   r   infnanr   r8   r9   r:   r;   r   r<   r=   r>   r?   r@   r   r   r   .test_write_points_from_dataframe_with_nan_linei  $   


"zBTestDataFrameClient.test_write_points_from_dataframe_with_nan_linec                 C   r   )z+Test write points from json with NaN lines.r   r   r
   r   r   r!   r"   r&   r   r+   r,   r-   r.   r/   r1   r   r   Nr   r   r@   r   r   r   .test_write_points_from_dataframe_with_nan_json  r  zBTestDataFrameClient.test_write_points_from_dataframe_with_nan_jsonc                 C   s   t d}t jddddtjgddddtjgg||tdd	 gg d
d}d}t >}|j	tj
ddd tdd}|j|ddddgd | |jj| |j|dddddgd | |jj| W d   dS 1 skw   Y  dS )z9Test write points from dataframe with NaN lines and tags.r   rT   r
   r   rV   r   r   r   r!   rW   r&   s   foo,tag_one=blue,tag_two=1 column_one="1",column_two=1i 0
foo,tag_one=red,tag_two=0 column_one="2",column_two=2i 3600000000000
r+   r,   r-   r.   r/   r1   r   rX   rY   )r   r[   N)r3   r   r[   r   r@   r   r   r   7test_write_points_from_dataframe_with_tags_and_nan_line  s0   

	

"zKTestDataFrameClient.test_write_points_from_dataframe_with_tags_and_nan_linec                 C   s   dddg dg dg dg dgdgigi}t d	d
ddd}d}ddi}t|dd|' |j||dd	gd}|d }t| | dd	gt|jj W d   dS 1 sVw   Y  dS )zTest query with custom indexes.r   r   r   )r   r^   r   )r
   r   local)r   r   r  )rr   r   r  r   r   r   r   r   r.   r   r   r   r   r   r   )r   Zdata_frame_indexN)r   r   r   r   r   listr(   names)r   r'   rE   r   r   r   Z_data_framer   r   r   test_query_custom_index  s4   

"z+TestDataFrameClient.test_query_custom_indexN)6__name__
__module____qualname____doc__r   rF   rI   rJ   rL   rN   rP   rR   r]   r_   rc   rj   rn   r   unittestskipr   r   r   r   	TypeErrorr   r   r   r   	Exceptionr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r
  r   r   r   r   r      sl     G+A
6A



*

,7\" r   )r  Z
__future__r   r   r   r   Zdatetimer   r   r  r   r8   Z
nose.toolsr   Zinfluxdb.testsr   r	   Zclient_testr   Zpandasr5   Zpandas.util.testingr   Zinfluxdbr   Znumpyr   ZTestCaser   r   r   r   r   <module>   s(   