Skip to content

Commit

Permalink
QA: Add EOL/deprecation warning about support for SQLAlchemy 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jan 26, 2023
1 parent 696a623 commit 3183efc
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/crate/client/sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,24 @@
from .dialect import CrateDialect
from .sa_version import SA_1_4, SA_VERSION

# SQLAlchemy 1.3 does not have the `exec_driver_sql` method.

if SA_VERSION < SA_1_4:
import textwrap
import warnings

# SQLAlchemy 1.3 is effectively EOL.
SA13_DEPRECATION_WARNING = textwrap.dedent("""
WARNING: SQLAlchemy 1.3 is effectively EOL.
With SQLAlchemy 2 around the corner, this will be even more immanent.
Future versions of the CrateDB SQLAlchemy dialect will drop support for SQLAlchemy 1.3.
It is recommended that you transition to using SQLAlchemy 1.4 or 2.0.
""".lstrip("\n"))
warnings.warn(message=SA13_DEPRECATION_WARNING, category=DeprecationWarning)

# SQLAlchemy 1.3 does not have the `exec_driver_sql` method, so add it.
monkeypatch_add_exec_driver_sql()


__all__ = [
CrateDialect,
]
2 changes: 2 additions & 0 deletions src/crate/client/sqlalchemy/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .array_test import SqlAlchemyArrayTypeTest
from .dialect_test import SqlAlchemyDialectTest
from .function_test import SqlAlchemyFunctionTest
from .warnings_test import SqlAlchemyWarningsTest


def test_suite():
Expand All @@ -38,4 +39,5 @@ def test_suite():
tests.addTest(makeSuite(SqlAlchemyDialectTest))
tests.addTest(makeSuite(SqlAlchemyFunctionTest))
tests.addTest(makeSuite(SqlAlchemyArrayTypeTest))
tests.addTest(makeSuite(SqlAlchemyWarningsTest))
return tests
30 changes: 30 additions & 0 deletions src/crate/client/sqlalchemy/tests/warnings_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8; -*-
import sys
import warnings
from unittest import TestCase

from crate.testing.util import ExtraAssertions


class SqlAlchemyWarningsTest(TestCase, ExtraAssertions):

def test_sa13_deprecation_warning(self):
"""
Verify that a `DeprecationWarning` is issued when running SQLAlchemy 1.3.
https://docs.python.org/3/library/warnings.html#testing-warnings
"""
with warnings.catch_warnings(record=True) as w:

# Cause all warnings to always be triggered.
warnings.simplefilter("always")

# Trigger a warning by importing the SQLAlchemy dialect module.
# Because it already has been loaded, unload it beforehand.
del sys.modules["crate.client.sqlalchemy"]
import crate.client.sqlalchemy # noqa: F401

# Verify details of the SA13 EOL/deprecation warning.
self.assertEqual(len(w), 1)
self.assertIsSubclass(w[-1].category, DeprecationWarning)
self.assertIn("SQLAlchemy 1.3 is effectively EOL.", str(w[-1].message))
20 changes: 20 additions & 0 deletions src/crate/testing/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ExtraAssertions:
"""
Additional assert methods for unittest.
- https://github.com/python/cpython/issues/71339
- https://bugs.python.org/issue14819
- https://bugs.python.org/file43047/extra_assertions.patch
"""

def assertIsSubclass(self, cls, superclass, msg=None):
try:
r = issubclass(cls, superclass)
except TypeError:
if not isinstance(cls, type):
self.fail(self._formatMessage(msg,
'%r is not a class' % (cls,)))
raise
if not r:
self.fail(self._formatMessage(msg,
'%r is not a subclass of %r' % (cls, superclass)))

0 comments on commit 3183efc

Please sign in to comment.