]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Vendor assert_raises[_message], add new check constraint target
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 5 Mar 2020 17:13:46 +0000 (12:13 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 5 Mar 2020 17:36:23 +0000 (12:36 -0500)
SQLAlchemy in 1.3 / master is now checking that re-thrown exceptions
have a cause, which we haven't implemented for Alembic yet.
If we did implement this for Alembic, we'd still need to
vendor these two anyway to test.   See
https://github.com/sqlalchemy/sqlalchemy/issues/4849

Also add "table_or_column_check_constraint" target so that
builds can pass, this was added for 1.4 / master
in
https://github.com/sqlalchemy/sqlalchemy/commit/ca2e4f385802799c2584782a8528e19a9e5513bc

Change-Id: I07fb2a380f027c44f6bb36e9499da2e8ae2223e7

alembic/operations/ops.py
alembic/testing/assertions.py

index 5ec27623358a5e89fe25f97c20e59f21eb316135..71294722e9adbe92b5dcf05a6e50b552a00956dc 100644 (file)
@@ -108,6 +108,7 @@ class DropConstraintOp(MigrateOperation):
             "primary_key_constraint": "primary",
             "check_constraint": "check",
             "column_check_constraint": "check",
+            "table_or_column_check_constraint": "check",
         }
 
         constraint_table = sqla_compat._table_for_constraint(constraint)
@@ -707,6 +708,7 @@ class CreateForeignKeyOp(AddConstraintOp):
     "create_check_constraint", "batch_create_check_constraint"
 )
 @AddConstraintOp.register_add_constraint("check_constraint")
+@AddConstraintOp.register_add_constraint("table_or_column_check_constraint")
 @AddConstraintOp.register_add_constraint("column_check_constraint")
 class CreateCheckConstraintOp(AddConstraintOp):
     """Represent a create check constraint operation."""
index 3dc08f0b7374eb20285bcef0ec6ebf319593c959..a78e5e8e379eea3bc1307a68e206abe2e996ec49 100644 (file)
@@ -2,10 +2,9 @@ from __future__ import absolute_import
 
 import re
 
+from sqlalchemy import util
 from sqlalchemy.engine import default
 from sqlalchemy.testing.assertions import _expect_warnings
-from sqlalchemy.testing.assertions import assert_raises  # noqa
-from sqlalchemy.testing.assertions import assert_raises_message  # noqa
 from sqlalchemy.testing.assertions import eq_  # noqa
 from sqlalchemy.testing.assertions import is_  # noqa
 from sqlalchemy.testing.assertions import is_false  # noqa
@@ -17,6 +16,29 @@ from sqlalchemy.util import decorator
 from ..util.compat import py3k
 
 
+def assert_raises(except_cls, callable_, *args, **kw):
+    try:
+        callable_(*args, **kw)
+        success = False
+    except except_cls:
+        success = True
+
+    # assert outside the block so it works for AssertionError too !
+    assert success, "Callable did not raise an exception"
+
+
+def assert_raises_message(except_cls, msg, callable_, *args, **kwargs):
+    try:
+        callable_(*args, **kwargs)
+        assert False, "Callable did not raise an exception"
+    except except_cls as e:
+        assert re.search(msg, util.text_type(e), re.UNICODE), "%r !~ %s" % (
+            msg,
+            e,
+        )
+        print(util.text_type(e).encode("utf-8"))
+
+
 def eq_ignore_whitespace(a, b, msg=None):
     # sqlalchemy.testing.assertion has this function
     # but not with the special "!U" detection part