Code

Ticket #3518: humanize_tests_r4537.diff

File humanize_tests_r4537.diff, 2.6 KB (added by Jyrki Pulliainen <jyrki.pulliainen@…>, 7 years ago)
Line 
1Index: regressiontests/humanize/__init__.py
2===================================================================
3Index: regressiontests/humanize/tests.py
4===================================================================
5--- regressiontests/humanize/tests.py   (revision 0)
6+++ regressiontests/humanize/tests.py   (revision 0)
7@@ -0,0 +1,52 @@
8+import unittest
9+from django.template import Template, Context, add_to_builtins
10+
11+add_to_builtins('django.contrib.humanize.templatetags.humanize')
12+
13+class HumanizeTests(unittest.TestCase):
14+
15+    def humanize_tester(self, test_list, result_list, method):
16+        # Using max below ensures we go through both lists
17+        # However, if the lists are not equal length, this raises an exception
18+        for index in xrange(len(max(test_list,result_list))):
19+            test_content = test_list[index]
20+            t = Template('{{ test_content|%s }}' % method)
21+            rendered = t.render(Context(locals())).strip()
22+            self.assertEqual(rendered, result_list[index],
23+                             msg="""%s test failed, produced %s,
24+should've produced %s""" % (method, rendered, result_list[index]))
25+   
26+    def test_ordinal(self):
27+        test_list = ('1','2','3','4','11','12',
28+                     '13','101','102','103','111',
29+                     'something else')
30+        result_list = ('1st', '2nd', '3rd', '4th', '11th',
31+                       '12th', '13th', '101st', '102nd', '103rd',
32+                       '111th', 'something else')
33+
34+        self.humanize_tester(test_list, result_list, 'ordinal')
35+
36+    def test_intcomma(self):
37+        test_list = ('100','1000','10123','10311','1000000')
38+        result_list = ('100', '1,000', '10,123', '10,311', '1,000,000')
39+
40+        self.humanize_tester(test_list, result_list, 'intcomma')
41+
42+    def test_intword(self):
43+        test_list = ('100', '1000000', '1200000', '1290000',
44+                     '1000000000','2000000000','6000000000000')
45+        result_list = ('100', '1.0 million', '1.2 million', '1.3 million',
46+                       '1.0 billion', '2.0 billion', '6.0 trillion')
47+
48+        self.humanize_tester(test_list, result_list, 'intword')
49+
50+    def test_apnumber(self):
51+        test_list = [str(x) for x in xrange(1,11)]
52+        result_list = ('one', 'two', 'three', 'four', 'five', 'six',
53+                       'seven', 'eight', 'nine', '10')
54+
55+        self.humanize_tester(test_list, result_list, 'apnumber')
56+
57+if __name__ == '__main__':
58+    unittest.main()
59+   
60Index: regressiontests/humanize/models.py
61===================================================================