From cd0bdca35f9b48d37a1f93c5b036786b01ea0372 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 16 Oct 2015 12:29:32 -0400 Subject: - Fixed an 0.8 regression whereby the "imports" dictionary member of the autogen context was removed; this collection is documented in the "render custom type" documentation as a place to add new imports. The member is now known as :attr:`.AutogenContext.imports` and the documentation is repaired. fixes #332 --- tests/test_autogen_render.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tests/test_autogen_render.py') diff --git a/tests/test_autogen_render.py b/tests/test_autogen_render.py index e7010b5..c113a23 100644 --- a/tests/test_autogen_render.py +++ b/tests/test_autogen_render.py @@ -992,14 +992,23 @@ unique=False, """ def test_render_custom(self): + class MySpecialType(Integer): + pass + def render(type_, obj, context): if type_ == "foreign_key": return None if type_ == "column": if obj.name == "y": return None + elif obj.name == "q": + return False else: return "col(%s)" % obj.name + if type_ == "type" and isinstance(obj, MySpecialType): + context.imports.add("from mypackage import MySpecialType") + return "MySpecialType()" + return "render:%s" % type_ self.autogen_context.opts.update( @@ -1010,6 +1019,7 @@ unique=False, """ t = Table('t', MetaData(), Column('x', Integer), Column('y', Integer), + Column('q', MySpecialType()), PrimaryKeyConstraint('x'), ForeignKeyConstraint(['x'], ['y']) ) @@ -1019,8 +1029,13 @@ unique=False, """ result, "sa.create_table('t'," "col(x)," + "sa.Column('q', MySpecialType(), nullable=True)," "render:primary_key)" ) + eq_( + self.autogen_context.imports, + set(['from mypackage import MySpecialType']) + ) def test_render_modify_type(self): op_obj = ops.AlterColumnOp( @@ -1350,7 +1365,7 @@ unique=False, """ autogenerate.render._repr_type(type_, self.autogen_context), "mysql.VARCHAR(charset='utf8', national=True, length=20)" ) - eq_(self.autogen_context._imports, + eq_(self.autogen_context.imports, set(['from sqlalchemy.dialects import mysql']) ) -- cgit v1.2.1