1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007 Edgewall Software
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://babel.edgewall.org/wiki/License.
#
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://babel.edgewall.org/log/.
import doctest
import unittest
from babel import numbers
class FormatDecimalTestCase(unittest.TestCase):
def test_subpatterns(self):
self.assertEqual(numbers.format_decimal(-12345, '#,##0.##;-#',
locale='en_US'), '-12,345')
self.assertEqual(numbers.format_decimal(-12345, '#,##0.##;(#)',
locale='en_US'), '(12,345)')
def test_default_rounding(self):
"""
Testing Round-Half-Even (Banker's rounding)
A '5' is rounded to the closest 'even' number
"""
self.assertEqual(numbers.format_decimal(5.5, '0', locale='sv'), '6')
self.assertEqual(numbers.format_decimal(6.5, '0', locale='sv'), '6')
self.assertEqual(numbers.format_decimal(1.2325, locale='sv'), '1,232')
self.assertEqual(numbers.format_decimal(1.2335, locale='sv'), '1,234')
def suite():
suite = unittest.TestSuite()
suite.addTest(doctest.DocTestSuite(numbers))
suite.addTest(unittest.makeSuite(FormatDecimalTestCase))
return suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')
|