Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow None as 'default_tzinfo' of DateTime. #6

Merged
merged 1 commit into from
Apr 2, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions colander/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,8 @@ class DateTime(SchemaType):
"""
err_template = _('Invalid date')

def __init__(self, default_tzinfo=None):
if default_tzinfo is None:
def __init__(self, default_tzinfo=_marker):
if default_tzinfo is _marker:
default_tzinfo = iso8601.iso8601.Utc()
self.default_tzinfo = default_tzinfo

Expand Down
15 changes: 15 additions & 0 deletions colander/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,13 @@ def test_serialize_with_naive_datetime(self):
expected = dt.replace(tzinfo=typ.default_tzinfo).isoformat()
self.assertEqual(result, expected)

def test_serialize_with_none_tzinfo_naive_datetime(self):
typ = self._makeOne(default_tzinfo=None)
node = DummySchemaNode(None)
dt = self._dt()
result = typ.serialize(node, dt)
self.assertEqual(result, dt.isoformat())

def test_serialize_with_tzware_datetime(self):
import iso8601
typ = self._makeOne()
Expand Down Expand Up @@ -1324,6 +1331,14 @@ def test_deserialize_naive_with_default_tzinfo(self):
result = typ.deserialize(node, iso)
self.assertEqual(result.isoformat(), dt_with_tz.isoformat())

def test_deserialize_none_tzinfo(self):
typ = self._makeOne(default_tzinfo=None)
dt = self._dt()
iso = dt.isoformat()
node = DummySchemaNode(None)
result = typ.deserialize(node, iso)
self.assertEqual(result.isoformat(), dt.isoformat())

class TestDate(unittest.TestCase):
def _makeOne(self, *arg, **kw):
from colander import Date
Expand Down