diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ebd157..b61ff4b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,7 +22,7 @@ commands: pip install . --user pip install .\[dataframe\] --user pip install .\[test\] --user - pytest -m "<< parameters.pytest-marker >>" tests --junitxml=test-reports/junit.xml --cov=./ --cov-report xml:coverage.xml + pytest -m "<< parameters.pytest-marker >>" tests --junitxml=test-reports/junit.xml --cov=./influxdb_client_3 --cov-report xml:coverage.xml - save_cache: name: Saving Pip Cache key: *cache-key diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e7aa49..085e534 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Features +1. [#89](https://github.com/InfluxCommunity/influxdb3-python/pull/89): Use `datetime.fromisoformat` over `dateutil.parse` in Python 3.11+ 1. [#92](https://github.com/InfluxCommunity/influxdb3-python/pull/92): Update `user-agent` header value to `influxdb3-python/{VERSION}` and add it to queries as well. ## 0.5.0 [2024-05-17] diff --git a/influxdb_client_3/write_client/client/util/date_utils.py b/influxdb_client_3/write_client/client/util/date_utils.py index 11baecb..e7e4238 100644 --- a/influxdb_client_3/write_client/client/util/date_utils.py +++ b/influxdb_client_3/write_client/client/util/date_utils.py @@ -2,6 +2,7 @@ import datetime import threading from datetime import timezone as tz +from sys import version_info from dateutil import parser @@ -90,7 +91,10 @@ def get_date_helper() -> DateHelper: import ciso8601 _date_helper.parse_date = ciso8601.parse_datetime except ModuleNotFoundError: - _date_helper.parse_date = parser.parse + if (version_info.major, version_info.minor) >= (3, 11): + _date_helper.parse_date = datetime.datetime.fromisoformat + else: + _date_helper.parse_date = parser.parse date_helper = _date_helper return date_helper diff --git a/tests/test_date_helper.py b/tests/test_date_helper.py new file mode 100644 index 0000000..7c39c43 --- /dev/null +++ b/tests/test_date_helper.py @@ -0,0 +1,21 @@ +import unittest +from datetime import datetime, timezone + +from dateutil import tz + +from influxdb_client_3.write_client.client.util.date_utils import DateHelper, get_date_helper + + +class TestDateHelper(unittest.TestCase): + + def test_to_utc(self): + date = get_date_helper().to_utc(datetime(2021, 4, 29, 20, 30, 10, 0)) + self.assertEqual(datetime(2021, 4, 29, 20, 30, 10, 0, timezone.utc), date) + + def test_to_utc_different_timezone(self): + date = DateHelper(timezone=tz.gettz('ETC/GMT+2')).to_utc(datetime(2021, 4, 29, 20, 30, 10, 0)) + self.assertEqual(datetime(2021, 4, 29, 22, 30, 10, 0, timezone.utc), date) + + def test_parse(self): + date = get_date_helper().parse_date("2021-03-20T15:59:10.607352Z") + self.assertEqual(datetime(2021, 3, 20, 15, 59, 10, 607352, timezone.utc), date) diff --git a/tests/test_merge_options.py b/tests/test_merge_options.py index a263a41..0c20b80 100644 --- a/tests/test_merge_options.py +++ b/tests/test_merge_options.py @@ -3,7 +3,7 @@ import influxdb_client_3 -class MergeOptionsTests(unittest.TestCase): +class TestMergeOptions(unittest.TestCase): def test_merge_with_empty_custom(self): defaults = {"a": 1, "b": 2} diff --git a/tests/test_query.py b/tests/test_query.py index 1fd7cb8..ad91063 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -112,7 +112,7 @@ def test_influx_default_query_headers(): _req_headers = {} -class QueryTests(unittest.TestCase): +class TestQuery(unittest.TestCase): @patch('influxdb_client_3._InfluxDBClient') @patch('influxdb_client_3._WriteApi')