From 5b97778e098720ec37a394bcef27e9b79b178b52 Mon Sep 17 00:00:00 2001 From: Maico Timmerman Date: Tue, 15 Nov 2016 15:39:18 -0500 Subject: [PATCH] Add single pound to generated comments Adjustment to the "please adjust!" comment in the script.py.mako template so that the generated comment starts with a single pound sign, appeasing flake8. Change-Id: I4b425d2fa8701cabf8352d046b3342a73f78c70d Pull-request: https://bitbucket.org/zzzeek/alembic/pull-requests/65 Partially-fixes: #393 --- alembic/autogenerate/render.py | 5 ++-- docs/build/changelog.rst | 8 ++++++ tests/test_autogen_composition.py | 48 +++++++++++++++---------------- tests/test_autogen_render.py | 4 +-- tests/test_script_production.py | 4 +-- 5 files changed, 38 insertions(+), 31 deletions(-) diff --git a/alembic/autogenerate/render.py b/alembic/autogenerate/render.py index cade4d7c..476c1f9f 100644 --- a/alembic/autogenerate/render.py +++ b/alembic/autogenerate/render.py @@ -52,8 +52,7 @@ def _render_cmd_body(op_container, autogen_context): printer = PythonPrinter(buf) printer.writeline( - "### commands auto generated by Alembic - " - "please adjust! ###" + "# ### commands auto generated by Alembic - please adjust! ###" ) if not op_container.ops: @@ -65,7 +64,7 @@ def _render_cmd_body(op_container, autogen_context): for line in lines: printer.writeline(line) - printer.writeline("### end Alembic commands ###") + printer.writeline("# ### end Alembic commands ###") return buf.getvalue() diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index f8a89be2..1f683c27 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -6,6 +6,14 @@ Changelog .. changelog:: :version: 0.8.9 + .. change:: 393 + :tags: bug, autogenerate + :tickets: 393 + + Adjustment to the "please adjust!" comment in the script.py.mako + template so that the generated comment starts with a single pound + sign, appeasing flake8. + .. change:: :tags: bug, autogenerate :tickets: 395 diff --git a/tests/test_autogen_composition.py b/tests/test_autogen_composition.py index ace6e194..c5363175 100644 --- a/tests/test_autogen_composition.py +++ b/tests/test_autogen_composition.py @@ -26,13 +26,13 @@ class AutogenerateDiffTest(ModelOne, AutogenTest, TestBase): autogenerate._render_migration_diffs(context, template_args) eq_(re.sub(r"u'", "'", template_args['upgrades']), - """### commands auto generated by Alembic - please adjust! ### + """# ### commands auto generated by Alembic - please adjust! ### pass - ### end Alembic commands ###""") + # ### end Alembic commands ###""") eq_(re.sub(r"u'", "'", template_args['downgrades']), - """### commands auto generated by Alembic - please adjust! ### + """# ### commands auto generated by Alembic - please adjust! ### pass - ### end Alembic commands ###""") + # ### end Alembic commands ###""") def test_render_nothing_batch(self): context = MigrationContext.configure( @@ -53,13 +53,13 @@ class AutogenerateDiffTest(ModelOne, AutogenTest, TestBase): autogenerate._render_migration_diffs(context, template_args) eq_(re.sub(r"u'", "'", template_args['upgrades']), - """### commands auto generated by Alembic - please adjust! ### + """# ### commands auto generated by Alembic - please adjust! ### pass - ### end Alembic commands ###""") + # ### end Alembic commands ###""") eq_(re.sub(r"u'", "'", template_args['downgrades']), - """### commands auto generated by Alembic - please adjust! ### + """# ### commands auto generated by Alembic - please adjust! ### pass - ### end Alembic commands ###""") + # ### end Alembic commands ###""") def test_render_diffs_standard(self): """test a full render including indentation""" @@ -67,7 +67,7 @@ class AutogenerateDiffTest(ModelOne, AutogenTest, TestBase): template_args = {} autogenerate._render_migration_diffs(self.context, template_args) eq_(re.sub(r"u'", "'", template_args['upgrades']), - """### commands auto generated by Alembic - please adjust! ### + """# ### commands auto generated by Alembic - please adjust! ### op.create_table('item', sa.Column('id', sa.Integer(), nullable=False), sa.Column('description', sa.String(length=100), nullable=True), @@ -96,10 +96,10 @@ nullable=True)) nullable=False) op.drop_index('pw_idx', table_name='user') op.drop_column('user', 'pw') - ### end Alembic commands ###""") + # ### end Alembic commands ###""") eq_(re.sub(r"u'", "'", template_args['downgrades']), - """### commands auto generated by Alembic - please adjust! ### + """# ### commands auto generated by Alembic - please adjust! ### op.add_column('user', sa.Column('pw', sa.VARCHAR(length=50), \ nullable=True)) op.create_index('pw_idx', 'user', ['pw'], unique=False) @@ -125,7 +125,7 @@ nullable=True)) sa.ForeignKeyConstraint(['uid'], ['user.id'], ) ) op.drop_table('item') - ### end Alembic commands ###""") + # ### end Alembic commands ###""") def test_render_diffs_batch(self): """test a full render in batch mode including indentation""" @@ -135,7 +135,7 @@ nullable=True)) autogenerate._render_migration_diffs(self.context, template_args) eq_(re.sub(r"u'", "'", template_args['upgrades']), - """### commands auto generated by Alembic - please adjust! ### + """# ### commands auto generated by Alembic - please adjust! ### op.create_table('item', sa.Column('id', sa.Integer(), nullable=False), sa.Column('description', sa.String(length=100), nullable=True), @@ -169,10 +169,10 @@ nullable=True)) batch_op.drop_index('pw_idx') batch_op.drop_column('pw') - ### end Alembic commands ###""") + # ### end Alembic commands ###""") eq_(re.sub(r"u'", "'", template_args['downgrades']), - """### commands auto generated by Alembic - please adjust! ### + """# ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('user', schema=None) as batch_op: batch_op.add_column(sa.Column('pw', sa.VARCHAR(length=50), nullable=True)) batch_op.create_index('pw_idx', ['pw'], unique=False) @@ -203,7 +203,7 @@ nullable=True)) sa.ForeignKeyConstraint(['uid'], ['user.id'], ) ) op.drop_table('item') - ### end Alembic commands ###""") + # ### end Alembic commands ###""") def test_imports_maintined(self): template_args = {} @@ -252,13 +252,13 @@ class AutogenerateDiffTestWSchema(ModelOne, AutogenTest, TestBase): autogenerate._render_migration_diffs(context, template_args) eq_(re.sub(r"u'", "'", template_args['upgrades']), - """### commands auto generated by Alembic - please adjust! ### + """# ### commands auto generated by Alembic - please adjust! ### pass - ### end Alembic commands ###""") + # ### end Alembic commands ###""") eq_(re.sub(r"u'", "'", template_args['downgrades']), - """### commands auto generated by Alembic - please adjust! ### + """# ### commands auto generated by Alembic - please adjust! ### pass - ### end Alembic commands ###""") + # ### end Alembic commands ###""") def test_render_diffs_extras(self): """test a full render including indentation (include and schema)""" @@ -271,7 +271,7 @@ class AutogenerateDiffTestWSchema(ModelOne, AutogenTest, TestBase): autogenerate._render_migration_diffs(self.context, template_args) eq_(re.sub(r"u'", "'", template_args['upgrades']), - """### commands auto generated by Alembic - please adjust! ### + """# ### commands auto generated by Alembic - please adjust! ### op.create_table('item', sa.Column('id', sa.Integer(), nullable=False), sa.Column('description', sa.String(length=100), nullable=True), @@ -307,10 +307,10 @@ source_schema='%(schema)s', referent_schema='%(schema)s') schema='%(schema)s') op.drop_index('pw_idx', table_name='user', schema='test_schema') op.drop_column('user', 'pw', schema='%(schema)s') - ### end Alembic commands ###""" % {"schema": self.schema}) + # ### end Alembic commands ###""" % {"schema": self.schema}) eq_(re.sub(r"u'", "'", template_args['downgrades']), - """### commands auto generated by Alembic - please adjust! ### + """# ### commands auto generated by Alembic - please adjust! ### op.add_column('user', sa.Column('pw', sa.VARCHAR(length=50), \ autoincrement=False, nullable=True), schema='%(schema)s') op.create_index('pw_idx', 'user', ['pw'], unique=False, schema='%(schema)s') @@ -341,5 +341,5 @@ name='extra_uid_fkey'), schema='%(schema)s' ) op.drop_table('item', schema='%(schema)s') - ### end Alembic commands ###""" % {"schema": self.schema}) + # ### end Alembic commands ###""" % {"schema": self.schema}) diff --git a/tests/test_autogen_render.py b/tests/test_autogen_render.py index 64425a97..4beabb07 100644 --- a/tests/test_autogen_render.py +++ b/tests/test_autogen_render.py @@ -1674,7 +1674,7 @@ class RenderNamingConventionTest(TestBase): eq_( autogenerate.render_python_code(uo, render_as_batch=True), - "### commands auto generated by Alembic - please adjust! ###\n" + "# ### commands auto generated by Alembic - please adjust! ###\n" " op.create_table('sometable',\n" " sa.Column('x', sa.Integer(), nullable=True),\n" " sa.Column('y', sa.Integer(), nullable=True)\n" @@ -1683,5 +1683,5 @@ class RenderNamingConventionTest(TestBase): "as batch_op:\n" " batch_op.create_index(" "'ix1', ['x', 'y'], unique=False)\n\n" - " ### end Alembic commands ###" + " # ### end Alembic commands ###" ) diff --git a/tests/test_script_production.py b/tests/test_script_production.py index 66e311d1..9399be66 100644 --- a/tests/test_script_production.py +++ b/tests/test_script_production.py @@ -708,14 +708,14 @@ class RewriterTest(TestBase): eq_( autogenerate.render_python_code(directives[0].upgrade_ops), - "### commands auto generated by Alembic - please adjust! ###\n" + "# ### commands auto generated by Alembic - please adjust! ###\n" " op.add_column('t1', " "sa.Column('x', sa.Integer(), nullable=True))\n" " op.create_index('ixt', 't1', ['x'], unique=False)\n" " op.alter_column('t1', 'x',\n" " existing_type=sa.Integer(),\n" " nullable=False)\n" - " ### end Alembic commands ###" + " # ### end Alembic commands ###" ) -- 2.47.2