From: Mike Bayer Date: Wed, 24 Jan 2018 22:27:10 +0000 (-0500) Subject: Adjust tests for pyodbc 4.0.22 X-Git-Tag: rel_1_2_2~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=907c3dc1954d35cad50d9db4f652586e1066ed5d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Adjust tests for pyodbc 4.0.22 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 --- diff --git a/lib/sqlalchemy/dialects/mssql/pyodbc.py b/lib/sqlalchemy/dialects/mssql/pyodbc.py index c66c45ec68..3d541f2cf0 100644 --- a/lib/sqlalchemy/dialects/mssql/pyodbc.py +++ b/lib/sqlalchemy/dialects/mssql/pyodbc.py @@ -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) diff --git a/test/dialect/mssql/test_types.py b/test/dialect/mssql/test_types.py index d7ea8f708f..ac45566719 100644 --- a/test/dialect/mssql/test_types.py +++ b/test/dialect/mssql/test_types.py @@ -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) diff --git a/test/requirements.py b/test/requirements.py index 1a09d963cd..f4ce0f0feb 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -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):