Incorrect date decoding in Python 3
Issue #52
resolved
Hi.
The following test
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import tempfile
import unittest
from savReaderWriter import SavReader, SavWriter
class DecodeSPSSDateTest(unittest.TestCase):
def test(self):
with tempfile.NamedTemporaryFile(suffix='.sav') as tmpfile:
with SavWriter(tmpfile.name, ['date'], {b'date': 0}, formats={b'date': b'EDATE40'}, ioUtf8=True, ioLocale="C.UTF-8") as writer:
writer.writerow([writer.spssDateTime(b"2000-01-01", "%Y-%m-%d")])
with SavReader(tmpfile.name, returnHeader=False, ioUtf8=True, ioLocale="C.UTF-8") as reader:
print(sys.version_info)
date = list(reader)[0][0]
self.assertEqual('2000-01-01', date)
is successful in Python 2, but unsuccessful in Python 3:
F
======================================================================
FAIL: test (tests.test_bug.DecodeSPSSDateTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ire/code/datasetconverter/tests/test_bug.py", line 20, in test
self.assertEqual('2000-01-01', date)
AssertionError: '2000-01-01' != 13166064000.0
-------------------- >> begin captured stdout << ---------------------
sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)
--------------------- >> end captured stdout << ----------------------
----------------------------------------------------------------------
Ran 1 test in 0.012s
FAILED (failures=1)
Or did I miss something in the settings?
Comments (2)
-
repo owner -
repo owner - changed status to resolved
Fixed issue
#52, date was not converted into ISO8601 string in Python 3.→ <<cset 844d4b697980>>
- Log in to comment
Ok, this was caused by the fact that Python 2 does implicit conversion from unicodestrings to bytestrings. Python 3 makes more sense, though.
Ok, I will push a commit that passes all tests, including yours, in Py2.7, Py33 and higher, and Pypy. Thanks again Ivar!
Albert-Jan