rusackas commented on code in PR #45507:
URL: https://github.com/apache/superset/pull/45507#discussion_r4336734171


##########
tests/unit_tests/db_engine_specs/test_oceanbase.py:
##########
@@ -59,3 +64,214 @@ def test_get_column_spec(
     )
 
     assert_column_spec(spec, native_type, sqla_type, attrs, generic_type, 
is_dttm)
+
+
+def install_fake_oceanbase_py(monkeypatch: pytest.MonkeyPatch) -> Any:
+    """
+    Stub a minimal ``oceanbase_py`` package replicating the real dialect's
+    bugs (``Connection.execute(raw_string)``, no not-found handling) into
+    ``sys.modules`` and return its (not yet patched) dialect class.
+
+    This lets the tests exercise the actual patch logic without needing the
+    real driver installed -- it pins ``sqlalchemy<2``, incompatible with this
+    repo's own pin, so it's never part of the base dev environment (see
+    ``requirements/development.in``); CI installs it standalone, with
+    ``--no-deps``, only for the dedicated nightly testcontainers job.
+    """
+
+    class FakeIdentifierPreparer:
+        @staticmethod
+        def quote_identifier(name: str) -> str:
+            return f"`{name}`"
+
+    class FakeOceanBaseDialect:
+        default_schema_name = "test_schema"
+        identifier_preparer = FakeIdentifierPreparer()
+
+        def _get_default_schema_name(self, connection: Any) -> str:
+            return self.default_schema_name
+
+        def has_table(
+            self, connection: Any, table_name: str, schema: Optional[str] = 
None
+        ) -> bool:
+            # The original, unpatched method: passes a raw string straight
+            # to Connection.execute() (rejected outright by SQLAlchemy 2.0)
+            # and never catches the "table doesn't exist" error, so it can
+            # only ever return True.
+            connection.execute(f"DESCRIBE {table_name}")
+            return True
+
+        def get_columns(
+            self, connection: Any, table_name: str, schema: Optional[str] = 
None
+        ) -> list[dict[str, Any]]:
+            connection.execute(f"SHOW COLUMNS FROM {table_name}")
+            return []
+
+    datatype_module = 
python_types.ModuleType("oceanbase_py.sqlalchemy.datatype")
+    datatype_module.parse_sql_type = lambda native_type: native_type  # type: 
ignore[attr-defined]

Review Comment:
   Good catch @sadpandajoe. The fake now returns `types.INTEGER()` and records 
what it was handed, and the test asserts both the type instance and that the 
parser got `"int"`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to