Python sqlalchemy.testing.exclusions.against() Examples

The following are 30 code examples of sqlalchemy.testing.exclusions.against(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlalchemy.testing.exclusions , or try the search function .
Example #1
Source File: requirements.py    From sqlalchemy with MIT License 6 votes vote down vote up
def unicode_ddl(self):
        """Target driver must support some degree of non-ascii symbol names."""
        # TODO: expand to exclude MySQLdb versions w/ broken unicode

        return skip_if(
            [
                no_support("oracle", "FIXME: no support in database?"),
                no_support("sybase", "FIXME: guessing, needs confirmation"),
                no_support("mssql+pymssql", "no FreeTDS support"),
                LambdaPredicate(
                    lambda config: against(config, "mysql+mysqlconnector")
                    and config.db.dialect._mysqlconnector_version_info > (2, 0)
                    and util.py2k,
                    "bug in mysqlconnector 2.0",
                ),
                exclude(
                    "mysql", "<", (4, 1, 1), "no unicode connection support"
                ),
            ]
        ) 
Example #2
Source File: requirements.py    From sqlalchemy with MIT License 6 votes vote down vote up
def pyodbc_fast_executemany(self):
        def has_fastexecutemany(config):
            if not against(config, "mssql+pyodbc"):
                return False
            if config.db.dialect._dbapi_version() < (4, 0, 19):
                return False
            with config.db.connect() as conn:
                drivername = conn.connection.connection.getinfo(
                    config.db.dialect.dbapi.SQL_DRIVER_NAME
                )
                # on linux this is something like 'libmsodbcsql-13.1.so.9.2'.
                # on Windows this is something like 'msodbcsql17.dll'.
                return "msodbc" in drivername

        return only_if(
            has_fastexecutemany, "only on pyodbc > 4.0.19 w/ msodbc driver"
        ) 
Example #3
Source File: requirements.py    From sqlalchemy with MIT License 6 votes vote down vote up
def precision_numerics_many_significant_digits(self):
        """target backend supports values with many digits on both sides,
        such as 319438950232418390.273596, 87673.594069654243

        """

        def broken_cx_oracle(config):
            return (
                against(config, "oracle+cx_oracle")
                and config.db.dialect.cx_oracle_ver <= (6, 0, 2)
                and config.db.dialect.cx_oracle_ver > (6,)
            )

        return fails_if(
            [
                ("sqlite", None, None, "TODO"),
                ("firebird", None, None, "Precision must be from 1 to 18"),
                ("sybase+pysybase", None, None, "TODO"),
            ]
        ) 
Example #4
Source File: requirements.py    From sqlalchemy with MIT License 6 votes vote down vote up
def json_type(self):
        return only_on(
            [
                lambda config: against(config, "mysql")
                and (
                    (
                        not config.db.dialect._is_mariadb
                        and against(config, "mysql >= 5.7")
                    )
                    or (
                        config.db.dialect._mariadb_normalized_version_info
                        >= (10, 2, 7)
                    )
                ),
                "postgresql >= 9.3",
                self._sqlite_json,
            ]
        ) 
Example #5
Source File: requirements.py    From sqlalchemy with MIT License 6 votes vote down vote up
def ctes(self):
        """Target database supports CTEs"""
        return only_on(
            [
                lambda config: against(config, "mysql")
                and (
                    (
                        config.db.dialect._is_mariadb
                        and config.db.dialect._mariadb_normalized_version_info
                        >= (10, 2)
                    )
                    or (
                        not config.db.dialect._is_mariadb
                        and config.db.dialect.server_version_info >= (8,)
                    )
                ),
                "postgresql",
                "mssql",
                "oracle",
                "sqlite>=3.8.3",
            ]
        ) 
Example #6
Source File: requirements.py    From sqlalchemy with MIT License 6 votes vote down vote up
def get_isolation_levels(self, config):
        levels = set(config.db.dialect._isolation_lookup)

        if against(config, "sqlite"):
            default = "SERIALIZABLE"
            levels.add("AUTOCOMMIT")
        elif against(config, "postgresql"):
            default = "READ COMMITTED"
            levels.add("AUTOCOMMIT")
        elif against(config, "mysql"):
            default = "REPEATABLE READ"
            levels.add("AUTOCOMMIT")
        elif against(config, "mssql"):
            default = "READ COMMITTED"
            levels.add("AUTOCOMMIT")
        elif against(config, "oracle"):
            default = "READ COMMITTED"
            levels.add("AUTOCOMMIT")
        else:
            raise NotImplementedError()

        return {"default": default, "supported": levels} 
Example #7
Source File: requirements.py    From sqlalchemy with MIT License 6 votes vote down vote up
def non_native_boolean_unconstrained(self):
        """target database is not native boolean and allows arbitrary integers
        in it's "bool" column"""

        return skip_if(
            [
                LambdaPredicate(
                    lambda config: against(config, "mssql"),
                    "SQL Server drivers / odbc seem to change "
                    "their mind on this",
                ),
                LambdaPredicate(
                    lambda config: config.db.dialect.supports_native_boolean,
                    "native boolean dialect",
                ),
            ]
        ) 
Example #8
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _mysql_not_mariadb_102(self, config):
        return against(config, "mysql") and (
            not config.db.dialect._is_mariadb
            or config.db.dialect._mariadb_normalized_version_info < (10, 2)
        ) 
Example #9
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _mysql_not_mariadb_103(self, config):
        return against(config, "mysql") and (
            not config.db.dialect._is_mariadb
            or config.db.dialect._mariadb_normalized_version_info < (10, 3)
        ) 
Example #10
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def cxoracle6_or_greater(self):
        return only_if(
            lambda config: against(config, "oracle+cx_oracle")
            and config.db.dialect.cx_oracle_ver >= (6,)
        ) 
Example #11
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _mysql_check_constraints_exist(self, config):
        # 1. we dont have mysql / mariadb or
        # 2. we have mysql / mariadb that enforces check constraints
        return not exclusions.against(
            config, "mysql"
        ) or self._mysql_and_check_constraints_exist(config) 
Example #12
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _mysql_not_mariadb_104(self, config):
        return against(config, "mysql") and (
            not config.db.dialect._is_mariadb
            or config.db.dialect._mariadb_normalized_version_info < (10, 4)
        ) 
Example #13
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _mysql_and_check_constraints_exist(self, config):
        # 1. we have mysql / mariadb and
        # 2. it enforces check constraints
        if exclusions.against(config, "mysql"):
            if config.db.dialect._is_mariadb:
                norm_version_info = (
                    config.db.dialect._mariadb_normalized_version_info
                )
                return norm_version_info >= (10, 2)
            else:
                norm_version_info = config.db.dialect.server_version_info
                return norm_version_info >= (8, 0, 16)
        else:
            return False 
Example #14
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _mysql_80(self, config):
        return (
            against(config, "mysql")
            and config.db.dialect._is_mysql
            and config.db.dialect.server_version_info >= (8,)
        ) 
Example #15
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def mysql_ngram_fulltext(self):
        def check(config):
            return (
                against(config, "mysql")
                and not config.db.dialect._is_mariadb
                and config.db.dialect.server_version_info >= (5, 7)
            )

        return only_if(check) 
Example #16
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def mysql_non_strict(self):
        def check(config):
            if not against(config, "mysql"):
                return False

            row = (
                config.db.connect(close_with_result=True)
                .exec_driver_sql("show variables like 'sql_mode'")
                .first()
            )
            return not row or "STRICT_TRANS_TABLES" not in row[1]

        return only_if(check) 
Example #17
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _has_mysql_fully_case_sensitive(self, config):
        return (
            against(config, "mysql")
            and config.db.dialect._detect_casing(config.db) == 0
        ) 
Example #18
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def mysql_zero_date(self):
        def check(config):
            if not against(config, "mysql"):
                return False

            row = (
                config.db.connect(close_with_result=True)
                .exec_driver_sql("show variables like 'sql_mode'")
                .first()
            )
            return not row or "NO_ZERO_DATE" not in row[1]

        return only_if(check) 
Example #19
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def postgresql_utf8_server_encoding(self):

        return only_if(
            lambda config: against(config, "postgresql")
            and config.db.connect(close_with_result=True)
            .exec_driver_sql("show server_encoding")
            .scalar()
            .lower()
            == "utf8"
        ) 
Example #20
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _has_pg_extension(self, name):
        def check(config):
            if not against(config, "postgresql"):
                return False
            count = (
                config.db.connect(close_with_result=True)
                .exec_driver_sql(
                    "SELECT count(*) FROM pg_extension "
                    "WHERE extname='%s'" % name
                )
                .scalar()
            )
            return bool(count)

        return only_if(check, "needs %s extension" % name) 
Example #21
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def implicit_decimal_binds(self):
        """target backend will return a selected Decimal as a Decimal, not
        a string.

        e.g.::

            expr = decimal.Decimal("15.7563")

            value = e.scalar(
                select([literal(expr)])
            )

            assert value == expr

        See :ticket:`4036`

        """

        # fixed for mysqlclient in
        # https://github.com/PyMySQL/mysqlclient-python/commit/68b9662918577fc05be9610ef4824a00f2b051b0
        def check(config):
            if against(config, "mysql+mysqldb"):
                # can remove once post 1.3.13 is released
                try:
                    from MySQLdb import converters
                    from decimal import Decimal

                    return Decimal not in converters.conversions
                except:
                    return True

            return against(
                config, "mysql+mysqldb"
            ) and config.db.dialect._mysql_dbapi_version <= (1, 3, 13)

        return exclusions.fails_on(check, "fixed for mysqlclient post 1.3.13") 
Example #22
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def reflects_json_type(self):
        return only_on(
            [
                lambda config: against(config, "mysql >= 5.7")
                and not config.db.dialect._is_mariadb,
                "postgresql >= 9.3",
                "sqlite >= 3.9",
            ]
        ) 
Example #23
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _sqlite_json(self, config):
        if not against(config, "sqlite >= 3.9"):
            return False
        else:
            with config.db.connect() as conn:
                try:
                    return (
                        conn.exec_driver_sql(
                            """select json_extract('{"foo": "bar"}', """
                            """'$."foo"')"""
                        ).scalar()
                        == "bar"
                    )
                except exc.DBAPIError:
                    return False 
Example #24
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def _sqlite_file_db(self, config):
        return against(config, "sqlite") and config.db.dialect._is_url_file_db(
            config.db.url
        ) 
Example #25
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def json_index_supplementary_unicode_element(self):
        # for sqlite see https://bugs.python.org/issue38749
        return skip_if(
            [
                lambda config: against(config, "mysql")
                and config.db.dialect._is_mariadb,
                "sqlite",
            ]
        ) 
Example #26
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def array_type(self):
        return only_on(
            [
                lambda config: against(config, "postgresql")
                and not against(config, "+pg8000")
            ]
        ) 
Example #27
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def tuple_in(self):
        def _sqlite_tuple_in(config):
            return against(
                config, "sqlite"
            ) and config.db.dialect.dbapi.sqlite_version_info >= (3, 15, 0)

        return only_on(["mysql", "postgresql", _sqlite_tuple_in]) 
Example #28
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def binary_comparisons(self):
        """target database/driver can allow BLOB/BINARY fields to be compared
        against a bound parameter value.
        """
        return skip_if(["oracle", "mssql"], "not supported by database/driver") 
Example #29
Source File: requirements.py    From sqlalchemy with MIT License 5 votes vote down vote up
def oracle5x(self):
        return only_if(
            lambda config: against(config, "oracle+cx_oracle")
            and config.db.dialect.cx_oracle_ver < (6,)
        ) 
Example #30
Source File: plugin_base.py    From jarvis with GNU General Public License v2.0 4 votes vote down vote up
def _prep_testing_database(options, file_config):
    from sqlalchemy.testing import config, util
    from sqlalchemy.testing.exclusions import against
    from sqlalchemy import schema, inspect

    if options.dropfirst:
        for cfg in config.Config.all_configs():
            e = cfg.db
            inspector = inspect(e)
            try:
                view_names = inspector.get_view_names()
            except NotImplementedError:
                pass
            else:
                for vname in view_names:
                    e.execute(schema._DropView(
                        schema.Table(vname, schema.MetaData())
                    ))

            if config.requirements.schemas.enabled_for_config(cfg):
                try:
                    view_names = inspector.get_view_names(
                        schema="test_schema")
                except NotImplementedError:
                    pass
                else:
                    for vname in view_names:
                        e.execute(schema._DropView(
                            schema.Table(vname, schema.MetaData(),
                                         schema="test_schema")
                        ))

            util.drop_all_tables(e, inspector)

            if config.requirements.schemas.enabled_for_config(cfg):
                util.drop_all_tables(e, inspector, schema=cfg.test_schema)

            if against(cfg, "postgresql"):
                from sqlalchemy.dialects import postgresql
                for enum in inspector.get_enums("*"):
                    e.execute(postgresql.DropEnumType(
                        postgresql.ENUM(
                            name=enum['name'],
                            schema=enum['schema'])))