summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-11-22 20:04:19 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2013-11-22 20:04:19 -0500
commit6b79d2ea7951abc2bb6083b541db0fbf71590dd3 (patch)
tree4c1edc6856fe743b44e69c1f70750d469b642ed5 /test
parentf112dc1d533033f19186eb65227aba1660d03102 (diff)
downloadsqlalchemy-6b79d2ea7951abc2bb6083b541db0fbf71590dd3.tar.gz
- The precision used when coercing a returned floating point value to
Python ``Decimal`` via string is now configurable. The flag ``decimal_return_scale`` is now supported by all :class:`.Numeric` and :class:`.Float` types, which will ensure this many digits are taken from the native floating point value when it is converted to string. If not present, the type will make use of the value of ``.scale``, if the type supports this setting and it is non-None. Otherwise the original default length of 10 is used. [ticket:2867]
Diffstat (limited to 'test')
-rw-r--r--test/dialect/mysql/test_types.py19
-rw-r--r--test/requirements.py7
2 files changed, 25 insertions, 1 deletions
diff --git a/test/dialect/mysql/test_types.py b/test/dialect/mysql/test_types.py
index ec7b69926..014d29d69 100644
--- a/test/dialect/mysql/test_types.py
+++ b/test/dialect/mysql/test_types.py
@@ -10,7 +10,7 @@ from sqlalchemy.testing import fixtures, AssertsCompiledSQL, AssertsExecutionRes
from sqlalchemy import testing
from sqlalchemy.testing.engines import utf8_engine
import datetime
-
+import decimal
class TypesTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL):
"Test MySQL column types"
@@ -147,6 +147,23 @@ class TypesTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL):
res
)
+ @testing.provide_metadata
+ def test_precision_float_roundtrip(self):
+ t = Table('t', self.metadata,
+ Column('scale_value', mysql.DOUBLE(precision=15, scale=12, asdecimal=True)),
+ Column('unscale_value', mysql.DOUBLE(decimal_return_scale=12, asdecimal=True))
+ )
+ t.create(testing.db)
+ testing.db.execute(
+ t.insert(), scale_value=45.768392065789,
+ unscale_value=45.768392065789
+ )
+ result = testing.db.scalar(select([t.c.scale_value]))
+ eq_(result, decimal.Decimal("45.768392065789"))
+
+ result = testing.db.scalar(select([t.c.unscale_value]))
+ eq_(result, decimal.Decimal("45.768392065789"))
+
@testing.exclude('mysql', '<', (4, 1, 1), 'no charset support')
def test_charset(self):
"""Exercise CHARACTER SET and COLLATE-ish options on string types."""
diff --git a/test/requirements.py b/test/requirements.py
index 4ed0a9289..b6fca06ed 100644
--- a/test/requirements.py
+++ b/test/requirements.py
@@ -541,6 +541,13 @@ class DefaultRequirements(SuiteRequirements):
)
@property
+ def precision_generic_float_type(self):
+ """target backend will return native floating point numbers with at
+ least seven decimal places when using the generic Float type."""
+
+ return fails_if('mysql', 'mysql FLOAT type only returns 4 decimals')
+
+ @property
def floats_to_four_decimals(self):
return fails_if("mysql+oursql", "Floating point error")