Django

Code

Show
Ignore:
Timestamp:
08/20/07 03:50:08 (1 year ago)
Author:
mtredinnick
Message:

Fixed #3311 -- Added naturalday filter to contrib.humanize. Thanks, Jyrki Pulliainen.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/regressiontests/humanize/tests.py

    r5876 r5985  
    11import unittest 
     2from datetime import timedelta, date 
    23from django.template import Template, Context, add_to_builtins 
     4from django.utils.dateformat import DateFormat 
     5from django.utils.translation import ugettext as _ 
    36 
    47add_to_builtins('django.contrib.humanize.templatetags.humanize') 
     
    912        # Using max below ensures we go through both lists 
    1013        # However, if the lists are not equal length, this raises an exception 
    11         for index in xrange(len(max(test_list,result_list))): 
     14        for index in xrange(max(len(test_list), len(result_list))): 
    1215            test_content = test_list[index] 
    1316            t = Template('{{ test_content|%s }}' % method) 
    1417            rendered = t.render(Context(locals())).strip() 
    1518            self.assertEqual(rendered, result_list[index], 
    16                              msg="""%s test failed, produced %s, 
    17 should've produced %s""" % (method, rendered, result_list[index])) 
     19                             msg="%s test failed, produced %s, should've produced %s" % (method, rendered, result_list[index])) 
    1820 
    1921    def test_ordinal(self): 
     
    5052        self.humanize_tester(test_list, result_list, 'apnumber') 
    5153 
     54    def test_naturalday(self): 
     55        from django.template import defaultfilters 
     56        today = date.today() 
     57        yesterday = today - timedelta(days=1) 
     58        tomorrow = today + timedelta(days=1) 
     59        someday = today - timedelta(days=10) 
     60        notdate = u"I'm not a date value" 
     61 
     62        test_list = (today, yesterday, tomorrow, someday, notdate) 
     63        someday_result = defaultfilters.date(someday) 
     64        result_list = (_(u'today'), _(u'yesterday'), _(u'tomorrow'), 
     65                       someday_result, u"I'm not a date value") 
     66        self.humanize_tester(test_list, result_list, 'naturalday') 
     67 
    5268if __name__ == '__main__': 
    5369    unittest.main()