Ticket #11321: 11321-r11173-test.diff
File 11321-r11173-test.diff, 2.2 KB (added by , 15 years ago) |
---|
-
tests/regressiontests/humanize/timezone.py
1 from datetime import tzinfo, timedelta 2 3 class FixedOffset(tzinfo): 4 """Fixed offset in hours east from UTC.""" 5 6 def __init__(self, offset, name): 7 self.__offset = timedelta(hours=offset) 8 self.__name = name 9 10 def utcoffset(self, dt): 11 return self.__offset 12 13 def tzname(self, dt): 14 return self.__name 15 16 def dst(self, dt): 17 return timedelta(0) -
tests/regressiontests/humanize/tests.py
59 59 tomorrow = today + timedelta(days=1) 60 60 someday = today - timedelta(days=10) 61 61 notdate = u"I'm not a date value" 62 62 63 63 test_list = (today, yesterday, tomorrow, someday, notdate) 64 64 someday_result = defaultfilters.date(someday) 65 65 result_list = (_(u'today'), _(u'yesterday'), _(u'tomorrow'), 66 66 someday_result, u"I'm not a date value") 67 67 self.humanize_tester(test_list, result_list, 'naturalday') 68 69 def test_naturalday_tz(self): 70 from datetime import datetime 71 from django.contrib.humanize.templatetags.humanize import naturalday 72 from timezone import FixedOffset 73 74 today = date.today() 75 76 tz_one = FixedOffset(-12, 'TzOne') 77 tz_two = FixedOffset(12, 'TzTwo') 68 78 79 # Can be today or yesterday 80 date_one = datetime(today.year, today.month, today.day, tzinfo=tz_one) 81 naturalday_one = naturalday(date_one) 82 # Can be today or tomorrow 83 date_two = datetime(today.year, today.month, today.day, tzinfo=tz_two) 84 naturalday_two = naturalday(date_two) 85 86 # As 24h of difference they will never be the same 87 self.assertNotEqual(naturalday_one, naturalday_two) 88 69 89 if __name__ == '__main__': 70 90 unittest.main() 71 91