diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py
index 3e19fed..cfa93fe 100644
|
a
|
b
|
def intword(value):
|
| 43 | 43 | numbers over 1 million. For example, 1000000 becomes '1.0 million', 1200000 |
| 44 | 44 | becomes '1.2 million' and '1200000000' becomes '1.2 billion'. |
| 45 | 45 | """ |
| 46 | | value = int(value) |
| | 46 | try: |
| | 47 | value = int(value) |
| | 48 | except (TypeError, ValueError): |
| | 49 | return value |
| 47 | 50 | if value < 1000000: |
| 48 | 51 | return value |
| 49 | 52 | if value < 1000000000: |
| … |
… |
def apnumber(value):
|
| 66 | 69 | """ |
| 67 | 70 | try: |
| 68 | 71 | value = int(value) |
| 69 | | except ValueError: |
| | 72 | except (TypeError, ValueError): |
| 70 | 73 | return value |
| 71 | 74 | if not 0 < value < 10: |
| 72 | 75 | return value |
diff --git a/tests/regressiontests/humanize/tests.py b/tests/regressiontests/humanize/tests.py
index e1962ab..7eeaaee 100644
|
a
|
b
|
class HumanizeTests(unittest.TestCase):
|
| 32 | 32 | |
| 33 | 33 | def test_intcomma(self): |
| 34 | 34 | test_list = (100, 1000, 10123, 10311, 1000000, 1234567.25, |
| 35 | | '100', '1000', '10123', '10311', '1000000', '1234567.1234567') |
| | 35 | '100', '1000', '10123', '10311', '1000000', '1234567.1234567', |
| | 36 | None) |
| 36 | 37 | result_list = ('100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.25', |
| 37 | | '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567') |
| | 38 | '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567', |
| | 39 | None) |
| 38 | 40 | |
| 39 | 41 | self.humanize_tester(test_list, result_list, 'intcomma') |
| 40 | 42 | |
| 41 | 43 | def test_intword(self): |
| 42 | 44 | test_list = ('100', '1000000', '1200000', '1290000', |
| 43 | | '1000000000','2000000000','6000000000000') |
| | 45 | '1000000000','2000000000','6000000000000', |
| | 46 | None) |
| 44 | 47 | result_list = ('100', '1.0 million', '1.2 million', '1.3 million', |
| 45 | | '1.0 billion', '2.0 billion', '6.0 trillion') |
| | 48 | '1.0 billion', '2.0 billion', '6.0 trillion', |
| | 49 | None) |
| 46 | 50 | |
| 47 | 51 | self.humanize_tester(test_list, result_list, 'intword') |
| 48 | 52 | |
| 49 | 53 | def test_apnumber(self): |
| 50 | 54 | test_list = [str(x) for x in range(1, 11)] |
| | 55 | test_list.append(None) |
| 51 | 56 | result_list = (u'one', u'two', u'three', u'four', u'five', u'six', |
| 52 | | u'seven', u'eight', u'nine', u'10') |
| | 57 | u'seven', u'eight', u'nine', u'10', None) |
| 53 | 58 | |
| 54 | 59 | self.humanize_tester(test_list, result_list, 'apnumber') |
| 55 | 60 | |
| … |
… |
class HumanizeTests(unittest.TestCase):
|
| 61 | 66 | someday = today - timedelta(days=10) |
| 62 | 67 | notdate = u"I'm not a date value" |
| 63 | 68 | |
| 64 | | test_list = (today, yesterday, tomorrow, someday, notdate) |
| | 69 | test_list = (today, yesterday, tomorrow, someday, notdate, None) |
| 65 | 70 | someday_result = defaultfilters.date(someday) |
| 66 | 71 | result_list = (_(u'today'), _(u'yesterday'), _(u'tomorrow'), |
| 67 | | someday_result, u"I'm not a date value") |
| | 72 | someday_result, u"I'm not a date value", None) |
| 68 | 73 | self.humanize_tester(test_list, result_list, 'naturalday') |
| 69 | 74 | |
| 70 | 75 | if __name__ == '__main__': |