From: Mike Bayer Date: Wed, 8 Dec 2010 19:31:45 +0000 (-0500) Subject: - add test coverage for what DBAPIs give us raw for numerics X-Git-Tag: rel_0_7b1~189 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d5d0bbd83eba94f45d3d5f62b57b681a9947a5e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - add test coverage for what DBAPIs give us raw for numerics --- diff --git a/test/sql/test_types.py b/test/sql/test_types.py index bfadca7c91..bb3a449ca7 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -1375,7 +1375,55 @@ class NumericTest(TestBase): numbers ) +class NumericRawSQLTest(TestBase): + """Test what DBAPIs and dialects return without any typing + information supplied at the SQLA level. + + """ + def _fixture(self, metadata, type, data): + t = Table('t', metadata, + Column("val", type) + ) + metadata.create_all() + t.insert().execute(val=data) + + @testing.fails_on('sqlite', "Doesn't provide Decimal results natively") + @testing.provide_metadata + def test_decimal_fp(self): + t = self._fixture(metadata, Numeric(10, 5), Decimal("45.5")) + val = testing.db.execute("select val from t").scalar() + assert isinstance(val, Decimal) + eq_(val, Decimal("45.5")) + + @testing.fails_on('sqlite', "Doesn't provide Decimal results natively") + @testing.provide_metadata + def test_decimal_int(self): + t = self._fixture(metadata, Numeric(10, 5), Decimal("45")) + val = testing.db.execute("select val from t").scalar() + assert isinstance(val, Decimal) + eq_(val, Decimal("45")) + @testing.provide_metadata + def test_ints(self): + t = self._fixture(metadata, Integer, 45) + val = testing.db.execute("select val from t").scalar() + assert isinstance(val, (int, long)) + eq_(val, 45) + + @testing.provide_metadata + def test_float(self): + t = self._fixture(metadata, Float, 46.583) + val = testing.db.execute("select val from t").scalar() + assert isinstance(val, float) + + # some DBs have unusual float handling + if testing.against('oracle+cx_oracle'): + eq_(round_decimal(val, 3), 46.583) + else: + eq_(val, 46.583) + + + class IntervalTest(TestBase, AssertsExecutionResults): @classmethod