diff options
author | Changaco <changaco@changaco.oy.lc> | 2018-06-17 09:55:02 +0200 |
---|---|---|
committer | Changaco <changaco@changaco.oy.lc> | 2018-06-17 10:46:54 +0200 |
commit | b5f6f362440faf862ea887a4157252874c59d910 (patch) | |
tree | 8daae8a99bea528785698c2c228dbc88546582fa /tests | |
parent | 6bf8745f6a913af71357583e8e97116fcfd444ca (diff) | |
download | babel-b5f6f362440faf862ea887a4157252874c59d910.tar.gz |
add a `suggestions` attribute to `NumberFormatError`
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_numbers.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/tests/test_numbers.py b/tests/test_numbers.py index b9dcb72..9c3896c 100644 --- a/tests/test_numbers.py +++ b/tests/test_numbers.py @@ -167,17 +167,21 @@ class NumberParsingTestCase(unittest.TestCase): def test_parse_decimal_strict_mode(self): # Numbers with a misplaced grouping symbol should be rejected - with self.assertRaises(numbers.NumberFormatError): + with self.assertRaises(numbers.NumberFormatError) as info: numbers.parse_decimal('11.11', locale='de', strict=True) + assert info.exception.suggestions == ['1.111', '11,11'] # Numbers with two misplaced grouping symbols should be rejected - with self.assertRaises(numbers.NumberFormatError): + with self.assertRaises(numbers.NumberFormatError) as info: numbers.parse_decimal('80.00.00', locale='de', strict=True) + assert info.exception.suggestions == ['800.000'] # Partially grouped numbers should be rejected - with self.assertRaises(numbers.NumberFormatError): + with self.assertRaises(numbers.NumberFormatError) as info: numbers.parse_decimal('2000,000', locale='en_US', strict=True) + assert info.exception.suggestions == ['2,000,000', '2,000'] # Numbers with duplicate grouping symbols should be rejected - with self.assertRaises(numbers.NumberFormatError): + with self.assertRaises(numbers.NumberFormatError) as info: numbers.parse_decimal('0,,000', locale='en_US', strict=True) + assert info.exception.suggestions == ['0'] # Properly formatted numbers should be accepted assert str(numbers.parse_decimal('1.001', locale='de', strict=True)) == '1001' # Trailing zeroes should be accepted |