4
4
from datetime import datetime , timezone , timedelta
5
5
from decimal import Decimal
6
6
7
- from pytz import UTC , timezone
7
+ from dateutil import tz
8
8
9
9
from influxdb_client import Point , WritePrecision
10
10
@@ -181,7 +181,7 @@ def test_DateTimeFormatting(self):
181
181
182
182
self .assertEqual ("h2o,location=europe level=2i 1444897215000" , point .to_line_protocol ())
183
183
184
- date_time = datetime (2015 , 10 , 15 , 8 , 20 , 15 , 750 , UTC )
184
+ date_time = datetime (2015 , 10 , 15 , 8 , 20 , 15 , 750 , timezone . utc )
185
185
186
186
point = Point .measurement ("h2o" ) \
187
187
.tag ("location" , "europe" ) \
@@ -214,15 +214,15 @@ def test_DateTimeFormatting(self):
214
214
point = Point .measurement ("h2o" ) \
215
215
.tag ("location" , "europe" ) \
216
216
.field ("level" , True ) \
217
- .time (datetime .now (UTC ), WritePrecision .S )
217
+ .time (datetime .now (timezone . utc ), WritePrecision .S )
218
218
219
219
line_protocol = point .to_line_protocol ()
220
220
self .assertTrue ("." not in line_protocol )
221
221
222
222
point = Point .measurement ("h2o" ) \
223
223
.tag ("location" , "europe" ) \
224
224
.field ("level" , True ) \
225
- .time (datetime .now (UTC ), WritePrecision .NS )
225
+ .time (datetime .now (timezone . utc ), WritePrecision .NS )
226
226
227
227
line_protocol = point .to_line_protocol ()
228
228
self .assertTrue ("." not in line_protocol )
@@ -293,9 +293,9 @@ def test_lineprotocol_encode(self):
293
293
def test_timestamp (self ):
294
294
"""Test timezone in TestLineProtocol object."""
295
295
dt = datetime (2009 , 11 , 10 , 23 , 0 , 0 , 123456 )
296
- utc = UTC . localize ( dt )
297
- berlin = timezone ( 'Europe/Berlin' ). localize ( dt )
298
- eastern = berlin .astimezone (timezone ('US/Eastern' ))
296
+ utc = dt . replace ( tzinfo = timezone . utc )
297
+ berlin = dt . replace ( tzinfo = tz . gettz ( 'Europe/Berlin' ))
298
+ eastern = berlin .astimezone (tz . gettz ('US/Eastern' ))
299
299
300
300
exp_utc = 'A val=1i 1257894000123456000'
301
301
exp_est = 'A val=1i 1257890400123456000'
@@ -335,9 +335,9 @@ def test_only_infinity_values(self):
335
335
def test_timezone (self ):
336
336
"""Test timezone in TestLineProtocol object."""
337
337
dt = datetime (2009 , 11 , 10 , 23 , 0 , 0 , 123456 )
338
- utc = UTC . localize ( dt )
339
- berlin = timezone ( 'Europe/Berlin' ). localize ( dt )
340
- eastern = berlin .astimezone (timezone ('US/Eastern' ))
338
+ utc = dt . replace ( tzinfo = timezone . utc )
339
+ berlin = dt . replace ( tzinfo = tz . gettz ( 'Europe/Berlin' ))
340
+ eastern = berlin .astimezone (tz . gettz ('US/Eastern' ))
341
341
342
342
self .assertEqual ("h2o val=1i 0" , Point .measurement ("h2o" ).field ("val" , 1 ).time (0 ).to_line_protocol ())
343
343
self .assertEqual ("h2o val=1i 1257894000123456000" , Point .measurement ("h2o" ).field ("val" , 1 ).time (
@@ -367,8 +367,8 @@ def test_from_dict_without_tags(self):
367
367
self .assertEqual ("my-org field1=1i,field2=2i" , point .to_line_protocol ())
368
368
369
369
def test_points_from_different_timezones (self ):
370
- time_in_utc = UTC . localize ( datetime (2020 , 7 , 4 , 0 , 0 , 0 , 123456 ))
371
- time_in_hk = timezone ( 'Asia/Hong_Kong' ). localize ( datetime (2020 , 7 , 4 , 8 , 0 , 0 , 123456 )) # +08:00
370
+ time_in_utc = datetime (2020 , 7 , 4 , 0 , 0 , 0 , 123456 ). replace ( tzinfo = timezone . utc )
371
+ time_in_hk = datetime (2020 , 7 , 4 , 8 , 0 , 0 , 123456 ). replace ( tzinfo = tz . gettz ( 'Asia/Hong_Kong' )) # +08:00
372
372
373
373
point_utc = Point .measurement ("h2o" ).field ("val" , 1 ).time (time_in_utc )
374
374
point_hk = Point .measurement ("h2o" ).field ("val" , 1 ).time (time_in_hk )
@@ -378,11 +378,11 @@ def test_unsupported_field_type(self):
378
378
with self .assertRaises (ValueError ) as ve :
379
379
Point .measurement ("h2o" ) \
380
380
.tag ("location" , "europe" ) \
381
- .field ("level" , UTC ) \
381
+ .field ("level" , timezone . utc ) \
382
382
.to_line_protocol ()
383
383
exception = ve .exception
384
384
385
- self .assertEqual ('Type: "<class \' pytz.UTC \' >" of field: "level" is not supported.' , f'{ exception } ' )
385
+ self .assertEqual ('Type: "<class \' datetime.timezone \' >" of field: "level" is not supported.' , f'{ exception } ' )
386
386
387
387
def test_backslash (self ):
388
388
point = Point .from_dict ({"measurement" : "test" ,
0 commit comments