Author: jezdez Date: 2011-05-17 03:15:58 -0700 (Tue, 17 May 2011) New Revision: 16232
Modified: django/trunk/tests/regressiontests/humanize/tests.py Log: Updated humanize tests to use the FixedOffset timezone from the utils and removed a bit code smell while I'm here. Modified: django/trunk/tests/regressiontests/humanize/tests.py =================================================================== --- django/trunk/tests/regressiontests/humanize/tests.py 2011-05-15 23:02:36 UTC (rev 16231) +++ django/trunk/tests/regressiontests/humanize/tests.py 2011-05-17 10:15:58 UTC (rev 16232) @@ -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 @@ 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 @@ 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) -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.