From 62262be5f2540a520812db410c8a2553a35813d7 Mon Sep 17 00:00:00 2001 From: aniversarioperu Date: Wed, 3 Sep 2014 17:39:53 +0300 Subject: [PATCH 1/3] I created a test file I created a new file for testing the module dataset.freeze.format.fcsv. I wrote a test for the function ``value_to_str``. --- test/test_freeze.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/test_freeze.py diff --git a/test/test_freeze.py b/test/test_freeze.py new file mode 100644 index 0000000..52c94c2 --- /dev/null +++ b/test/test_freeze.py @@ -0,0 +1,17 @@ +# -*- encoding: utf-8 -*- +import unittest +from dataset.freeze.format.fcsv import value_to_str + +from .sample_data import TEST_DATA + + +class FreezeTestCase(unittest.TestCase): + + def test_value_to_str1(self): + assert '2011-01-01T00:00:00' == value_to_str(TEST_DATA[0]['date']) + + def test_value_to_str2(self): + assert 'hóla' == value_to_str(u'\u0068\u00f3\u006c\u0061') + + def test_value_to_str3(self): + assert '' == value_to_str(None) From 1e82be8fd0e132f08a6b22d364d8df1492c1c3cf Mon Sep 17 00:00:00 2001 From: aniversarioperu Date: Thu, 4 Sep 2014 07:02:27 +0300 Subject: [PATCH 2/3] fixed code and test for Python3 --- dataset/freeze/format/fcsv.py | 4 +++- setup.py | 3 ++- test/test_freeze.py | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dataset/freeze/format/fcsv.py b/dataset/freeze/format/fcsv.py index 1d75ee4..eff3fb9 100644 --- a/dataset/freeze/format/fcsv.py +++ b/dataset/freeze/format/fcsv.py @@ -1,13 +1,15 @@ import csv from datetime import datetime +from six import PY3 + from dataset.freeze.format.common import Serializer def value_to_str(value): if isinstance(value, datetime): return value.isoformat() - if hasattr(value, 'encode'): + if not PY3 and hasattr(value, 'encode'): return value.encode('utf-8') if value is None: return '' diff --git a/setup.py b/setup.py index ba6ed1a..8b254d5 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,8 @@ setup( 'sqlalchemy >= 0.9.1', 'alembic >= 0.6.2', 'python-slugify >= 0.0.6', - "PyYAML >= 3.10" + "PyYAML >= 3.10", + "six >= 1.7.3" ] + py26_dependency, tests_require=[], test_suite='test', diff --git a/test/test_freeze.py b/test/test_freeze.py index 52c94c2..10b1bc8 100644 --- a/test/test_freeze.py +++ b/test/test_freeze.py @@ -1,5 +1,8 @@ # -*- encoding: utf-8 -*- import unittest + +from six import PY3 + from dataset.freeze.format.fcsv import value_to_str 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']) 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): assert '' == value_to_str(None) From 5b65693ef883074d7fb3bf3f2f3d7feb5fb89e4d Mon Sep 17 00:00:00 2001 From: aniversarioperu Date: Thu, 4 Sep 2014 09:15:53 +0300 Subject: [PATCH 3/3] full coverage for function value_to_str --- test/test_freeze.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_freeze.py b/test/test_freeze.py index 10b1bc8..e6c5d31 100644 --- a/test/test_freeze.py +++ b/test/test_freeze.py @@ -21,3 +21,6 @@ class FreezeTestCase(unittest.TestCase): def test_value_to_str3(self): assert '' == value_to_str(None) + + def test_value_to_str4(self): + assert [] == value_to_str([])