|
@@ -1,10 +1,13 @@
|
|
from datetime import timedelta, date, datetime, tzinfo, timedelta
|
|
from datetime import timedelta, date, datetime, tzinfo, timedelta
|
|
|
|
|
|
|
|
+from django.conf import settings
|
|
from django.template import Template, Context, add_to_builtins
|
|
from django.template import Template, Context, add_to_builtins
|
|
-from django.utils import unittest
|
|
|
|
|
|
+from django.test import TestCase
|
|
|
|
+from django.utils import translation
|
|
from django.utils.dateformat import DateFormat
|
|
from django.utils.dateformat import DateFormat
|
|
from django.utils.translation import ugettext as _
|
|
from django.utils.translation import ugettext as _
|
|
from django.utils.html import escape
|
|
from django.utils.html import escape
|
|
|
|
+from django.conf import settings
|
|
|
|
|
|
add_to_builtins('django.contrib.humanize.templatetags.humanize')
|
|
add_to_builtins('django.contrib.humanize.templatetags.humanize')
|
|
|
|
|
|
@@ -26,7 +29,7 @@ class FixedOffset(tzinfo):
|
|
return timedelta(0)
|
|
return timedelta(0)
|
|
|
|
|
|
|
|
|
|
-class HumanizeTests(unittest.TestCase):
|
|
|
|
|
|
+class HumanizeTests(TestCase):
|
|
|
|
|
|
def humanize_tester(self, test_list, result_list, method):
|
|
def humanize_tester(self, test_list, result_list, method):
|
|
# Using max below ensures we go through both lists
|
|
# Using max below ensures we go through both lists
|
|
@@ -60,14 +63,31 @@ class HumanizeTests(unittest.TestCase):
|
|
|
|
|
|
def test_intword(self):
|
|
def test_intword(self):
|
|
test_list = ('100', '1000000', '1200000', '1290000',
|
|
test_list = ('100', '1000000', '1200000', '1290000',
|
|
- '1000000000','2000000000','6000000000000',
|
|
|
|
|
|
+ '1000000000', '2000000000', '6000000000000',
|
|
None)
|
|
None)
|
|
result_list = ('100', '1.0 million', '1.2 million', '1.3 million',
|
|
result_list = ('100', '1.0 million', '1.2 million', '1.3 million',
|
|
'1.0 billion', '2.0 billion', '6.0 trillion',
|
|
'1.0 billion', '2.0 billion', '6.0 trillion',
|
|
None)
|
|
None)
|
|
-
|
|
|
|
self.humanize_tester(test_list, result_list, 'intword')
|
|
self.humanize_tester(test_list, result_list, 'intword')
|
|
|
|
|
|
|
|
+ def test_i18n_intcomma(self):
|
|
|
|
+ test_list = (100, 1000, 10123, 10311, 1000000, 1234567.25,
|
|
|
|
+ '100', '1000', '10123', '10311', '1000000', None)
|
|
|
|
+ result_list = ('100', '1.000', '10.123', '10.311', '1.000.000', '1.234.567,25',
|
|
|
|
+ '100', '1.000', '10.123', '10.311', '1.000.000', None)
|
|
|
|
+ with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True):
|
|
|
|
+ with translation.override('de'):
|
|
|
|
+ self.humanize_tester(test_list, result_list, 'intcomma')
|
|
|
|
+
|
|
|
|
+ def test_i18n_intword(self):
|
|
|
|
+ test_list = ('100', '1000000', '1200000', '1290000',
|
|
|
|
+ '1000000000','2000000000','6000000000000')
|
|
|
|
+ result_list = ('100', '1,0 Million', '1,2 Millionen', '1,3 Millionen',
|
|
|
|
+ '1,0 Milliarde', '2,0 Milliarden', '6,0 Billionen')
|
|
|
|
+ with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True):
|
|
|
|
+ with translation.override('de'):
|
|
|
|
+ self.humanize_tester(test_list, result_list, 'intword')
|
|
|
|
+
|
|
def test_apnumber(self):
|
|
def test_apnumber(self):
|
|
test_list = [str(x) for x in range(1, 11)]
|
|
test_list = [str(x) for x in range(1, 11)]
|
|
test_list.append(None)
|
|
test_list.append(None)
|