summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2023-04-26 21:40:38 +0200
committerMike Bayer <mike_mp@zzzcomputing.com>2023-05-09 10:14:58 -0400
commitff821e57c960f095ab2988a0f892b3127374f498 (patch)
tree4dc3c70ff635ccaa77702976326e5c83b279d19c /lib/sqlalchemy/testing
parent39c8e95b1f50190ff30a836b2bcf13ba2cacc052 (diff)
downloadsqlalchemy-ff821e57c960f095ab2988a0f892b3127374f498.tar.gz
Ensure float are not implemented as numeric
Fixed the base class for dialect-specific float/double types; Oracle :class:`_oracle.BINARY_DOUBLE` now subclasses :class:`_sqltypes.Double`, and internal types for :class:`_sqltypes.Float` for asyncpg and pg8000 now correctly subclass :class:`_sqltypes.Float`. Added suite tests to ensure that floating point types, such as class:`_types.Float` and :class:`_types.Double` are not resolved as class:`_types.Numeric` in the dialect, since it may not compatible in all cases, such as when casting a value. Change-Id: I20b814e8e029d57921d9728a55f2570f74c35c87
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/requirements.py6
-rw-r--r--lib/sqlalchemy/testing/suite/test_types.py11
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py
index b59cce374..c1d6a14aa 100644
--- a/lib/sqlalchemy/testing/requirements.py
+++ b/lib/sqlalchemy/testing/requirements.py
@@ -1241,6 +1241,12 @@ class SuiteRequirements(Requirements):
return exclusions.open()
@property
+ def float_is_numeric(self):
+ """target backend uses Numeric for Float/Dual"""
+
+ return exclusions.open()
+
+ @property
def text_type(self):
"""Target database must support an unbounded Text() "
"type such as TEXT or CLOB"""
diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py
index 72f1e8c10..92781cc1b 100644
--- a/lib/sqlalchemy/testing/suite/test_types.py
+++ b/lib/sqlalchemy/testing/suite/test_types.py
@@ -13,6 +13,7 @@ from .. import fixtures
from .. import mock
from ..assertions import eq_
from ..assertions import is_
+from ..assertions import ne_
from ..config import requirements
from ..schema import Column
from ..schema import Table
@@ -47,6 +48,7 @@ from ... import UUID
from ... import Uuid
from ...orm import declarative_base
from ...orm import Session
+from ...sql import sqltypes
from ...sql.sqltypes import LargeBinary
from ...sql.sqltypes import PickleType
@@ -1090,6 +1092,15 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase):
Numeric(precision=5, scale=3), numbers, numbers, check_scale=True
)
+ @testing.combinations(sqltypes.Float, sqltypes.Double, argnames="cls_")
+ @testing.requires.float_is_numeric
+ def test_float_is_not_numeric(self, connection, cls_):
+ target_type = cls_().dialect_impl(connection.dialect)
+ numeric_type = sqltypes.Numeric().dialect_impl(connection.dialect)
+
+ ne_(target_type.__visit_name__, numeric_type.__visit_name__)
+ ne_(target_type.__class__, numeric_type.__class__)
+
class BooleanTest(_LiteralRoundTripFixture, fixtures.TablesTest):
__backend__ = True