Ticket #4976: humainze-none.diff

File humainze-none.diff, 3.3 KB (added by Adam Vandenberg, 14 years ago)

Updated patch to trunk

  • django/contrib/humanize/templatetags/humanize.py

    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):  
    4343    numbers over 1 million. For example, 1000000 becomes '1.0 million', 1200000
    4444    becomes '1.2 million' and '1200000000' becomes '1.2 billion'.
    4545    """
    46     value = int(value)
     46    try:
     47        value = int(value)
     48    except (TypeError, ValueError):
     49        return value
    4750    if value < 1000000:
    4851        return value
    4952    if value < 1000000000:
    def apnumber(value):  
    6669    """
    6770    try:
    6871        value = int(value)
    69     except ValueError:
     72    except (TypeError, ValueError):
    7073        return value
    7174    if not 0 < value < 10:
    7275        return value
  • tests/regressiontests/humanize/tests.py

    diff --git a/tests/regressiontests/humanize/tests.py b/tests/regressiontests/humanize/tests.py
    index e1962ab..7eeaaee 100644
    a b class HumanizeTests(unittest.TestCase):  
    3232
    3333    def test_intcomma(self):
    3434        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)
    3637        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)
    3840
    3941        self.humanize_tester(test_list, result_list, 'intcomma')
    4042
    4143    def test_intword(self):
    4244        test_list = ('100', '1000000', '1200000', '1290000',
    43                      '1000000000','2000000000','6000000000000')
     45                     '1000000000','2000000000','6000000000000',
     46                     None)
    4447        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)
    4650
    4751        self.humanize_tester(test_list, result_list, 'intword')
    4852
    4953    def test_apnumber(self):
    5054        test_list = [str(x) for x in range(1, 11)]
     55        test_list.append(None)
    5156        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)
    5358
    5459        self.humanize_tester(test_list, result_list, 'apnumber')
    5560
    class HumanizeTests(unittest.TestCase):  
    6166        someday = today - timedelta(days=10)
    6267        notdate = u"I'm not a date value"
    6368
    64         test_list = (today, yesterday, tomorrow, someday, notdate)
     69        test_list = (today, yesterday, tomorrow, someday, notdate, None)
    6570        someday_result = defaultfilters.date(someday)
    6671        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)
    6873        self.humanize_tester(test_list, result_list, 'naturalday')
    6974
    7075if __name__ == '__main__':
Back to Top