Here are the examples of the python api sqlalchemy.testing.exclusions.against taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
58 Examples
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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",
),
]
)
@property
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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])
@property
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def array_type(self):
return only_on(
[
lambda config: against(config, "postgresql")
and not against(config, "+pg8000")
and not against(config, "+zxjdbc")
]
)
@property
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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",
]
)
def _sqlite_file_db(self, config):
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _sqlite_file_db(self, config):
return against(config, "sqlite") and config.db.dialect._is_url_file_db(
config.db.url
)
def _sqlite_memory_db(self, config):
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _sqlite_memory_db(self, config):
return against(
config, "sqlite"
) and not config.db.dialect._is_url_file_db(config.db.url)
def _sqlite_json(self, config):
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _sqlite_json(self, config):
if not against(config, "sqlite >= 3.9"):
return False
else:
with config.db.connect() as conn:
try:
return (
conn.scalar(
"""select json_extract('{"foo": "bar"}', """
"""'$."foo"')"""
)
== "bar"
)
except exc.DBAPIError:
return False
@property
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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",
]
)
@property
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _has_pg_extension(self, name):
def check(config):
if not against(config, "postgresql"):
return False
count = config.db.scalar(
"SELECT count(*) FROM pg_extension "
"WHERE extname='%s'" % name
)
return bool(count)
return only_if(check, "needs %s extension" % name)
@property
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def range_types(self):
def check_range_types(config):
if not against(
config, ["postgresql+psycopg2", "postgresql+psycopg2cffi"]
):
return False
try:
config.db.scalar("select '[1,2)'::int4range;")
return True
except Exception:
return False
return only_if(check_range_types)
@property
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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"
)
@property
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def mysql_zero_date(self):
def check(config):
if not against(config, "mysql"):
return False
row = config.db.execute("show variables like 'sql_mode'").first()
return not row or "NO_ZERO_DATE" not in row[1]
return only_if(check)
@property
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def mysql_non_strict(self):
def check(config):
if not against(config, "mysql"):
return False
row = config.db.execute("show variables like 'sql_mode'").first()
return not row or "STRICT_TRANS_TABLES" not in row[1]
return only_if(check)
@property
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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)
def _mariadb_102(self, config):
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _mariadb_102(self, config):
return (
against(config, "mysql")
and config.db.dialect._is_mariadb
and config.db.dialect._mariadb_normalized_version_info > (10, 2)
)
def _mysql_and_check_constraints_exist(self, config):
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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
def _mysql_check_constraints_exist(self, config):
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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)
def _mysql_check_constraints_dont_exist(self, config):
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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)
)
def _mysql_not_mariadb_103(self, config):
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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)
)
def _mysql_not_mariadb_104(self, config):
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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)
)
def _has_mysql_on_windows(self, config):
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _has_mysql_on_windows(self, config):
return (
against(config, "mysql")
and config.db.dialect._detect_casing(config.db) == 1
)
def _has_mysql_fully_case_sensitive(self, config):
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _has_mysql_fully_case_sensitive(self, config):
return (
against(config, "mysql")
and config.db.dialect._detect_casing(config.db) == 0
)
@property
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def postgresql_utf8_server_encoding(self):
return only_if(
lambda config: against(config, "postgresql")
and config.db.scalar("show server_encoding").lower() == "utf8"
)
@property
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def cxoracle6_or_greater(self):
return only_if(
lambda config: against(config, "oracle+cx_oracle")
and config.db.dialect.cx_oracle_ver >= (6,)
)
@property
3
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def oracle5x(self):
return only_if(
lambda config: against(config, "oracle+cx_oracle")
and config.db.dialect.cx_oracle_ver < (6,)
)
@property
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def foreign_key_constraint_name_reflection(self):
return fails_if(
lambda config: against(config, ["mysql", "mariadb"])
and not self._mysql_80(config)
and not self._mariadb_105(config)
)
@property
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
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", "mariadb", "postgresql", _sqlite_tuple_in, "oracle"]
)
@property
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def tuple_valued_builtin_functions(self):
return only_on(
lambda config: self._sqlite_json(config)
or against(config, "postgresql")
)
@property
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def array_type(self):
return only_on(
[
lambda config: against(config, "postgresql")
and not against(config, "+pg8000")
]
)
@property
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
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,
"mariadb",
"sqlite",
]
)
@property
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
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
@property
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def _has_pg_extension(self, name):
def check(config):
if not against(config, "postgresql"):
return False
with config.db.connect() as conn:
count = conn.exec_driver_sql(
"SELECT count(*) FROM pg_extension "
"WHERE extname='%s'" % name
).scalar()
return bool(count)
return only_if(check, "needs %s extension" % name)
@property
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def mysql_zero_date(self):
def check(config):
if not against(config, "mysql"):
return False
with config.db.connect() as conn:
row = conn.exec_driver_sql(
"show variables like 'sql_mode'"
).first()
return not row or "NO_ZERO_DATE" not in row[1]
return only_if(check)
@property
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def mysql_non_strict(self):
def check(config):
if not against(config, "mysql"):
return False
with config.db.connect() as conn:
row = conn.exec_driver_sql(
"show variables like 'sql_mode'"
).first()
return not row or "STRICT_TRANS_TABLES" not in row[1]
return only_if(check)
@property
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
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)
def _mysql_80(self, config):
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def _mysql_80(self, config):
return (
against(config, "mysql")
and config.db.dialect._is_mysql
and config.db.dialect.server_version_info >= (8,)
)
def _mariadb_102(self, config):
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def _mariadb_102(self, config):
return (
against(config, ["mysql", "mariadb"])
and config.db.dialect._is_mariadb
and config.db.dialect._mariadb_normalized_version_info >= (10, 2)
)
def _mariadb_105(self, config):
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def _mariadb_105(self, config):
return (
against(config, ["mysql", "mariadb"])
and config.db.dialect._is_mariadb
and config.db.dialect._mariadb_normalized_version_info >= (10, 5)
)
def _mysql_and_check_constraints_exist(self, config):
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def _mysql_and_check_constraints_exist(self, config):
# 1. we have mysql / mariadb and
# 2. it enforces check constraints
if exclusions.against(config, ["mysql", "mariadb"]):
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
def _mysql_check_constraints_exist(self, config):
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
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", "mariadb"]
) or self._mysql_and_check_constraints_exist(config)
def _mysql_check_constraints_dont_exist(self, config):
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def _mysql_not_mariadb_102(self, config):
return (against(config, ["mysql", "mariadb"])) and (
not config.db.dialect._is_mariadb
or config.db.dialect._mariadb_normalized_version_info < (10, 2)
)
def _mysql_not_mariadb_103(self, config):
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def _mysql_not_mariadb_103(self, config):
return (against(config, ["mysql", "mariadb"])) and (
not config.db.dialect._is_mariadb
or config.db.dialect._mariadb_normalized_version_info < (10, 3)
)
def _mysql_not_mariadb_104(self, config):
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def _mysql_not_mariadb_104(self, config):
return (against(config, ["mysql", "mariadb"])) and (
not config.db.dialect._is_mariadb
or config.db.dialect._mariadb_normalized_version_info < (10, 4)
)
def _has_mysql_on_windows(self, config):
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def _has_mysql_on_windows(self, config):
with config.db.connect() as conn:
return (
against(config, ["mysql", "mariadb"])
) and config.db.dialect._detect_casing(conn) == 1
def _has_mysql_fully_case_sensitive(self, config):
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def _has_mysql_fully_case_sensitive(self, config):
with config.db.connect() as conn:
return (
against(config, "mysql")
and config.db.dialect._detect_casing(conn) == 0
)
@property
3
Source : requirements.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def postgresql_utf8_server_encoding(self):
def go(config):
if not against(config, "postgresql"):
return False
with config.db.connect() as conn:
enc = conn.exec_driver_sql("show server_encoding").scalar()
return enc.lower() == "utf8"
return only_if(go)
@property
0
Source : plugin_base.py
with MIT License
from analyzeDFIR
with MIT License
from analyzeDFIR
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'])))
@post
0
Source : plugin_base.py
with MIT License
from dhina016
with MIT License
from dhina016
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"]
)
)
)
@post
0
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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}
@property
0
Source : requirements.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
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",
]
)
@property
See More Examples