11
11
12
12
class PointTest (unittest .TestCase ):
13
13
14
+ def test_ToStr (self ):
15
+ point = Point .measurement ("h2o" ).tag ("location" , "europe" ).field ("level" , 2.2 )
16
+ expected_str = "h2o,location=europe level=2.2"
17
+ self .assertEqual (expected_str , str (point ))
18
+
19
+ def my_str_rep (p : Point ) -> str :
20
+ return f'{ p ._name } - { p ._tags } - { p ._fields } - { p ._time } '
21
+
22
+ Point .set_str_rep (my_str_rep )
23
+
24
+ self .assertEqual (my_str_rep (point ), str (point ))
25
+
14
26
def test_MeasurementEscape (self ):
15
27
point = Point .measurement ("h2 o" ).tag ("location" , "europe" ).tag ("" , "warn" ).field ("level" , 2 )
16
28
self .assertEqual (point .to_line_protocol (), "h2\\ o,location=europe level=2i" )
@@ -36,17 +48,17 @@ def test_TagEmptyValue(self):
36
48
self .assertEqual ("h2o,location=europe level=2i" , point .to_line_protocol ())
37
49
38
50
def test_TagEscapingKeyAndValue (self ):
39
-
40
51
point = Point .measurement ("h\n 2\r o\t _data" ) \
41
52
.tag ("new\n line" , "new\n line" ) \
42
53
.tag ("carriage\r return" , "carriage\n return" ) \
43
54
.tag ("t\t ab" , "t\t ab" ) \
44
55
.field ("level" , 2 )
45
56
46
- self .assertEqual ("h\\ n2\\ ro\\ t_data,carriage\\ rreturn=carriage\\ nreturn,new\\ nline=new\\ nline,t\\ tab=t\\ tab level=2i" , point .to_line_protocol ())
57
+ self .assertEqual (
58
+ "h\\ n2\\ ro\\ t_data,carriage\\ rreturn=carriage\\ nreturn,new\\ nline=new\\ nline,t\\ tab=t\\ tab level=2i" ,
59
+ point .to_line_protocol ())
47
60
48
61
def test_EqualSignEscaping (self ):
49
-
50
62
point = Point .measurement ("h=2o" ) \
51
63
.tag ("l=ocation" , "e=urope" ) \
52
64
.field ("l=evel" , 2 )
@@ -391,22 +403,24 @@ def test_backslash(self):
391
403
def test_numpy_types (self ):
392
404
from influxdb_client .extras import np
393
405
394
- point = Point .measurement ("h2o" )\
395
- .tag ("location" , "europe" )\
396
- .field ("np.float1" , np .float (1.123 ))\
397
- .field ("np.float2" , np .float16 (2.123 ))\
398
- .field ("np.float3" , np .float32 (3.123 ))\
399
- .field ("np.float4" , np .float64 (4.123 ))\
400
- .field ("np.int1" , np .int8 (1 ))\
401
- .field ("np.int2" , np .int16 (2 ))\
402
- .field ("np.int3" , np .int32 (3 ))\
403
- .field ("np.int4" , np .int64 (4 ))\
404
- .field ("np.uint1" , np .uint8 (5 ))\
405
- .field ("np.uint2" , np .uint16 (6 ))\
406
- .field ("np.uint3" , np .uint32 (7 ))\
406
+ point = Point .measurement ("h2o" ) \
407
+ .tag ("location" , "europe" ) \
408
+ .field ("np.float1" , np .float (1.123 )) \
409
+ .field ("np.float2" , np .float16 (2.123 )) \
410
+ .field ("np.float3" , np .float32 (3.123 )) \
411
+ .field ("np.float4" , np .float64 (4.123 )) \
412
+ .field ("np.int1" , np .int8 (1 )) \
413
+ .field ("np.int2" , np .int16 (2 )) \
414
+ .field ("np.int3" , np .int32 (3 )) \
415
+ .field ("np.int4" , np .int64 (4 )) \
416
+ .field ("np.uint1" , np .uint8 (5 )) \
417
+ .field ("np.uint2" , np .uint16 (6 )) \
418
+ .field ("np.uint3" , np .uint32 (7 )) \
407
419
.field ("np.uint4" , np .uint64 (8 ))
408
420
409
- self .assertEqual ("h2o,location=europe np.float1=1.123,np.float2=2.123,np.float3=3.123,np.float4=4.123,np.int1=1i,np.int2=2i,np.int3=3i,np.int4=4i,np.uint1=5i,np.uint2=6i,np.uint3=7i,np.uint4=8i" , point .to_line_protocol ())
421
+ self .assertEqual (
422
+ "h2o,location=europe np.float1=1.123,np.float2=2.123,np.float3=3.123,np.float4=4.123,np.int1=1i,np.int2=2i,np.int3=3i,np.int4=4i,np.uint1=5i,np.uint2=6i,np.uint3=7i,np.uint4=8i" ,
423
+ point .to_line_protocol ())
410
424
411
425
def test_from_dictionary_custom_measurement (self ):
412
426
dictionary = {
@@ -457,7 +471,9 @@ def test_from_dictionary_custom_fields(self):
457
471
record_measurement_key = "name" ,
458
472
record_tag_keys = ["location" , "version" ],
459
473
record_field_keys = ["pressure" , "temperature" ])
460
- self .assertEqual ("sensor_pt859,location=warehouse_125,version=2021.06.05.5874 pressure=125i,temperature=10i 1632208639" , point .to_line_protocol ())
474
+ self .assertEqual (
475
+ "sensor_pt859,location=warehouse_125,version=2021.06.05.5874 pressure=125i,temperature=10i 1632208639" ,
476
+ point .to_line_protocol ())
461
477
462
478
def test_from_dictionary_tolerant_to_missing_tags_and_fields (self ):
463
479
dictionary = {
0 commit comments