diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2017-02-24 13:03:54 +0000 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2017-02-24 13:23:56 +0000 |
| commit | 691df4952ba9132f6af012f021c0db04c8681d9e (patch) | |
| tree | c60bf3f3cf3561a8a3c784d808923d7b787e462e /tests | |
| parent | 3b665d35d5948eab4f3001eb2e2c1f8810e10905 (diff) | |
| download | psycopg2-691df4952ba9132f6af012f021c0db04c8681d9e.tar.gz | |
Handle overflow in interval parsing
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/test_dates.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/test_dates.py b/tests/test_dates.py index bffd05d..9b71905 100755 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -373,6 +373,24 @@ class DatetimeTests(ConnectingTestCase, CommonDatetimeTestsMixin): t = self.execute("select '0.0000006'::interval") self.assertEqual(total_seconds(t), 1e-6) + def test_interval_overflow(self): + cur = self.conn.cursor() + # hack a cursor to receive values too extreme to be represented + # but still I want an error, not a random number + psycopg2.extensions.register_type( + psycopg2.extensions.new_type( + psycopg2.STRING.values, 'WAT', psycopg2.extensions.INTERVAL), + cur) + + def f(val): + cur.execute("select '%s'::text" % val) + return cur.fetchone()[0] + + self.assertRaises(OverflowError, f, '100000000000000000:00:00') + self.assertRaises(OverflowError, f, '00:100000000000000000:00:00') + self.assertRaises(OverflowError, f, '00:00:100000000000000000:00') + self.assertRaises(OverflowError, f, '00:00:00.100000000000000000') + # Only run the datetime tests if psycopg was compiled with support. if not hasattr(psycopg2.extensions, 'PYDATETIME'): |
