]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Adjust tests for pyodbc 4.0.22
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 24 Jan 2018 22:27:10 +0000 (17:27 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 24 Jan 2018 23:07:35 +0000 (18:07 -0500)
pyodbc 4.0.22 is no longer allowing a datetime to be truncated
into a date, and additionally is asserting that numeric truncation
is not occurring; previously, it looks like we could send a
decimal of -1E-25 through the driver but we were only getting
back -1E-20, the test failed to check this.  Not clear if the
larger precision worked fully at some point, but in any case,
it doesn't work now so just remove those values from the test.

Change-Id: I66c7863b1708eb72f48173083b4ef78c93893b52

lib/sqlalchemy/dialects/mssql/pyodbc.py
test/dialect/mssql/test_types.py
test/requirements.py

index c66c45ec68abc3490d938e1af0b2c5e3f9d53684..3d541f2cf09734d1b7e577fa357c289ae1417cd9 100644 (file)
@@ -114,7 +114,6 @@ class _ms_numeric_pyodbc(object):
         def process(value):
             if self.asdecimal and \
                     isinstance(value, decimal.Decimal):
-
                 adjusted = value.adjusted()
                 if adjusted < 0:
                     return self._small_dec_to_string(value)
index d7ea8f708f233229ca4b4d96565747fc01da1cf4..ac455667198a8064fefdc73bd343e85faf6f4291 100644 (file)
@@ -572,10 +572,16 @@ class TypeRoundTripTest(
             '45125E-2',
             '1234.58965E-2',
             '1.521E+15',
-            '-1E-25',
-            '1E-25',
-            '1254E-25',
-            '-1203E-25',
+
+            # previously, these were at -1E-25, which were inserted
+            # cleanly howver we only got back 20 digits of accuracy.
+            # pyodbc as of 4.0.22 now disallows the silent truncation.
+            '-1E-20',
+            '1E-20',
+            '1254E-20',
+            '-1203E-20',
+
+
             '0',
             '-0.00',
             '-0',
@@ -583,14 +589,29 @@ class TypeRoundTripTest(
             '000000000000000000012',
             '000000000000.32E12',
             '00000000000000.1E+12',
-            '000000000000.2E-32',
-        )]
 
-        for value in test_items:
-            numeric_table.insert().execute(numericcol=value)
+            # these are no longer accepted by pyodbc 4.0.22 but it seems
+            # they were not actually round-tripping correctly before that
+            # in any case
+            # '-1E-25',
+            # '1E-25',
+            # '1254E-25',
+            # '-1203E-25',
+            # '000000000000.2E-32',
+        )]
 
-        for value in select([numeric_table.c.numericcol]).execute():
-            assert value[0] in test_items, "%r not in test_items" % value[0]
+        with testing.db.connect() as conn:
+            for value in test_items:
+                result = conn.execute(
+                    numeric_table.insert(),
+                    dict(numericcol=value)
+                )
+                primary_key = result.inserted_primary_key
+                returned = conn.scalar(
+                    select([numeric_table.c.numericcol]).
+                    where(numeric_table.c.id == primary_key[0])
+                )
+                eq_(value, returned)
 
     def test_float(self):
         float_table = Table(
@@ -721,7 +742,13 @@ class TypeRoundTripTest(
         t1 = datetime.time(11, 2, 32)
         d2 = datetime.datetime(2007, 10, 30, 11, 2, 32)
         t.insert().execute(adate=d1, adatetime=d2, atime=t1)
-        t.insert().execute(adate=d2, adatetime=d2, atime=d2)
+
+        # NOTE: this previously passed 'd2' for "adate" even though
+        # "adate" is a date column; we asserted that it truncated w/o issue.
+        # As of pyodbc 4.0.22, this is no longer accepted, was accepted
+        # in 4.0.21.  See also the new pyodbc assertions regarding numeric
+        # precision.
+        t.insert().execute(adate=d1, adatetime=d2, atime=d2)
 
         x = t.select().execute().fetchall()[0]
         self.assert_(x.adate.__class__ == datetime.date)
index 1a09d963cd15fcb626684ac852df67492a4554c8..f4ce0f0feb6a8c96cfd79e55e1e9ad57073897fb 100644 (file)
@@ -740,7 +740,8 @@ class DefaultRequirements(SuiteRequirements):
         """target dialect accepts a datetime object as the target
         of a date column."""
 
-        return fails_on('mysql+mysqlconnector')
+        # does not work as of pyodbc 4.0.22
+        return fails_on('mysql+mysqlconnector') + skip_if("mssql+pyodbc")
 
     @property
     def date_historic(self):