def assert_compile(self, clause, result, params=None, checkparams=None, for_executemany=False, check_literal_execute=None, check_post_param=None, dialect=None, checkpositional=None, check_prefetch=None, use_default_dialect=False, allow_dialect_select=False, supports_default_values=True, literal_binds=False, render_postcompile=False, schema_translate_map=None, render_schema_translate=False, default_schema_name=None):
    if use_default_dialect:
        dialect = default.DefaultDialect()
        dialect.supports_default_values = supports_default_values
    elif allow_dialect_select:
        dialect = None
    else:
        if (dialect is None):
            dialect = getattr(self, '__dialect__', None)
        if (dialect is None):
            dialect = config.db.dialect
        elif (dialect == 'default'):
            dialect = default.DefaultDialect()
            dialect.supports_default_values = supports_default_values
        elif (dialect == 'default_enhanced'):
            dialect = default.StrCompileDialect()
        elif isinstance(dialect, util.string_types):
            dialect = url.URL.create(dialect).get_dialect()()
    if default_schema_name:
        dialect.default_schema_name = default_schema_name
    kw = {}
    compile_kwargs = {}
    if schema_translate_map:
        kw['schema_translate_map'] = schema_translate_map
    if (params is not None):
        kw['column_keys'] = list(params)
    if literal_binds:
        compile_kwargs['literal_binds'] = True
    if render_postcompile:
        compile_kwargs['render_postcompile'] = True
    if for_executemany:
        kw['for_executemany'] = True
    if render_schema_translate:
        kw['render_schema_translate'] = True
    from sqlalchemy import orm
    if isinstance(clause, orm.dynamic.AppenderQuery):
        clause = clause._statement
    if isinstance(clause, orm.Query):
        compile_state = clause._compile_state()
        compile_state.statement._label_style = LABEL_STYLE_TABLENAME_PLUS_COL
        clause = compile_state.statement
    if compile_kwargs:
        kw['compile_kwargs'] = compile_kwargs

    class DontAccess(object):

        def __getattribute__(self, key):
            raise NotImplementedError('compiler accessed .statement; use compiler.current_executable')

    class CheckCompilerAccess(object):

        def __init__(self, test_statement):
            self.test_statement = test_statement
            self._annotations = {}
            self.supports_execution = getattr(test_statement, 'supports_execution', False)
            if self.supports_execution:
                self._execution_options = test_statement._execution_options
                if isinstance(test_statement, (sql.Insert, sql.Update, sql.Delete)):
                    self._returning = test_statement._returning
                if isinstance(test_statement, (sql.Insert, sql.Update)):
                    self._inline = test_statement._inline
                    self._return_defaults = test_statement._return_defaults

        def _default_dialect(self):
            return self.test_statement._default_dialect()

        def compile(self, dialect, **kw):
            return self.test_statement.compile.__func__(self, dialect=dialect, **kw)

        def _compiler(self, dialect, **kw):
            return self.test_statement._compiler.__func__(self, dialect, **kw)

        def _compiler_dispatch(self, compiler, **kwargs):
            if hasattr(compiler, 'statement'):
                with mock.patch.object(compiler, 'statement', DontAccess()):
                    return self.test_statement._compiler_dispatch(compiler, **kwargs)
            else:
                return self.test_statement._compiler_dispatch(compiler, **kwargs)
    c = CheckCompilerAccess(clause).compile(dialect=dialect, **kw)
    param_str = repr(getattr(c, 'params', {}))
    if util.py3k:
        param_str = param_str.encode('utf-8').decode('ascii', 'ignore')
        print((('\nSQL String:\n' + util.text_type(c)) + param_str).encode('utf-8'))
    else:
        print((('\nSQL String:\n' + util.text_type(c).encode('utf-8')) + param_str))
    cc = re.sub('[\\n\\t]', '', util.text_type(c))
    eq_(cc, result, ('%r != %r on dialect %r' % (cc, result, dialect)))
    if (checkparams is not None):
        eq_(c.construct_params(params), checkparams)
    if (checkpositional is not None):
        p = c.construct_params(params)
        eq_(tuple([p[x] for x in c.positiontup]), checkpositional)
    if (check_prefetch is not None):
        eq_(c.prefetch, check_prefetch)
    if (check_literal_execute is not None):
        eq_({c.bind_names[b]: b.effective_value for b in c.literal_execute_params}, check_literal_execute)
    if (check_post_param is not None):
        eq_({c.bind_names[b]: b.effective_value for b in c.post_compile_params}, check_post_param)
def assert_compile(self, clause, result, params=None, checkparams=None, for_executemany=False, check_literal_execute=None, check_post_param=None, dialect=None, checkpositional=None, check_prefetch=None, use_default_dialect=False, allow_dialect_select=False, supports_default_values=True, literal_binds=False, render_postcompile=False, schema_translate_map=None, render_schema_translate=False, default_schema_name=None):
    if use_default_dialect:
        dialect = default.DefaultDialect()
        dialect.supports_default_values = supports_default_values
    elif allow_dialect_select:
        dialect = None
    else:
        if (dialect is None):
            dialect = getattr(self, '__dialect__', None)
        if (dialect is None):
            dialect = config.db.dialect
        elif (dialect == 'default'):
            dialect = default.DefaultDialect()
            dialect.supports_default_values = supports_default_values
        elif (dialect == 'default_enhanced'):
            dialect = default.StrCompileDialect()
        elif isinstance(dialect, util.string_types):
            dialect = url.URL.create(dialect).get_dialect()()
    if default_schema_name:
        dialect.default_schema_name = default_schema_name
    kw = {}
    compile_kwargs = {}
    if schema_translate_map:
        kw['schema_translate_map'] = schema_translate_map
    if (params is not None):
        kw['column_keys'] = list(params)
    if literal_binds:
        compile_kwargs['literal_binds'] = True
    if render_postcompile:
        compile_kwargs['render_postcompile'] = True
    if for_executemany:
        kw['for_executemany'] = True
    if render_schema_translate:
        kw['render_schema_translate'] = True
    from sqlalchemy import orm
    if isinstance(clause, orm.dynamic.AppenderQuery):
        clause = clause._statement
    if isinstance(clause, orm.Query):
        compile_state = clause._compile_state()
        compile_state.statement._label_style = LABEL_STYLE_TABLENAME_PLUS_COL
        clause = compile_state.statement
    if compile_kwargs:
        kw['compile_kwargs'] = compile_kwargs

    class DontAccess(object):

        def __getattribute__(self, key):
            raise NotImplementedError('compiler accessed .statement; use compiler.current_executable')

    class CheckCompilerAccess(object):

        def __init__(self, test_statement):
            self.test_statement = test_statement
            self._annotations = {}
            self.supports_execution = getattr(test_statement, 'supports_execution', False)
            if self.supports_execution:
                self._execution_options = test_statement._execution_options
                if isinstance(test_statement, (sql.Insert, sql.Update, sql.Delete)):
                    self._returning = test_statement._returning
                if isinstance(test_statement, (sql.Insert, sql.Update)):
                    self._inline = test_statement._inline
                    self._return_defaults = test_statement._return_defaults

        def _default_dialect(self):
            return self.test_statement._default_dialect()

        def compile(self, dialect, **kw):
            return self.test_statement.compile.__func__(self, dialect=dialect, **kw)

        def _compiler(self, dialect, **kw):
            return self.test_statement._compiler.__func__(self, dialect, **kw)

        def _compiler_dispatch(self, compiler, **kwargs):
            if hasattr(compiler, 'statement'):
                with mock.patch.object(compiler, 'statement', DontAccess()):
                    return self.test_statement._compiler_dispatch(compiler, **kwargs)
            else:
                return self.test_statement._compiler_dispatch(compiler, **kwargs)
    c = CheckCompilerAccess(clause).compile(dialect=dialect, **kw)
    param_str = repr(getattr(c, 'params', {}))
    if util.py3k:
        param_str = param_str.encode('utf-8').decode('ascii', 'ignore')
        print((('\nSQL String:\n' + util.text_type(c)) + param_str).encode('utf-8'))
    else:
        print((('\nSQL String:\n' + util.text_type(c).encode('utf-8')) + param_str))
    cc = re.sub('[\\n\\t]', , util.text_type(c))
    eq_(cc, result, ('%r != %r on dialect %r' % (cc, result, dialect)))
    if (checkparams is not None):
        eq_(c.construct_params(params), checkparams)
    if (checkpositional is not None):
        p = c.construct_params(params)
        eq_(tuple([p[x] for x in c.positiontup]), checkpositional)
    if (check_prefetch is not None):
        eq_(c.prefetch, check_prefetch)
    if (check_literal_execute is not None):
        eq_({c.bind_names[b]: b.effective_value for b in c.literal_execute_params}, check_literal_execute)
    if (check_post_param is not None):
        eq_({c.bind_names[b]: b.effective_value for b in c.post_compile_params}, check_post_param)