Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 9ad005ec1c50e254dd61bbb1760c524aa01a79e2 1 parent 66fd824
@jezdez jezdez authored
Showing with 8 additions and 30 deletions.
  1. +8 −30 tests/regressiontests/humanize/tests.py
View
38 tests/regressiontests/humanize/tests.py
@@ -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 @@ def test_apnumber(self):
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 @@ def test_naturalday_tz(self):
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)

0 comments on commit 9ad005e

Please sign in to comment.
Something went wrong with that request. Please try again.