diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-07-20 12:54:37 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-07-21 12:07:30 -0400 |
commit | 7995199012173d77e2dcaf02d4ded5d2d7a6f634 (patch) | |
tree | 40d52590ef9ff7d4e4708318eb0f924f95e7033c /tests/test_environment.py | |
parent | 02a1bf3454acb7b02942e246c19326630a8f9175 (diff) | |
download | alembic-7995199012173d77e2dcaf02d4ded5d2d7a6f634.tar.gz |
Add dialect_options to environment; set paramstyle=named for offline
Fixed bug where the double-percent logic applied to some dialects such as
psycopg2 would be rendered in ``--sql`` mode, by allowing dialect options
to be passed through to the dialect used to generate SQL and then providing
``paramstyle="named"`` so that percent signs need not be doubled. For
users having this issue, existing env.py scripts need to add
``dialect_opts={"paramstyle": "named"}`` to their offline
context.configure(). See the ``alembic/templates/generic/env.py`` template
for an example.
Change-Id: Ia6a495704b029eaff43fb3b6df602ca667002b7a
Fixes: #562
Diffstat (limited to 'tests/test_environment.py')
-rw-r--r-- | tests/test_environment.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/test_environment.py b/tests/test_environment.py index 6109ed7..fadab54 100644 --- a/tests/test_environment.py +++ b/tests/test_environment.py @@ -1,8 +1,9 @@ #!coding: utf-8 - +from alembic import command from alembic.environment import EnvironmentContext from alembic.migration import MigrationContext from alembic.script import ScriptDirectory +from alembic.testing import config from alembic.testing import eq_ from alembic.testing import is_ from alembic.testing.assertions import expect_warnings @@ -11,6 +12,7 @@ from alembic.testing.env import _sqlite_file_db from alembic.testing.env import clear_staging_env from alembic.testing.env import staging_env from alembic.testing.env import write_script +from alembic.testing.fixtures import capture_context_buffer from alembic.testing.fixtures import TestBase from alembic.testing.mock import call from alembic.testing.mock import MagicMock @@ -61,6 +63,35 @@ class EnvironmentTest(TestBase): ctx = MigrationContext(ctx.dialect, None, {}) is_(ctx.config, None) + @config.requirements.sqlalchemy_issue_3740 + def test_sql_mode_parameters(self): + env = self._fixture() + + a_rev = "arev" + env.script.generate_revision(a_rev, "revision a", refresh=True) + write_script( + env.script, + a_rev, + """\ +"Rev A" +revision = '{}' +down_revision = None + +from alembic import op + +def upgrade(): + op.execute(''' + do some SQL thing with a % percent sign % + ''') + +""".format( + a_rev + ), + ) + with capture_context_buffer(transactional_ddl=True) as buf: + command.upgrade(self.cfg, "arev", sql=True) + assert "do some SQL thing with a % percent sign %" in buf.getvalue() + def test_warning_on_passing_engine(self): env = self._fixture() |