From 135caf77636cc5f4bf663d3fce8ac2fbe93029b1 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Tue, 18 Oct 2022 20:49:57 +0200 Subject: [PATCH] TIMESTAMP->dt: Use `backports.zoneinfo` on Python<3.9 --- docs/query.rst | 6 +++++- setup.py | 3 ++- src/crate/client/doctests/cursor.txt | 13 ++++++++++--- src/crate/client/test_cursor.py | 5 ++++- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/docs/query.rst b/docs/query.rst index 801144cfe..8f5d1d361 100644 --- a/docs/query.rst +++ b/docs/query.rst @@ -291,7 +291,11 @@ Let's exercise all of them. >>> ccursor.fetchone() ['foo', datetime.datetime(2022, 7, 19, 4, 10, 36, 758000, tzinfo=)] - >>> import zoneinfo + >>> try: + ... import zoneinfo + ... except ModuleNotFoundError: + ... from backports import zoneinfo + >>> ccursor.time_zone = zoneinfo.ZoneInfo("Australia/Sydney") >>> ccursor.execute("SELECT datetime_tz FROM locations ORDER BY name") >>> ccursor.fetchone() diff --git a/setup.py b/setup.py index c3ac39f7d..b89f9751f 100644 --- a/setup.py +++ b/setup.py @@ -65,7 +65,8 @@ def read(path): }, extras_require=dict( sqlalchemy=['sqlalchemy>=1.0,<1.5', - 'geojson>=2.5.0'], + 'geojson>=2.5.0', + 'backports.zoneinfo<1; python_version<"3.9"'], test=['tox>=3,<4', 'zope.testing>=4,<5', 'zope.testrunner>=5,<6', diff --git a/src/crate/client/doctests/cursor.txt b/src/crate/client/doctests/cursor.txt index 78c8daa6e..6f1756fe6 100644 --- a/src/crate/client/doctests/cursor.txt +++ b/src/crate/client/doctests/cursor.txt @@ -415,11 +415,18 @@ Let's exercise all of them:: >>> cursor.fetchone() ['foo', datetime.datetime(2022, 7, 19, 4, 10, 36, 758000, tzinfo=)] - >>> import zoneinfo + >>> try: + ... import zoneinfo + ... except ModuleNotFoundError: + ... from backports import zoneinfo >>> cursor.time_zone = zoneinfo.ZoneInfo("Australia/Sydney") >>> cursor.execute('') - >>> cursor.fetchone() - ['foo', datetime.datetime(2022, 7, 19, 4, 10, 36, 758000, tzinfo=zoneinfo.ZoneInfo(key='Australia/Sydney'))] + >>> record = cursor.fetchone() + >>> record + ['foo', datetime.datetime(2022, 7, 19, 4, 10, 36, 758000, ...zoneinfo.ZoneInfo(key='Australia/Sydney'))] + + >>> record[1].tzname() + 'AEST' >>> cursor.time_zone = "+0530" >>> cursor.execute('') diff --git a/src/crate/client/test_cursor.py b/src/crate/client/test_cursor.py index f3bdd3828..4e4b80032 100644 --- a/src/crate/client/test_cursor.py +++ b/src/crate/client/test_cursor.py @@ -20,10 +20,13 @@ # software solely pursuant to the terms of the relevant commercial agreement. import datetime -import zoneinfo from ipaddress import IPv4Address from unittest import TestCase from unittest.mock import MagicMock +try: + import zoneinfo +except ModuleNotFoundError: + from backports import zoneinfo import pytz