]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
tests: Use the automatically chosen Decimal class 272/head
authorIsaac Jurado <diptongo@gmail.com>
Sun, 11 Oct 2015 12:26:04 +0000 (14:26 +0200)
committerIsaac Jurado <diptongo@gmail.com>
Wed, 14 Oct 2015 17:54:12 +0000 (19:54 +0200)
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.

babel/plural.py
tests/test_numbers.py
tests/test_plural.py

index 50bf5418182a58d0779fd1b4ad35239dfbd60962..b5ce9ba654c6141238e8e591f98af28176ba2f39 100644 (file)
@@ -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 ()
index 0d8fa00fcbf1c0d50af0dd666de9b1f11014ca7b..f042833b38875115bca27d7b61e7f45b3391ae87 100644 (file)
 # 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):
index 278b5dba8bcc39fda1981fda19bc7cd8fe4f5422..b0cad8da2cea2860fd456ac728599b07288b94c5 100644 (file)
 # 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)