|
| 1 | +import pytest |
| 2 | +import sqlalchemy as sa |
| 3 | +import sqlalchemy.testing.suite.test_types |
| 4 | +from sqlalchemy.testing.suite import * |
| 5 | + |
| 6 | +from sqlalchemy.testing.suite.test_select import CompoundSelectTest as _CompoundSelectTest |
| 7 | +from sqlalchemy.testing.suite.test_reflection import ( |
| 8 | + HasTableTest as _HasTableTest, |
| 9 | + HasIndexTest as _HasIndexTest, |
| 10 | + ComponentReflectionTest as _ComponentReflectionTest, |
| 11 | + CompositeKeyReflectionTest as _CompositeKeyReflectionTest, |
| 12 | + ComponentReflectionTestExtra as _ComponentReflectionTestExtra, |
| 13 | + QuotedNameArgumentTest as _QuotedNameArgumentTest, |
| 14 | +) |
| 15 | +from sqlalchemy.testing.suite.test_types import ( |
| 16 | + IntegerTest as _IntegerTest, |
| 17 | + TrueDivTest as _TrueDivTest, |
| 18 | + TimeTest as _TimeTest, |
| 19 | + TimeMicrosecondsTest as _TimeMicrosecondsTest, |
| 20 | + DateTimeCoercedToDateTimeTest as _DateTimeCoercedToDateTimeTest, |
| 21 | +) |
| 22 | +from sqlalchemy.testing.suite.test_dialect import DifficultParametersTest as _DifficultParametersTest |
| 23 | +from sqlalchemy.testing.suite.test_select import JoinTest as _JoinTest |
| 24 | + |
| 25 | + |
| 26 | +test_types_suite = sqlalchemy.testing.suite.test_types |
| 27 | +col_creator = test_types_suite.Column |
| 28 | + |
| 29 | + |
| 30 | +def column_getter(*args, **kwargs): |
| 31 | + col = col_creator(*args, **kwargs) |
| 32 | + if col.name == "x": |
| 33 | + col.primary_key = True |
| 34 | + return col |
| 35 | + |
| 36 | + |
| 37 | +test_types_suite.Column = column_getter |
| 38 | + |
| 39 | + |
| 40 | +class ComponentReflectionTest(_ComponentReflectionTest): |
| 41 | + @property |
| 42 | + def _required_column_keys(self): |
| 43 | + # nullable had changed so don't check it. |
| 44 | + return {"name", "type", "default"} |
| 45 | + |
| 46 | + def _check_list(self, result, exp, req_keys=None, msg=None): |
| 47 | + try: |
| 48 | + return super()._check_list(result, exp, req_keys, msg) |
| 49 | + except AssertionError as err: |
| 50 | + if "nullable" in err.args[0]: |
| 51 | + return "We changed nullable in define_reflected_tables method so won't check it." |
| 52 | + raise |
| 53 | + |
| 54 | + @classmethod |
| 55 | + def define_reflected_tables(cls, metadata, schema): |
| 56 | + Table( |
| 57 | + "users", |
| 58 | + metadata, |
| 59 | + Column("user_id", sa.INT, primary_key=True), |
| 60 | + Column("test1", sa.CHAR(5)), |
| 61 | + Column("test2", sa.Float()), |
| 62 | + Column("parent_user_id", sa.Integer), |
| 63 | + schema=schema, |
| 64 | + test_needs_fk=True, |
| 65 | + ) |
| 66 | + |
| 67 | + Table( |
| 68 | + "dingalings", |
| 69 | + metadata, |
| 70 | + Column("dingaling_id", sa.Integer, primary_key=True), |
| 71 | + Column("address_id", sa.Integer), |
| 72 | + Column("id_user", sa.Integer), |
| 73 | + Column("data", sa.String(30)), |
| 74 | + schema=schema, |
| 75 | + test_needs_fk=True, |
| 76 | + ) |
| 77 | + |
| 78 | + Table( |
| 79 | + "email_addresses", |
| 80 | + metadata, |
| 81 | + Column("address_id", sa.Integer, primary_key=True), |
| 82 | + Column("remote_user_id", sa.Integer), |
| 83 | + Column("email_address", sa.String(20)), |
| 84 | + schema=schema, |
| 85 | + test_needs_fk=True, |
| 86 | + ) |
| 87 | + |
| 88 | + Table( |
| 89 | + "comment_test", |
| 90 | + metadata, |
| 91 | + Column("id", sa.Integer, primary_key=True, comment="id comment"), |
| 92 | + Column("data", sa.String(20), comment="data % comment"), |
| 93 | + Column("d2", sa.String(20), comment=r"""Comment types type speedily ' " \ '' Fun!"""), |
| 94 | + schema=schema, |
| 95 | + comment=r"""the test % ' " \ table comment""", |
| 96 | + ) |
| 97 | + |
| 98 | + Table( |
| 99 | + "no_constraints", |
| 100 | + metadata, |
| 101 | + Column("data", sa.String(20), primary_key=True, nullable=True), |
| 102 | + schema=schema, |
| 103 | + ) |
| 104 | + |
| 105 | + @pytest.mark.skip("views unsupported") |
| 106 | + def test_get_view_names(self, connection, use_schema): |
| 107 | + pass |
| 108 | + |
| 109 | + |
| 110 | +class CompositeKeyReflectionTest(_CompositeKeyReflectionTest): |
| 111 | + @classmethod |
| 112 | + def define_tables(cls, metadata): |
| 113 | + Table( |
| 114 | + "tb1", |
| 115 | + metadata, |
| 116 | + Column("id", Integer), |
| 117 | + Column("attr", Integer), |
| 118 | + Column("name", sa.VARCHAR(20)), |
| 119 | + # named pk unsupported |
| 120 | + sa.PrimaryKeyConstraint("name", "id", "attr"), |
| 121 | + schema=None, |
| 122 | + test_needs_fk=True, |
| 123 | + ) |
| 124 | + |
| 125 | + @pytest.mark.skip("TODO: pk key reflection unsupported") |
| 126 | + def test_pk_column_order(self, connection): |
| 127 | + pass |
| 128 | + |
| 129 | + |
| 130 | +class ComponentReflectionTestExtra(_ComponentReflectionTestExtra): |
| 131 | + def _type_round_trip(self, connection, metadata, *types): |
| 132 | + t = Table( |
| 133 | + "t", |
| 134 | + metadata, |
| 135 | + # table without pk unsupported |
| 136 | + *[Column("t%d" % i, type_, primary_key=True) for i, type_ in enumerate(types)], |
| 137 | + ) |
| 138 | + t.create(connection) |
| 139 | + return [c["type"] for c in inspect(connection).get_columns("t")] |
| 140 | + |
| 141 | + @pytest.mark.skip("TODO: numeric now int64??") |
| 142 | + def test_numeric_reflection(self): |
| 143 | + pass |
| 144 | + |
| 145 | + @pytest.mark.skip("TODO: varchar with length unsupported") |
| 146 | + def test_varchar_reflection(self): |
| 147 | + pass |
| 148 | + |
| 149 | + @testing.requires.table_reflection |
| 150 | + def test_nullable_reflection(self, connection, metadata): |
| 151 | + t = Table( |
| 152 | + "t", |
| 153 | + metadata, |
| 154 | + # table without pk unsupported |
| 155 | + Column("a", Integer, nullable=True, primary_key=True), |
| 156 | + Column("b", Integer, nullable=False, primary_key=True), |
| 157 | + ) |
| 158 | + t.create(connection) |
| 159 | + eq_( |
| 160 | + { |
| 161 | + col["name"]: col["nullable"] |
| 162 | + for col in inspect(connection).get_columns("t") |
| 163 | + }, |
| 164 | + {"a": True, "b": False}, |
| 165 | + ) |
| 166 | + |
| 167 | + |
| 168 | +class HasTableTest(_HasTableTest): |
| 169 | + @classmethod |
| 170 | + def define_tables(cls, metadata): |
| 171 | + Table( |
| 172 | + "test_table", |
| 173 | + metadata, |
| 174 | + Column("id", Integer, primary_key=True), |
| 175 | + Column("data", String(50)), |
| 176 | + ) |
| 177 | + |
| 178 | + @pytest.mark.skip("TODO: reflection cache unsupported") |
| 179 | + def test_has_table_cache(self, metadata): |
| 180 | + pass |
| 181 | + |
| 182 | + |
| 183 | +@pytest.mark.skip("CREATE INDEX syntax unsupported") |
| 184 | +class HasIndexTest(_HasIndexTest): |
| 185 | + pass |
| 186 | + |
| 187 | + |
| 188 | +@pytest.mark.skip("quotes unsupported in table names") |
| 189 | +class QuotedNameArgumentTest(_QuotedNameArgumentTest): |
| 190 | + pass |
| 191 | + |
| 192 | + |
| 193 | +class IntegerTest(_IntegerTest): |
| 194 | + @pytest.mark.skip("YQL doesn't support select with where without from") |
| 195 | + def test_huge_int_auto_accommodation(self, connection, intvalue): |
| 196 | + pass |
| 197 | + |
| 198 | + |
| 199 | +class TrueDivTest(_TrueDivTest): |
| 200 | + @pytest.mark.skip("Unsupported builtin: FLOOR") |
| 201 | + def test_floordiv_numeric(self, connection, left, right, expected): |
| 202 | + pass |
| 203 | + |
| 204 | + @pytest.mark.skip("Truediv unsupported for int") |
| 205 | + def test_truediv_integer(self, connection, left, right, expected): |
| 206 | + pass |
| 207 | + |
| 208 | + @pytest.mark.skip("Truediv unsupported for int") |
| 209 | + def test_truediv_integer_bound(self, connection): |
| 210 | + pass |
| 211 | + |
| 212 | + @pytest.mark.skip("Numeric is not Decimal") |
| 213 | + def test_truediv_numeric(self): |
| 214 | + pass |
| 215 | + |
| 216 | + |
| 217 | +class CompoundSelectTest(_CompoundSelectTest): |
| 218 | + @pytest.mark.skip("limit don't work") |
| 219 | + def test_distinct_selectable_in_unions(self): |
| 220 | + pass |
| 221 | + |
| 222 | + @pytest.mark.skip("limit don't work") |
| 223 | + def test_limit_offset_in_unions_from_alias(self): |
| 224 | + pass |
| 225 | + |
| 226 | + @pytest.mark.skip("limit don't work") |
| 227 | + def test_limit_offset_aliased_selectable_in_unions(self): |
| 228 | + pass |
| 229 | + |
| 230 | + @pytest.mark.skip("union with brackets don't work") |
| 231 | + def test_order_by_selectable_in_unions(self): |
| 232 | + pass |
| 233 | + |
| 234 | + @pytest.mark.skip("union with brackets don't work") |
| 235 | + def test_limit_offset_selectable_in_unions(self): |
| 236 | + pass |
| 237 | + |
| 238 | + |
| 239 | +@pytest.mark.skip("unsupported tricky names for columns") |
| 240 | +class DifficultParametersTest(_DifficultParametersTest): |
| 241 | + pass |
| 242 | + |
| 243 | + |
| 244 | +@pytest.mark.skip("JOIN ON expression must be a conjunction of equality predicates") |
| 245 | +class JoinTest(_JoinTest): |
| 246 | + pass |
| 247 | + |
| 248 | + |
| 249 | +@pytest.mark.skip("unsupported Time data type") |
| 250 | +class TimeTest(_TimeTest): |
| 251 | + pass |
| 252 | + |
| 253 | + |
| 254 | +@pytest.mark.skip("unsupported Time data type") |
| 255 | +class TimeMicrosecondsTest(_TimeMicrosecondsTest): |
| 256 | + pass |
| 257 | + |
| 258 | + |
| 259 | +@pytest.mark.skip("unsupported coerce dates from datetime") |
| 260 | +class DateTimeCoercedToDateTimeTest(_DateTimeCoercedToDateTimeTest): |
| 261 | + pass |
0 commit comments