Support alembic 0.8.9 in test_autogen_process_directives
The test case validates that autogenerated alembic commands meet our expectations. The new alembic version adds a leading '# ' to each autogenerated comment to make flake8 happy. This patch adopts the test case to handle both new and older versions. This is achieved by switching from exact match to using a regexp. Change-Id: I9ca411e5b3d20412fffa05f6eb79659f6c56f3fd Closes-Bug: #1647027
This commit is contained in:
parent
ef6a3d8789
commit
d8055d52e5
|
@ -15,6 +15,7 @@
|
|||
|
||||
import copy
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
|
@ -27,6 +28,7 @@ import mock
|
|||
from oslo_utils import fileutils
|
||||
import pkg_resources
|
||||
import sqlalchemy as sa
|
||||
from testtools import matchers
|
||||
|
||||
from neutron.db import migration
|
||||
from neutron.db.migration import autogen
|
||||
|
@ -674,8 +676,13 @@ class TestCli(base.BaseTestCase):
|
|||
self.assertTrue(expand.downgrade_ops.is_empty())
|
||||
self.assertTrue(contract.downgrade_ops.is_empty())
|
||||
|
||||
self.assertEqual(
|
||||
textwrap.dedent("""\
|
||||
def _get_regex(s):
|
||||
s = textwrap.dedent(s)
|
||||
s = re.escape(s)
|
||||
# alembic 0.8.9 added additional leading '# ' before comments
|
||||
return s.replace('\\#\\#\\#\\ ', '(# )?### ')
|
||||
|
||||
expected_regex = ("""\
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('organization',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
|
@ -686,17 +693,19 @@ class TestCli(base.BaseTestCase):
|
|||
"""sa.Column('organization_id', sa.Integer(), nullable=True))
|
||||
op.create_foreign_key('org_fk', 'user', """
|
||||
"""'organization', ['organization_id'], ['id'])
|
||||
### end Alembic commands ###"""),
|
||||
alembic_ag_api.render_python_code(expand.upgrade_ops)
|
||||
)
|
||||
self.assertEqual(
|
||||
textwrap.dedent("""\
|
||||
### end Alembic commands ###""")
|
||||
self.assertThat(
|
||||
alembic_ag_api.render_python_code(expand.upgrade_ops),
|
||||
matchers.MatchesRegex(_get_regex(expected_regex)))
|
||||
|
||||
expected_regex = ("""\
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint('user', 'uq_user_org', type_=None)
|
||||
op.drop_column('user', 'organization_name')
|
||||
### end Alembic commands ###"""),
|
||||
alembic_ag_api.render_python_code(contract.upgrade_ops)
|
||||
)
|
||||
### end Alembic commands ###""")
|
||||
self.assertThat(
|
||||
alembic_ag_api.render_python_code(contract.upgrade_ops),
|
||||
matchers.MatchesRegex(_get_regex(expected_regex)))
|
||||
|
||||
@mock.patch('alembic.script.ScriptDirectory.walk_revisions')
|
||||
def test__find_milestone_revisions_one_branch(self, walk_mock):
|
||||
|
|
Loading…
Reference in New Issue