From: Mike Bayer Date: Thu, 5 Mar 2020 17:13:46 +0000 (-0500) Subject: Vendor assert_raises[_message], add new check constraint target X-Git-Tag: rel_1_4_2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d791c575e95614f53c282a9f22166646dc46b9a0;p=thirdparty%2Fsqlalchemy%2Falembic.git Vendor assert_raises[_message], add new check constraint target 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 --- diff --git a/alembic/operations/ops.py b/alembic/operations/ops.py index 5ec27623..71294722 100644 --- a/alembic/operations/ops.py +++ b/alembic/operations/ops.py @@ -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.""" diff --git a/alembic/testing/assertions.py b/alembic/testing/assertions.py index 3dc08f0b..a78e5e8e 100644 --- a/alembic/testing/assertions.py +++ b/alembic/testing/assertions.py @@ -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