]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix: test_decimal on MSSQL - use a value that is accurately represented as a float...
authorPaul Johnston <paj@pajhome.org.uk>
Sun, 25 Nov 2007 23:34:39 +0000 (23:34 +0000)
committerPaul Johnston <paj@pajhome.org.uk>
Sun, 25 Nov 2007 23:34:39 +0000 (23:34 +0000)
lib/sqlalchemy/databases/mssql.py
test/sql/testtypes.py

index a1cefb0193c61b0c8765009c6e67dc32e435d164..d060458d4e9bc38d0e8e783c0dbb9b5074bcf148 100644 (file)
@@ -43,12 +43,23 @@ from sqlalchemy import sql, schema, exceptions, util
 from sqlalchemy.sql import compiler, expression, operators as sqlops
 from sqlalchemy.engine import default, base
 from sqlalchemy import types as sqltypes
+from sqlalchemy.util import Decimal as _python_Decimal
     
 MSSQL_RESERVED_WORDS = util.Set(['function'])
 
 class MSNumeric(sqltypes.Numeric):
     def result_processor(self, dialect):
-        return None
+        if self.asdecimal:
+            def process(value):
+                if value is not None:
+                    return _python_Decimal(str(value))
+                else:
+                    return value
+            return process
+        else:
+            def process(value):
+                return float(value)
+            return process
 
     def bind_processor(self, dialect):
         def process(value):
index 7a9add947135c87847f5324aa6d08ab740c182da..8c247897f4bc00f2b3bc3021b56b871582ac9ebb 100644 (file)
@@ -587,8 +587,8 @@ class NumericTest(AssertMixin):
 
     def test_decimal(self):
         from decimal import Decimal
-        numeric_table.insert().execute(numericcol=3.5, floatcol=5.6, ncasdec=12.4, fcasdec=15.78)
-        numeric_table.insert().execute(numericcol=Decimal("3.5"), floatcol=Decimal("5.6"), ncasdec=Decimal("12.4"), fcasdec=Decimal("15.78"))
+        numeric_table.insert().execute(numericcol=3.5, floatcol=5.6, ncasdec=12.4, fcasdec=15.75)
+        numeric_table.insert().execute(numericcol=Decimal("3.5"), floatcol=Decimal("5.6"), ncasdec=Decimal("12.4"), fcasdec=Decimal("15.75"))
         l = numeric_table.select().execute().fetchall()
         print l
         rounded = [
@@ -596,8 +596,8 @@ class NumericTest(AssertMixin):
             (l[1][0], l[1][1], round(l[1][2], 5), l[1][3], l[1][4]),
         ]
         assert rounded == [
-            (1, 3.5, 5.6, Decimal("12.4"), Decimal("15.78")),
-            (2, 3.5, 5.6, Decimal("12.4"), Decimal("15.78")),
+            (1, 3.5, 5.6, Decimal("12.4"), Decimal("15.75")),
+            (2, 3.5, 5.6, Decimal("12.4"), Decimal("15.75")),
         ]