@@ -88,6 +88,9 @@ def test_write_num_py(self):
8888
8989 pass
9090
91+
92+ class DataSerializerTest (unittest .TestCase ):
93+
9194 def test_write_nan (self ):
9295 from influxdb_client .extras import pd , np
9396
@@ -129,8 +132,6 @@ def test_write_tag_nan(self):
129132 now + timedelta (minutes = 60 ), now + timedelta (minutes = 90 )],
130133 columns = ["tag" , "actual_kw_price" , "forecast_kw_price" ])
131134
132- write_api = self .client .write_api (write_options = SYNCHRONOUS , point_settings = PointSettings ())
133-
134135 points = data_frame_to_list_of_points (data_frame = data_frame ,
135136 point_settings = PointSettings (),
136137 data_frame_measurement_name = 'measurement' ,
@@ -146,8 +147,6 @@ def test_write_tag_nan(self):
146147 self .assertEqual ("measurement,tag=tag actual_kw_price=3.138664,forecast_kw_price=20.755026 1586050200000000000" ,
147148 points [3 ])
148149
149- write_api .__del__ ()
150-
151150 def test_escaping_measurement (self ):
152151 from influxdb_client .extras import pd , np
153152
@@ -214,3 +213,24 @@ def test_tags_order(self):
214213
215214 self .assertEqual (1 , len (points ))
216215 self .assertEqual ("h2o,a=a,b=b,c=c level=2i 1586048400000000000" , points [0 ])
216+
217+ def test_escape_text_value (self ):
218+ from influxdb_client .extras import pd , np
219+
220+ now = pd .Timestamp ('2020-04-05 00:00+00:00' )
221+ an_hour_ago = now - timedelta (hours = 1 )
222+
223+ test = [{'a' : an_hour_ago , 'b' : 'hello world' , 'c' : 1 , 'd' : 'foo bar' },
224+ {'a' : now , 'b' : 'goodbye cruel world' , 'c' : 2 , 'd' : 'bar foo' }]
225+
226+ data_frame = pd .DataFrame (test )
227+ data_frame = data_frame .set_index ('a' )
228+
229+ points = data_frame_to_list_of_points (data_frame = data_frame ,
230+ point_settings = PointSettings (),
231+ data_frame_measurement_name = 'test' ,
232+ data_frame_tag_columns = ['d' ])
233+
234+ self .assertEqual (2 , len (points ))
235+ self .assertEqual ("test,d=foo\\ bar b=\" hello world\" ,c=1i 1586041200000000000" , points [0 ])
236+ self .assertEqual ("test,d=bar\\ foo b=\" goodbye cruel world\" ,c=2i 1586044800000000000" , points [1 ])
0 commit comments