Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #3518: Added unit tests for the humanize filters. Major thanks …

…to Jyrki Pulliainen for the tests.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4571 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a0157da26f143c2b78e98837d1ef5501beaba776 1 parent 8546521
Jacob Kaplan-Moss authored February 25, 2007
0  tests/regressiontests/humanize/__init__.py
No changes.
0  tests/regressiontests/humanize/models.py
No changes.
52  tests/regressiontests/humanize/tests.py
... ...
@@ -0,0 +1,52 @@
  1
+import unittest
  2
+from django.template import Template, Context, add_to_builtins
  3
+
  4
+add_to_builtins('django.contrib.humanize.templatetags.humanize')
  5
+
  6
+class HumanizeTests(unittest.TestCase):
  7
+
  8
+    def humanize_tester(self, test_list, result_list, method):
  9
+        # Using max below ensures we go through both lists
  10
+        # However, if the lists are not equal length, this raises an exception
  11
+        for index in xrange(len(max(test_list,result_list))):
  12
+            test_content = test_list[index]
  13
+            t = Template('{{ test_content|%s }}' % method)
  14
+            rendered = t.render(Context(locals())).strip()
  15
+            self.assertEqual(rendered, result_list[index],
  16
+                             msg="""%s test failed, produced %s,
  17
+should've produced %s""" % (method, rendered, result_list[index]))
  18
+    
  19
+    def test_ordinal(self):
  20
+        test_list = ('1','2','3','4','11','12',
  21
+                     '13','101','102','103','111',
  22
+                     'something else')
  23
+        result_list = ('1st', '2nd', '3rd', '4th', '11th',
  24
+                       '12th', '13th', '101st', '102nd', '103rd',
  25
+                       '111th', 'something else')
  26
+
  27
+        self.humanize_tester(test_list, result_list, 'ordinal')
  28
+
  29
+    def test_intcomma(self):
  30
+        test_list = ('100','1000','10123','10311','1000000')
  31
+        result_list = ('100', '1,000', '10,123', '10,311', '1,000,000')
  32
+
  33
+        self.humanize_tester(test_list, result_list, 'intcomma')
  34
+
  35
+    def test_intword(self):
  36
+        test_list = ('100', '1000000', '1200000', '1290000',
  37
+                     '1000000000','2000000000','6000000000000')
  38
+        result_list = ('100', '1.0 million', '1.2 million', '1.3 million',
  39
+                       '1.0 billion', '2.0 billion', '6.0 trillion')
  40
+
  41
+        self.humanize_tester(test_list, result_list, 'intword')
  42
+
  43
+    def test_apnumber(self):
  44
+        test_list = [str(x) for x in xrange(1,11)]
  45
+        result_list = ('one', 'two', 'three', 'four', 'five', 'six',
  46
+                       'seven', 'eight', 'nine', '10')
  47
+
  48
+        self.humanize_tester(test_list, result_list, 'apnumber')
  49
+
  50
+if __name__ == '__main__':
  51
+    unittest.main()
  52
+    

0 notes on commit a0157da

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