Skip to content

Commit

Permalink
Fix date/datetime negative infinity decoder regression
Browse files Browse the repository at this point in the history
This was introduced in 678f683.

Fixes: #62
  • Loading branch information
elprans committed Jan 5, 2017
1 parent d2be6ec commit ff68ca5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions asyncpg/protocol/codecs/datetime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ cdef int32_t pg_date_offset_ord = \

# Binary representations of infinity for datetimes.
cdef int64_t pg_time64_infinity = 0x7fffffffffffffff
cdef int64_t pg_time64_negative_infinity = -1
cdef int64_t pg_time64_negative_infinity = <int64_t>0x8000000000000000
cdef int32_t pg_date_infinity = 0x7fffffff
cdef int32_t pg_date_negative_infinity = -1
cdef int32_t pg_date_negative_infinity = <int32_t>0x80000000

infinity_datetime = datetime.datetime(
datetime.MAXYEAR, 12, 31, 23, 59, 59, 999999)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
if sys.version_info < (3, 5):
raise RuntimeError('asyncpg requires Python 3.5 or greater')

VERSION = '0.8.3'
VERSION = '0.8.4'
CFLAGS = ['-O2']
LDFLAGS = []

Expand Down
19 changes: 16 additions & 3 deletions tests/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,17 @@ def _timezone(offset):
datetime.datetime(250, 1, 1, 5, 25, 10),
infinity_datetime,
negative_infinity_datetime,
{'textinput': 'infinity', 'output': infinity_datetime},
{'textinput': '-infinity', 'output': negative_infinity_datetime},
]),
('date', 'date', [
datetime.date(3000, 5, 20),
datetime.date(2000, 1, 1),
datetime.date(500, 1, 1),
datetime.date(1, 1, 1),
infinity_date,
negative_infinity_date,
{'textinput': 'infinity', 'output': infinity_date},
{'textinput': '-infinity', 'output': negative_infinity_date},
]),
('time', 'time', [
datetime.time(12, 15, 20),
Expand Down Expand Up @@ -360,15 +364,24 @@ async def test_standard_codecs(self):
"SELECT $1::" + typname
)

textst = await self.con.prepare(
"SELECT $1::text::" + typname
)

for sample in sample_data:
with self.subTest(sample=sample, typname=typname):
stmt = st
if isinstance(sample, dict):
inputval = sample['input']
if 'textinput' in sample:
inputval = sample['textinput']
stmt = textst
else:
inputval = sample['input']
outputval = sample['output']
else:
inputval = outputval = sample

result = await st.fetchval(inputval)
result = await stmt.fetchval(inputval)
err_msg = (
"unexpected result for {} when passing {!r}: "
"received {!r}, expected {!r}".format(
Expand Down

0 comments on commit ff68ca5

Please sign in to comment.