summaryrefslogtreecommitdiff
path: root/tests/test_dates.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-06-16 00:54:38 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-06-16 00:54:38 +0100
commit315f72862cb605b4e9f8d127dcc87bbffff6ffa0 (patch)
tree1e93f4966ce7a51b1467dc0297af4b4f13716445 /tests/test_dates.py
parent30af82ef2f1cfa2443203bd994ff53e40862776b (diff)
downloadpsycopg2-bug-558.tar.gz
Parse a number as microseconds when casting intervalbug-558
Should close #558, but I'm curious to know if a number is returned for interval < 1 day too (which wouldn't trigger the overflow, but will finish parsing with part=0).
Diffstat (limited to 'tests/test_dates.py')
-rwxr-xr-xtests/test_dates.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/test_dates.py b/tests/test_dates.py
index 83eea32..f2f49f2 100755
--- a/tests/test_dates.py
+++ b/tests/test_dates.py
@@ -411,6 +411,25 @@ class DatetimeTests(ConnectingTestCase, CommonDatetimeTestsMixin):
self.assert_(t.tzinfo is not None)
self.assert_(t < datetime(1000, 1, 1, tzinfo=FixedOffsetTimezone()))
+ def test_redshift_day(self):
+ # Redshift is reported returning 1 day interval as microsec (bug #558)
+ cur = self.conn.cursor()
+ psycopg2.extensions.register_type(
+ psycopg2.extensions.new_type(
+ psycopg2.STRING.values, 'WAT', psycopg2.extensions.INTERVAL),
+ cur)
+
+ from datetime import timedelta
+ for s, v in [
+ ('0', timedelta(0)),
+ ('1000000', timedelta(seconds=1)), # Is this a thing?
+ ('86400000000', timedelta(days=1)),
+ ('-86400000000', timedelta(days=-1)),
+ ]:
+ cur.execute("select %s::text", (s,))
+ r = cur.fetchone()[0]
+ self.assertEqual(r, v, "%s -> %s != %s" % (s, r, v))
+
# Only run the datetime tests if psycopg was compiled with support.
if not hasattr(psycopg2.extensions, 'PYDATETIME'):