summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2021-06-15 00:20:09 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2021-06-15 00:22:54 +0100
commit1d3d5e905fd5da01a3e98afac006d91e31adb69e (patch)
tree102e97b9890cddbe278cde34135db4024339c0f9
parentf28502663f1c318dd01c975cf70e3dcce544ab3b (diff)
downloadpsycopg2-1d3d5e905fd5da01a3e98afac006d91e31adb69e.tar.gz
Deprecate the psycopg2.tz module
Don't use its objects anymore in the tests (except for the tests for the objects themselves).
-rw-r--r--NEWS2
-rw-r--r--doc/src/tz.rst4
-rw-r--r--lib/__init__.py2
-rwxr-xr-xtests/test_dates.py18
-rwxr-xr-xtests/test_types_extras.py13
5 files changed, 21 insertions, 18 deletions
diff --git a/NEWS b/NEWS
index 44289d5..ebb1288 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,8 @@ Other changes:
- Dropped support for mx.DateTime.
- Use `datetime.timezone` objects by default in datetime objects instead of
`~psycopg2.tz.FixedOffsetTimezone`.
+- The `psycopg2.tz` module is deprecated and scheduled to be dropped in the
+ next major release.
- Build system for Linux/MacOS binary packages moved to GitHub action, now
providing :pep:`600`\-style wheels packages.
diff --git a/doc/src/tz.rst b/doc/src/tz.rst
index 06333f8..c1bd5ff 100644
--- a/doc/src/tz.rst
+++ b/doc/src/tz.rst
@@ -5,6 +5,10 @@
.. module:: psycopg2.tz
+.. deprecated:: 2.9
+ The module will be dropped in psycopg 2.10. Use `datetime.timezone`
+ instead.
+
This module holds two different tzinfo implementations that can be used as the
`tzinfo` argument to `~datetime.datetime` constructors, directly passed to
Psycopg functions or used to set the `cursor.tzinfo_factory` attribute in
diff --git a/lib/__init__.py b/lib/__init__.py
index 52c82bc..8d61892 100644
--- a/lib/__init__.py
+++ b/lib/__init__.py
@@ -61,8 +61,6 @@ from psycopg2._psycopg import ( # noqa
__version__, __libpq_version__,
)
-from psycopg2 import tz # noqa
-
# Register default adapters.
diff --git a/tests/test_dates.py b/tests/test_dates.py
index 850c991..d4d2e7f 100755
--- a/tests/test_dates.py
+++ b/tests/test_dates.py
@@ -188,7 +188,7 @@ class DatetimeTests(ConnectingTestCase, CommonDatetimeTestsMixin):
self.assertEqual(value.replace(tzinfo=None), base)
# Conversion to UTC produces the expected offset.
- UTC = FixedOffsetTimezone(0, "UTC")
+ UTC = timezone(timedelta(0))
value_utc = value.astimezone(UTC).replace(tzinfo=None)
self.assertEqual(base - value_utc, timedelta(seconds=offset))
@@ -317,7 +317,7 @@ class DatetimeTests(ConnectingTestCase, CommonDatetimeTestsMixin):
self.assertEqual(None, dt.tzinfo)
def test_type_roundtrip_datetimetz(self):
- tz = FixedOffsetTimezone(8 * 60)
+ tz = timezone(timedelta(minutes=8 * 60))
dt1 = datetime(2010, 5, 3, 10, 20, 30, tzinfo=tz)
dt2 = self._test_type_roundtrip(dt1)
self.assertNotEqual(None, dt2.tzinfo)
@@ -328,7 +328,7 @@ class DatetimeTests(ConnectingTestCase, CommonDatetimeTestsMixin):
self.assertEqual(None, tm.tzinfo)
def test_type_roundtrip_timetz(self):
- tz = FixedOffsetTimezone(8 * 60)
+ tz = timezone(timedelta(minutes=8 * 60))
tm1 = time(10, 20, 30, tzinfo=tz)
tm2 = self._test_type_roundtrip(tm1)
self.assertNotEqual(None, tm2.tzinfo)
@@ -345,7 +345,7 @@ class DatetimeTests(ConnectingTestCase, CommonDatetimeTestsMixin):
def test_type_roundtrip_datetimetz_array(self):
self._test_type_roundtrip_array(
- datetime(2010, 5, 3, 10, 20, 30, tzinfo=FixedOffsetTimezone(0)))
+ datetime(2010, 5, 3, 10, 20, 30, tzinfo=timezone(timedelta(0))))
def test_type_roundtrip_time_array(self):
self._test_type_roundtrip_array(time(10, 20, 30))
@@ -359,10 +359,10 @@ class DatetimeTests(ConnectingTestCase, CommonDatetimeTestsMixin):
self.assertEqual(t, time(0, 0))
t = self.execute("select '24:00+05'::timetz;")
- self.assertEqual(t, time(0, 0, tzinfo=FixedOffsetTimezone(300)))
+ self.assertEqual(t, time(0, 0, tzinfo=timezone(timedelta(minutes=300))))
t = self.execute("select '24:00+05:30'::timetz;")
- self.assertEqual(t, time(0, 0, tzinfo=FixedOffsetTimezone(330)))
+ self.assertEqual(t, time(0, 0, tzinfo=timezone(timedelta(minutes=330))))
@skip_before_postgres(8, 1)
def test_large_interval(self):
@@ -430,11 +430,11 @@ class DatetimeTests(ConnectingTestCase, CommonDatetimeTestsMixin):
t = self.execute("select 'infinity'::timestamptz")
self.assert_(t.tzinfo is not None)
- self.assert_(t > datetime(4000, 1, 1, tzinfo=FixedOffsetTimezone()))
+ self.assert_(t > datetime(4000, 1, 1, tzinfo=timezone(timedelta(0))))
t = self.execute("select '-infinity'::timestamptz")
self.assert_(t.tzinfo is not None)
- self.assert_(t < datetime(1000, 1, 1, tzinfo=FixedOffsetTimezone()))
+ self.assert_(t < datetime(1000, 1, 1, tzinfo=timezone(timedelta(0))))
def test_redshift_day(self):
# Redshift is reported returning 1 day interval as microsec (bug #558)
@@ -473,7 +473,7 @@ class FromTicksTestCase(unittest.TestCase):
s = psycopg2.TimestampFromTicks(1273173119.99992)
self.assertEqual(s.adapted,
datetime(2010, 5, 6, 14, 11, 59, 999920,
- tzinfo=FixedOffsetTimezone(-5 * 60)))
+ tzinfo=timezone(timedelta(minutes=-5 * 60))))
def test_date_value_error_sec_59_99(self):
s = psycopg2.DateFromTicks(1273173119.99992)
diff --git a/tests/test_types_extras.py b/tests/test_types_extras.py
index c653020..26500eb 100755
--- a/tests/test_types_extras.py
+++ b/tests/test_types_extras.py
@@ -20,7 +20,7 @@ import json
import uuid
import warnings
from decimal import Decimal
-from datetime import date, datetime
+from datetime import date, datetime, timedelta, timezone
from functools import wraps
from pickle import dumps, loads
@@ -38,7 +38,6 @@ from psycopg2.extras import (
Inet, Json, NumericRange, Range, RealDictConnection,
register_composite, register_hstore, register_range,
)
-from psycopg2.tz import FixedOffsetTimezone
class TypesExtrasTests(ConnectingTestCase):
@@ -1282,7 +1281,7 @@ class RangeTestCase(unittest.TestCase):
Date-Time ranges should return a human-readable string as well on
string conversion.
'''
- tz = FixedOffsetTimezone(-5 * 60, "EST")
+ tz = timezone(timedelta(minutes=-5 * 60), "EST")
r = DateTimeTZRange(datetime(2010, 1, 1, tzinfo=tz),
datetime(2011, 1, 1, tzinfo=tz))
expected = '[2010-01-01 00:00:00-05:00, 2011-01-01 00:00:00-05:00)'
@@ -1377,9 +1376,9 @@ class RangeCasterTestCase(ConnectingTestCase):
def test_cast_timestamptz(self):
cur = self.conn.cursor()
- ts1 = datetime(2000, 1, 1, tzinfo=FixedOffsetTimezone(600))
+ ts1 = datetime(2000, 1, 1, tzinfo=timezone(timedelta(minutes=600)))
ts2 = datetime(2000, 12, 31, 23, 59, 59, 999,
- tzinfo=FixedOffsetTimezone(600))
+ tzinfo=timezone(timedelta(minutes=600)))
cur.execute("select tstzrange(%s, %s, '[]')", (ts1, ts2))
r = cur.fetchone()[0]
self.assert_(isinstance(r, DateTimeTZRange))
@@ -1465,9 +1464,9 @@ class RangeCasterTestCase(ConnectingTestCase):
self.assert_(isinstance(r1, DateTimeRange))
self.assert_(r1.isempty)
- ts1 = datetime(2000, 1, 1, tzinfo=FixedOffsetTimezone(600))
+ ts1 = datetime(2000, 1, 1, tzinfo=timezone(timedelta(minutes=600)))
ts2 = datetime(2000, 12, 31, 23, 59, 59, 999,
- tzinfo=FixedOffsetTimezone(600))
+ tzinfo=timezone(timedelta(minutes=600)))
r = DateTimeTZRange(ts1, ts2, '(]')
cur.execute("select %s", (r,))
r1 = cur.fetchone()[0]