o
    $^                     @   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ZddlmZ ddlm	Z	 dd	l
mZmZ dd
lmZ G dd dejZdS )z%Define the line protocol test module.    )absolute_import)division)print_function)unicode_literalsN)datetime)Decimal)UTCtimezone)line_protocolc                   @   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S )TestLineProtocolz$Define the LineProtocol test object.c                 C   s@   ddddddddd	d
ddddgd}|  t|d dS )z/Test make new lines in TestLineProtocol object. NzC:\   hello)Z	empty_tagZnone_tagZbackslash_tagZinteger_tagZ
string_tagtestzhello!   g?T)Z
string_valZint_val	float_valZ
none_fieldZbool_valmeasurementfieldsZtagspointszrtest,backslash_tag=C:\\,integer_tag=2,string_tag=hello bool_val=True,float_val=1.1,int_val=1i,string_val="hello!"
assertEqualr
   
make_linesselfdata r   C/usr/lib/python3/dist-packages/influxdb/tests/test_line_protocol.pytest_make_lines   s(   	z TestLineProtocol.test_make_linesc              
   C   s   t ddddddd}t|}td|}|td}d	d
ddiddd
ddiddd
ddi|dd
ddi|dd
ddi|dd
ddi|dgi}| t|dg dd  dS )z)Test timezone in TestLineProtocol object.i     
      r   i@ zEurope/Berlinz
US/Easternr   Avalr   )r   r   timez2009-11-10T23:00:00.123456Z
)z
A val=1i 0A val=1i 1257894000123456000r'   r'   A val=1i 1257890400123456000r(   N)	r   r   localizer	   Z
astimezoner   r
   r   join)r   ZdtZutcZberlinZeasternr   r   r   r   test_timezone3   s.   
zTestLineProtocol.test_timezonec                 C   *   ddddidgi}|  t|d dS )z:Test string value with newline in TestLineProtocol object.r   Zm1Z
multi_linezline1
line1
line3r   z$m1 multi_line="line1\nline1\nline3"
Nr   r   r   r   r   test_string_val_newlineQ      z(TestLineProtocol.test_string_val_newlinec                 C   0   ddidddidgd}|  t|d d	S )
z3Test make unicode lines in TestLineProtocol object.Zunicode_tagu   'Привет!'r   Zunicode_valu   Привет!r   r   u=   test,unicode_tag='Привет!' unicode_val="Привет!"
Nr   r   r   r   r   test_make_lines_unicodec      z(TestLineProtocol.test_make_lines_unicodec                 C   r,   )z+Test make lines with an empty string field.r   r   stringr   r   ztest string=""
Nr   r   r   r   r   "test_make_lines_empty_field_stringx   r.   z3TestLineProtocol.test_make_lines_empty_field_stringc                 C   r/   )
z0Test make lines with tag value contains newline.t1zline1
line2r   r$   r   r   r   z!test,t1=line1\nline2 val="hello"
Nr   r   r   r   r   test_tag_value_newline   r1   z'TestLineProtocol.test_tag_value_newlinec                 C      |  tdd dS )z2Test quote indentation in TestLineProtocol object.   \foo ' bar " Örfu   "\\foo ' bar \" Örf"N)r   r
   Zquote_identr   r   r   r   test_quote_ident      z!TestLineProtocol.test_quote_identc                 C   r6   )z.Test quote literal in TestLineProtocol object.r7   u   '\\foo \' bar " Örf'N)r   r
   Zquote_literalr8   r   r   r   test_quote_literal   r:   z#TestLineProtocol.test_quote_literalc                 C   r,   )z?Ensure precision is preserved when casting floats into strings.r   r   r   g     ?r   z"test float_val=1.0000000000000009
Nr   r   r   r   r   %test_float_with_long_decimal_fraction   s   
z6TestLineProtocol.test_float_with_long_decimal_fractionc                 C   s.   dddt didgi}| t|d dS )z@Ensure precision is preserved when casting Decimal into strings.r   r   r   g:Ŷ?r   z"test float_val=0.8289445733333332
N)r   r   r
   r   r   r   r   r   5test_float_with_long_decimal_fraction_as_type_decimal   s   
zFTestLineProtocol.test_float_with_long_decimal_fraction_as_type_decimalN)__name__
__module____qualname____doc__r   r+   r-   r0   r3   r5   r9   r;   r<   r=   r   r   r   r   r      s    r   )rA   Z
__future__r   r   r   r   Zunittestr   Zdecimalr   Zpytzr   r	   Zinfluxdbr
   ZTestCaser   r   r   r   r   <module>   s   