Updated humanize tests to use the FixedOffset timezone from the utils and removed a bit code smell while I'm here.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16232 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
66fd824ee0
commit
9ad005ec1c
|
@ -1,46 +1,25 @@
|
|||
from __future__ import with_statement
|
||||
from datetime import timedelta, date, datetime, tzinfo, timedelta
|
||||
from datetime import timedelta, date, datetime, tzinfo
|
||||
|
||||
from django.conf import settings
|
||||
from django.template import Template, Context, add_to_builtins
|
||||
from django.template import Template, Context, add_to_builtins, defaultfilters
|
||||
from django.test import TestCase
|
||||
from django.utils import translation
|
||||
from django.utils.dateformat import DateFormat
|
||||
from django.utils import translation, tzinfo
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.html import escape
|
||||
from django.conf import settings
|
||||
|
||||
add_to_builtins('django.contrib.humanize.templatetags.humanize')
|
||||
|
||||
|
||||
class FixedOffset(tzinfo):
|
||||
"""Fixed offset in hours east from UTC."""
|
||||
|
||||
def __init__(self, offset, name):
|
||||
self.__offset = timedelta(hours=offset)
|
||||
self.__name = name
|
||||
|
||||
def utcoffset(self, dt):
|
||||
return self.__offset
|
||||
|
||||
def tzname(self, dt):
|
||||
return self.__name
|
||||
|
||||
def dst(self, dt):
|
||||
return timedelta(0)
|
||||
|
||||
|
||||
class HumanizeTests(TestCase):
|
||||
|
||||
def humanize_tester(self, test_list, result_list, method):
|
||||
# Using max below ensures we go through both lists
|
||||
# However, if the lists are not equal length, this raises an exception
|
||||
for index in xrange(max(len(test_list), len(result_list))):
|
||||
test_content = test_list[index]
|
||||
for test_content, result in zip(test_list, result_list):
|
||||
t = Template('{{ test_content|%s }}' % method)
|
||||
rendered = t.render(Context(locals())).strip()
|
||||
self.assertEqual(rendered, escape(result_list[index]),
|
||||
msg="%s test failed, produced %s, should've produced %s" % (method, rendered, result_list[index]))
|
||||
self.assertEqual(rendered, escape(result),
|
||||
msg="%s test failed, produced '%s', should've produced '%s'" % (method, rendered, result))
|
||||
|
||||
def test_ordinal(self):
|
||||
test_list = ('1','2','3','4','11','12',
|
||||
|
@ -98,7 +77,6 @@ class HumanizeTests(TestCase):
|
|||
self.humanize_tester(test_list, result_list, 'apnumber')
|
||||
|
||||
def test_naturalday(self):
|
||||
from django.template import defaultfilters
|
||||
today = date.today()
|
||||
yesterday = today - timedelta(days=1)
|
||||
tomorrow = today + timedelta(days=1)
|
||||
|
@ -140,8 +118,8 @@ class HumanizeTests(TestCase):
|
|||
from django.contrib.humanize.templatetags.humanize import naturalday
|
||||
|
||||
today = date.today()
|
||||
tz_one = FixedOffset(-12, 'TzOne')
|
||||
tz_two = FixedOffset(12, 'TzTwo')
|
||||
tz_one = tzinfo.FixedOffset(timedelta(hours=-12))
|
||||
tz_two = tzinfo.FixedOffset(timedelta(hours=12))
|
||||
|
||||
# Can be today or yesterday
|
||||
date_one = datetime(today.year, today.month, today.day, tzinfo=tz_one)
|
||||
|
|
Loading…
Reference in New Issue