From: Isaac Jurado Date: Sun, 11 Oct 2015 12:26:04 +0000 (+0200) Subject: tests: Use the automatically chosen Decimal class X-Git-Tag: dev-2a51c9b95d06~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe77bb3e66a7838b119e6b8ca92c2e0396ed84dd;p=thirdparty%2Fbabel.git tests: Use the automatically chosen Decimal class Now that the babel._compat module can automatically select a faster decimal implementation if available, be more consistent across the rest of the code when dealing with Decimal instances. --- diff --git a/babel/plural.py b/babel/plural.py index 50bf5418..b5ce9ba6 100644 --- a/babel/plural.py +++ b/babel/plural.py @@ -8,10 +8,11 @@ :copyright: (c) 2013 by the Babel Team. :license: BSD, see LICENSE for more details. """ -import decimal import re import sys +from babel._compat import Decimal + _plural_tags = ('zero', 'one', 'two', 'few', 'many', 'other') _fallback_tag = 'other' @@ -32,9 +33,9 @@ def extract_operands(source): # 2.6's Decimal cannot convert from float directly if sys.version_info < (2, 7): n = str(n) - n = decimal.Decimal(n) + n = Decimal(n) - if isinstance(n, decimal.Decimal): + if isinstance(n, Decimal): dec_tuple = n.as_tuple() exp = dec_tuple.exponent fraction_digits = dec_tuple.digits[exp:] if exp < 0 else () diff --git a/tests/test_numbers.py b/tests/test_numbers.py index 0d8fa00f..f042833b 100644 --- a/tests/test_numbers.py +++ b/tests/test_numbers.py @@ -11,13 +11,13 @@ # individuals. For the exact contribution history, see the revision # history and logs, available at http://babel.edgewall.org/log/. -from decimal import Decimal import unittest import pytest from datetime import date from babel import numbers +from babel._compat import Decimal class FormatDecimalTestCase(unittest.TestCase): diff --git a/tests/test_plural.py b/tests/test_plural.py index 278b5dba..b0cad8da 100644 --- a/tests/test_plural.py +++ b/tests/test_plural.py @@ -10,10 +10,11 @@ # 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 decimal import unittest import pytest + from babel import plural +from babel._compat import Decimal def test_plural_rule(): @@ -33,29 +34,29 @@ def test_plural_rule_operands_i(): def test_plural_rule_operands_v(): rule = plural.PluralRule({'one': 'v is 2'}) - assert rule(decimal.Decimal('1.20')) == 'one' - assert rule(decimal.Decimal('1.2')) == 'other' + assert rule(Decimal('1.20')) == 'one' + assert rule(Decimal('1.2')) == 'other' assert rule(2) == 'other' def test_plural_rule_operands_w(): rule = plural.PluralRule({'one': 'w is 2'}) - assert rule(decimal.Decimal('1.23')) == 'one' - assert rule(decimal.Decimal('1.20')) == 'other' + assert rule(Decimal('1.23')) == 'one' + assert rule(Decimal('1.20')) == 'other' assert rule(1.2) == 'other' def test_plural_rule_operands_f(): rule = plural.PluralRule({'one': 'f is 20'}) - assert rule(decimal.Decimal('1.23')) == 'other' - assert rule(decimal.Decimal('1.20')) == 'one' + assert rule(Decimal('1.23')) == 'other' + assert rule(Decimal('1.20')) == 'one' assert rule(1.2) == 'other' def test_plural_rule_operands_t(): rule = plural.PluralRule({'one': 't = 5'}) - assert rule(decimal.Decimal('1.53')) == 'other' - assert rule(decimal.Decimal('1.50')) == 'one' + assert rule(Decimal('1.53')) == 'other' + assert rule(Decimal('1.50')) == 'one' assert rule(1.5) == 'one' @@ -250,6 +251,6 @@ EXTRACT_OPERANDS_TESTS = ( @pytest.mark.parametrize('source,n,i,v,w,f,t', EXTRACT_OPERANDS_TESTS) def test_extract_operands(source, n, i, v, w, f, t): - source = decimal.Decimal(source) if isinstance(source, str) else source + source = Decimal(source) if isinstance(source, str) else source assert (plural.extract_operands(source) == - decimal.Decimal(n), i, v, w, f, t) + Decimal(n), i, v, w, f, t)