fixed code and test for Python3
This commit is contained in:
parent
62262be5f2
commit
1e82be8fd0
@ -1,13 +1,15 @@
|
|||||||
import csv
|
import csv
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from six import PY3
|
||||||
|
|
||||||
from dataset.freeze.format.common import Serializer
|
from dataset.freeze.format.common import Serializer
|
||||||
|
|
||||||
|
|
||||||
def value_to_str(value):
|
def value_to_str(value):
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
return value.isoformat()
|
return value.isoformat()
|
||||||
if hasattr(value, 'encode'):
|
if not PY3 and hasattr(value, 'encode'):
|
||||||
return value.encode('utf-8')
|
return value.encode('utf-8')
|
||||||
if value is None:
|
if value is None:
|
||||||
return ''
|
return ''
|
||||||
|
|||||||
3
setup.py
3
setup.py
@ -33,7 +33,8 @@ setup(
|
|||||||
'sqlalchemy >= 0.9.1',
|
'sqlalchemy >= 0.9.1',
|
||||||
'alembic >= 0.6.2',
|
'alembic >= 0.6.2',
|
||||||
'python-slugify >= 0.0.6',
|
'python-slugify >= 0.0.6',
|
||||||
"PyYAML >= 3.10"
|
"PyYAML >= 3.10",
|
||||||
|
"six >= 1.7.3"
|
||||||
] + py26_dependency,
|
] + py26_dependency,
|
||||||
tests_require=[],
|
tests_require=[],
|
||||||
test_suite='test',
|
test_suite='test',
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from six import PY3
|
||||||
|
|
||||||
from dataset.freeze.format.fcsv import value_to_str
|
from dataset.freeze.format.fcsv import value_to_str
|
||||||
|
|
||||||
from .sample_data import TEST_DATA
|
from .sample_data import TEST_DATA
|
||||||
@ -11,7 +14,10 @@ class FreezeTestCase(unittest.TestCase):
|
|||||||
assert '2011-01-01T00:00:00' == value_to_str(TEST_DATA[0]['date'])
|
assert '2011-01-01T00:00:00' == value_to_str(TEST_DATA[0]['date'])
|
||||||
|
|
||||||
def test_value_to_str2(self):
|
def test_value_to_str2(self):
|
||||||
assert 'hóla' == value_to_str(u'\u0068\u00f3\u006c\u0061')
|
if PY3:
|
||||||
|
assert 'hóla' == value_to_str('\u0068\u00f3\u006c\u0061')
|
||||||
|
else:
|
||||||
|
assert 'hóla' == value_to_str(u'\u0068\u00f3\u006c\u0061')
|
||||||
|
|
||||||
def test_value_to_str3(self):
|
def test_value_to_str3(self):
|
||||||
assert '' == value_to_str(None)
|
assert '' == value_to_str(None)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user