Fixed #12123 -- Updated the utils.dateformat test to be a unittest too, due to a dependency on the old dateformat test.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11695 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2009-11-01 04:53:51 +00:00
parent acfa9332de
commit e18af06eed
2 changed files with 38 additions and 43 deletions

View File

@ -1,48 +1,42 @@
""" import os
>>> from datetime import datetime, date from unittest import TestCase
>>> from django.utils.dateformat import format from datetime import datetime, date
>>> from django.utils.tzinfo import FixedOffset, LocalTimezone from django.utils.dateformat import format
from django.utils.tzinfo import FixedOffset, LocalTimezone
# date class DateFormatTests(TestCase):
>>> d = date(2009, 5, 16) def setUp(self):
>>> date.fromtimestamp(int(format(d, 'U'))) == d self.old_TZ = os.environ['TZ']
True os.environ['TZ'] = 'Europe/Copenhagen'
# Naive datetime def tearDown(self):
>>> dt = datetime(2009, 5, 16, 5, 30, 30) os.environ['TZ'] = self.old_TZ
>>> datetime.fromtimestamp(int(format(dt, 'U'))) == dt
True
# datetime with local tzinfo def test_date(self):
>>> ltz = LocalTimezone(datetime.now()) d = date(2009, 5, 16)
>>> dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=ltz) self.assertEquals(date.fromtimestamp(int(format(d, 'U'))), d)
>>> datetime.fromtimestamp(int(format(dt, 'U')), ltz) == dt
True
>>> datetime.fromtimestamp(int(format(dt, 'U'))) == dt.replace(tzinfo=None)
True
# datetime with arbitrary tzinfo def test_naive_datetime(self):
>>> tz = FixedOffset(-510) dt = datetime(2009, 5, 16, 5, 30, 30)
>>> ltz = LocalTimezone(datetime.now()) self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U'))), dt)
>>> dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=tz)
>>> datetime.fromtimestamp(int(format(dt, 'U')), tz) == dt
True
>>> datetime.fromtimestamp(int(format(dt, 'U')), ltz) == dt
True
>>> datetime.fromtimestamp(int(format(dt, 'U'))) == dt.astimezone(ltz).replace(tzinfo=None)
True
>>> datetime.fromtimestamp(int(format(dt, 'U')), tz).utctimetuple() == dt.utctimetuple()
True
>>> datetime.fromtimestamp(int(format(dt, 'U')), ltz).utctimetuple() == dt.utctimetuple()
True
# Epoch def test_datetime_with_local_tzinfo(self):
>>> utc = FixedOffset(0) ltz = LocalTimezone(datetime.now())
>>> udt = datetime(1970, 1, 1, tzinfo=utc) dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=ltz)
>>> format(udt, 'U') self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), ltz), dt)
u'0' self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U'))), dt.replace(tzinfo=None))
"""
if __name__ == "__main__": def test_datetime_with_tzinfo(self):
import doctest tz = FixedOffset(-510)
doctest.testmod() ltz = LocalTimezone(datetime.now())
dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=tz)
self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), tz), dt)
self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), ltz), dt)
self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U'))), dt.astimezone(ltz).replace(tzinfo=None))
self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), tz).utctimetuple(), dt.utctimetuple())
self.assertEquals(datetime.fromtimestamp(int(format(dt, 'U')), ltz).utctimetuple(), dt.utctimetuple())
def test_epoch(self):
utc = FixedOffset(0)
udt = datetime(1970, 1, 1, tzinfo=utc)
self.assertEquals(format(udt, 'U'), u'0')

View File

@ -24,10 +24,11 @@ except NameError:
__test__ = { __test__ = {
'timesince': timesince, 'timesince': timesince,
'datastructures': datastructures, 'datastructures': datastructures,
'dateformat': dateformat,
'itercompat': itercompat, 'itercompat': itercompat,
} }
from dateformat import *
class TestUtilsHtml(TestCase): class TestUtilsHtml(TestCase):
def check_output(self, function, value, output=None): def check_output(self, function, value, output=None):