Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Jannis Leidel authored

Showing 1 changed file with 8 additions and 30 deletions. Show diff stats Hide diff stats

  1. 38  tests/regressiontests/humanize/tests.py
38  tests/regressiontests/humanize/tests.py
... ...
@@ -1,46 +1,25 @@
1 1
 from __future__ import with_statement
2  
-from datetime import timedelta, date, datetime, tzinfo, timedelta
  2
+from datetime import timedelta, date, datetime, tzinfo
3 3
 
4  
-from django.conf import settings
5  
-from django.template import Template, Context, add_to_builtins
  4
+from django.template import Template, Context, add_to_builtins, defaultfilters
6 5
 from django.test import TestCase
7  
-from django.utils import translation
8  
-from django.utils.dateformat import DateFormat
  6
+from django.utils import translation, tzinfo
9 7
 from django.utils.translation import ugettext as _
10 8
 from django.utils.html import escape
11  
-from django.conf import settings
12 9
 
13 10
 add_to_builtins('django.contrib.humanize.templatetags.humanize')
14 11
 
15 12
 
16  
-class FixedOffset(tzinfo):
17  
-    """Fixed offset in hours east from UTC."""
18  
-
19  
-    def __init__(self, offset, name):
20  
-        self.__offset = timedelta(hours=offset)
21  
-        self.__name = name
22  
-
23  
-    def utcoffset(self, dt):
24  
-        return self.__offset
25  
-
26  
-    def tzname(self, dt):
27  
-        return self.__name
28  
-
29  
-    def dst(self, dt):
30  
-        return timedelta(0)
31  
-
32  
-
33 13
 class HumanizeTests(TestCase):
34 14
 
35 15
     def humanize_tester(self, test_list, result_list, method):
36 16
         # Using max below ensures we go through both lists
37 17
         # However, if the lists are not equal length, this raises an exception
38  
-        for index in xrange(max(len(test_list), len(result_list))):
39  
-            test_content = test_list[index]
  18
+        for test_content, result in zip(test_list, result_list):
40 19
             t = Template('{{ test_content|%s }}' % method)
41 20
             rendered = t.render(Context(locals())).strip()
42  
-            self.assertEqual(rendered, escape(result_list[index]),
43  
-                             msg="%s test failed, produced %s, should've produced %s" % (method, rendered, result_list[index]))
  21
+            self.assertEqual(rendered, escape(result),
  22
+                             msg="%s test failed, produced '%s', should've produced '%s'" % (method, rendered, result))
44 23
 
45 24
     def test_ordinal(self):
46 25
         test_list = ('1','2','3','4','11','12',
@@ -98,7 +77,6 @@ def test_apnumber(self):
98 77
         self.humanize_tester(test_list, result_list, 'apnumber')
99 78
 
100 79
     def test_naturalday(self):
101  
-        from django.template import defaultfilters
102 80
         today = date.today()
103 81
         yesterday = today - timedelta(days=1)
104 82
         tomorrow = today + timedelta(days=1)
@@ -140,8 +118,8 @@ def test_naturalday_tz(self):
140 118
         from django.contrib.humanize.templatetags.humanize import naturalday
141 119
 
142 120
         today = date.today()
143  
-        tz_one = FixedOffset(-12, 'TzOne')
144  
-        tz_two = FixedOffset(12, 'TzTwo')
  121
+        tz_one = tzinfo.FixedOffset(timedelta(hours=-12))
  122
+        tz_two = tzinfo.FixedOffset(timedelta(hours=12))
145 123
 
146 124
         # Can be today or yesterday
147 125
         date_one = datetime(today.year, today.month, today.day, tzinfo=tz_one)

0 notes on commit 9ad005e

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