diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-11-22 20:04:19 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-11-22 20:04:19 -0500 |
| commit | 6b79d2ea7951abc2bb6083b541db0fbf71590dd3 (patch) | |
| tree | 4c1edc6856fe743b44e69c1f70750d469b642ed5 /test/dialect | |
| parent | f112dc1d533033f19186eb65227aba1660d03102 (diff) | |
| download | sqlalchemy-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/dialect')
| -rw-r--r-- | test/dialect/mysql/test_types.py | 19 |
1 files changed, 18 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.""" |
