summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2017-09-26 11:43:25 -0400
committerGerrit Code Review <gerrit@ci.zzzcomputing.com>2017-09-26 11:43:25 -0400
commit21af7fc4aa9a97e30846b7d95a6d53928e4f11d2 (patch)
tree4c713bd81b6d8c083ec832219c556c0ff6e5fd11 /test/sql
parent1b0b35f254f545dbeb3ad6e2215ba24ae1c02894 (diff)
parent35a1f5481a28837490037a6bd99d63590f748933 (diff)
downloadsqlalchemy-21af7fc4aa9a97e30846b7d95a6d53928e4f11d2.tar.gz
Merge "Make a common approach for "emulated" types"
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_metadata.py18
-rw-r--r--test/sql/test_types.py53
2 files changed, 54 insertions, 17 deletions
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py
index 87403be63..98b98fec3 100644
--- a/test/sql/test_metadata.py
+++ b/test/sql/test_metadata.py
@@ -1814,6 +1814,24 @@ class SchemaTypeTest(fixtures.TestBase):
is_true(y_copy.type._create_events)
+ # for Postgresql, this will emit CREATE TYPE
+ m.dispatch.before_create(t1, testing.db)
+ try:
+ eq_(t1.c.y.type.evt_targets, (t1, ))
+ finally:
+ # do the drop so that Postgresql emits DROP TYPE
+ m.dispatch.after_drop(t1, testing.db)
+
+ def test_enum_nonnative_column_copy_transfers_events(self):
+ m = MetaData()
+
+ type_ = self.WrapEnum('a', 'b', 'c', name='foo', native_enum=False)
+ y = Column('y', type_)
+ y_copy = y.copy()
+ t1 = Table('x', m, y_copy)
+
+ is_true(y_copy.type._create_events)
+
m.dispatch.before_create(t1, testing.db)
eq_(t1.c.y.type.evt_targets, (t1, ))
diff --git a/test/sql/test_types.py b/test/sql/test_types.py
index bbd8a221b..52706a0b9 100644
--- a/test/sql/test_types.py
+++ b/test/sql/test_types.py
@@ -140,6 +140,7 @@ class AdaptTest(fixtures.TestBase):
"sqlalchemy" in subcl.__module__:
yield True, subcl, [typ]
+ from sqlalchemy.sql import sqltypes
for is_down_adaption, typ, target_adaptions in adaptions():
if typ in (types.TypeDecorator, types.TypeEngine, types.Variant):
continue
@@ -148,9 +149,14 @@ class AdaptTest(fixtures.TestBase):
else:
t1 = typ()
for cls in target_adaptions:
- if not issubclass(typ, types.Enum) and \
- issubclass(cls, types.Enum):
+ if (
+ (is_down_adaption and
+ issubclass(typ, sqltypes.Emulated)) or
+ (not is_down_adaption and
+ issubclass(cls, sqltypes.Emulated))
+ ):
continue
+
if cls.__module__.startswith("test"):
continue
@@ -162,7 +168,11 @@ class AdaptTest(fixtures.TestBase):
t2, t1 = t1, t2
for k in t1.__dict__:
- if k in ('impl', '_is_oracle_number', '_create_events'):
+ if k in (
+ 'impl', '_is_oracle_number',
+ '_create_events', 'create_constraint',
+ 'inherit_schema', 'schema', 'metadata',
+ 'name', ):
continue
# assert each value was copied, or that
# the adapted type has a more specific
@@ -1498,12 +1508,24 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
def test_adapt(self):
from sqlalchemy.dialects.postgresql import ENUM
e1 = Enum('one', 'two', 'three', native_enum=False)
- eq_(e1.adapt(ENUM).native_enum, False)
+
+ false_adapt = e1.adapt(ENUM)
+ eq_(false_adapt.native_enum, False)
+ assert not isinstance(false_adapt, ENUM)
+
e1 = Enum('one', 'two', 'three', native_enum=True)
- eq_(e1.adapt(ENUM).native_enum, True)
- e1 = Enum('one', 'two', 'three', name='foo', schema='bar')
+ true_adapt = e1.adapt(ENUM)
+ eq_(true_adapt.native_enum, True)
+ assert isinstance(true_adapt, ENUM)
+
+ e1 = Enum('one', 'two', 'three', name='foo',
+ schema='bar', metadata=MetaData())
eq_(e1.adapt(ENUM).name, 'foo')
eq_(e1.adapt(ENUM).schema, 'bar')
+ is_(e1.adapt(ENUM).metadata, e1.metadata)
+ eq_(e1.adapt(Enum).name, 'foo')
+ eq_(e1.adapt(Enum).schema, 'bar')
+ is_(e1.adapt(Enum).metadata, e1.metadata)
e1 = Enum(self.SomeEnum)
eq_(e1.adapt(ENUM).name, 'someenum')
eq_(e1.adapt(ENUM).enums, ['one', 'two', 'three'])
@@ -2204,8 +2226,6 @@ class ExpressionTest(
assert expr.right.type._type_affinity is MyFoobarType
def test_date_coercion(self):
- from sqlalchemy.sql import column
-
expr = column('bar', types.NULLTYPE) - column('foo', types.TIMESTAMP)
eq_(expr.type._type_affinity, types.NullType)
@@ -2215,6 +2235,14 @@ class ExpressionTest(
expr = func.current_date() - column('foo', types.TIMESTAMP)
eq_(expr.type._type_affinity, types.Interval)
+ def test_interval_coercion(self):
+ expr = column('bar', types.Interval) + column('foo', types.Date)
+ eq_(expr.type._type_affinity, types.DateTime)
+
+ expr = column('bar', types.Interval) * column('foo', types.Numeric)
+ eq_(expr.type._type_affinity, types.Interval)
+
+
def test_numerics_coercion(self):
for op in (operator.add, operator.mul, operator.truediv, operator.sub):
@@ -2503,12 +2531,6 @@ class IntervalTest(fixtures.TestBase, AssertsExecutionResults):
assert adapted.native is False
eq_(str(adapted), "DATETIME")
- @testing.fails_on(
- "postgresql+zxjdbc",
- "Not yet known how to pass values of the INTERVAL type")
- @testing.fails_on(
- "oracle+zxjdbc",
- "Not yet known how to pass values of the INTERVAL type")
def test_roundtrip(self):
small_delta = datetime.timedelta(days=15, seconds=5874)
delta = datetime.timedelta(414)
@@ -2520,9 +2542,6 @@ class IntervalTest(fixtures.TestBase, AssertsExecutionResults):
eq_(row['native_interval_args'], delta)
eq_(row['non_native_interval'], delta)
- @testing.fails_on(
- "oracle+zxjdbc",
- "Not yet known how to pass values of the INTERVAL type")
def test_null(self):
interval_table.insert().execute(
id=1, native_inverval=None, non_native_interval=None)