Skip to content

Commit 2d2ddc6

Browse files
committed
chore: add test case to test Precision error
1 parent 1bdf569 commit 2d2ddc6

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

tests/test_WriteApi.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,33 @@ def test_write_empty_data(self):
306306

307307
self.assertEqual(len(result), 0)
308308

309+
def test_write_point_different_precision(self):
310+
bucket = self.create_test_bucket()
311+
312+
point1 = Point('test_precision') \
313+
.field('power', 10) \
314+
.tag('powerFlow', 'low') \
315+
.time(datetime.datetime(2020, 4, 20, 5, 30, tzinfo=datetime.timezone.utc), WritePrecision.S)
316+
317+
point2 = Point('test_precision') \
318+
.field('power', 20) \
319+
.tag('powerFlow', 'high') \
320+
.time(datetime.datetime(2020, 4, 20, 6, 30, tzinfo=datetime.timezone.utc), WritePrecision.MS)
321+
322+
writer = self.client.write_api(write_options=SYNCHRONOUS)
323+
writer.write(bucket.name, self.org, [point1, point2])
324+
325+
result = self.query_api.query(
326+
f"from(bucket:\"{bucket.name}\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()", self.org)
327+
328+
self.assertEqual(len(result), 2)
329+
self.assertEqual(len(result[0].records), 1)
330+
self.assertEqual(len(result[1].records), 1)
331+
self.assertEqual(result[0].records[0].get_time(),
332+
datetime.datetime(2020, 4, 20, 5, 30, tzinfo=datetime.timezone.utc))
333+
self.assertEqual(result[1].records[0].get_time(),
334+
datetime.datetime(2020, 4, 20, 6, 30, tzinfo=datetime.timezone.utc))
335+
309336

310337
class AsynchronousWriteTest(BaseTest):
311338

@@ -381,9 +408,9 @@ def test_use_default_tags_with_dictionaries(self):
381408
bucket = self.create_test_bucket()
382409

383410
_point1 = {"measurement": "h2o_feet", "tags": {"location": "coyote_creek"},
384-
"time": "2009-11-10T22:00:00Z", "fields": {"water_level": 1.0}}
411+
"time": "2009-11-10T22:00:00Z", "fields": {"water_level": 1.0}}
385412
_point2 = {"measurement": "h2o_feet", "tags": {"location": "coyote_creek"},
386-
"time": "2009-11-10T23:00:00Z", "fields": {"water_level": 2.0}}
413+
"time": "2009-11-10T23:00:00Z", "fields": {"water_level": 2.0}}
387414

388415
_point_list = [_point1, _point2]
389416

@@ -424,7 +451,7 @@ def test_use_default_tags_with_data_frame(self):
424451
columns=["location", "water_level"])
425452

426453
async_result = self.write_client.write(bucket.name, record=data_frame, data_frame_measurement_name='h2o_feet',
427-
data_frame_tag_columns=['location'])
454+
data_frame_tag_columns=['location'])
428455
async_result.get()
429456

430457
query = 'from(bucket:"' + bucket.name + '") |> range(start: 1970-01-01T00:00:00.000000001Z)'

0 commit comments

Comments
 (0)