Here are the examples of the python api sqlalchemy.testing.assert_raises_message taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1014 Examples
3
Source : test_reflection.py
with MIT License
from analyzeDFIR
with MIT License
from analyzeDFIR
def test_deprecated_get_primary_keys(self):
meta = self.metadata
users = self.tables.users
insp = Inspector(meta.bind)
assert_raises_message(
sa_exc.SADeprecationWarning,
"Call to deprecated method get_primary_keys."
" Use get_pk_constraint instead.",
insp.get_primary_keys, users.name
)
@testing.provide_metadata
3
Source : test_events.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_immutable_methods(self):
t1 = self.Target()
for meth in [
t1.dispatch.event_one.exec_once,
t1.dispatch.event_one.insert,
t1.dispatch.event_one.append,
t1.dispatch.event_one.remove,
t1.dispatch.event_one.clear,
]:
assert_raises_message(
NotImplementedError, r"need to call for_modify\(\)", meth
)
class NamedCallTest(fixtures.TestBase):
3
Source : test_events.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_no_remove_in_event(self):
Target = self._fixture()
t1 = Target()
def evt():
event.remove(t1, "event_one", evt)
event.listen(t1, "event_one", evt)
assert_raises_message(
Exception, "deque mutated during iteration", t1.dispatch.event_one
)
def test_no_add_in_event(self):
3
Source : test_events.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_no_add_in_event(self):
Target = self._fixture()
t1 = Target()
m1 = Mock()
def evt():
event.listen(t1, "event_one", m1)
event.listen(t1, "event_one", evt)
assert_raises_message(
Exception, "deque mutated during iteration", t1.dispatch.event_one
)
def test_remove_plain_named(self):
3
Source : test_inspect.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_no_inspect(self):
class SomeFoo(TestFixture):
pass
assert_raises_message(
exc.NoInspectionAvailable,
"No inspection system is available for object of type ",
inspect,
SomeFoo,
)
def test_class_insp(self):
3
Source : test_utils.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _assert_unorderable_types(self, callable_):
if util.py36:
assert_raises_message(
TypeError, "not supported between instances of", callable_
)
elif util.py3k:
assert_raises_message(TypeError, "unorderable types", callable_)
else:
assert_raises_message(
TypeError, "cannot compare sets using cmp()", callable_
)
def test_basic_sanity(self):
3
Source : test_engine.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_bad_freetds_warning(self):
engine = engines.testing_engine()
def _bad_version(connection):
return 95, 10, 255
engine.dialect._get_server_version_info = _bad_version
assert_raises_message(
exc.SAWarning, "Unrecognized server version info", engine.connect
)
class EngineFromConfigTest(fixtures.TestBase):
3
Source : test_engine.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_not_supported(self):
dialect, connection = self._fixture(None)
with expect_warnings("Could not fetch transaction isolation level"):
assert_raises_message(
NotImplementedError,
"Can't fetch isolation",
dialect.get_isolation_level,
connection,
)
3
Source : test_types.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_result_processor_invalid(self):
mssql_time_type = TIME()
result_processor = mssql_time_type.result_processor(None, None)
assert_raises_message(
ValueError,
"could not parse 'abc' as a time value",
result_processor,
"abc",
)
class MSDateTypeTest(fixtures.TestBase):
3
Source : test_types.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_result_processor_invalid(self):
mssql_date_type = _MSDate()
result_processor = mssql_date_type.result_processor(None, None)
assert_raises_message(
ValueError,
"could not parse 'abc' as a date value",
result_processor,
"abc",
)
def test_extract(self):
3
Source : test_types.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _test_cant_insert(self, tab):
with testing.db.connect() as conn:
assert_raises_message(
sa.exc.DBAPIError,
r".*Cannot insert an explicit value into a timestamp column.",
conn.execute,
tab.insert().values(data="ins", rv=b"000"),
)
class TypeDDLTest(fixtures.TestBase):
3
Source : test_compiler.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_varchar_raise(self, type_):
type_ = sqltypes.to_instance(type_)
assert_raises_message(
exc.CompileError,
"VARCHAR requires a length on dialect mysql",
type_.compile,
dialect=mysql.dialect(),
)
t1 = Table("sometable", MetaData(), Column("somecolumn", type_))
assert_raises_message(
exc.CompileError,
r"\(in table 'sometable', column 'somecolumn'\)\: "
r"(?:N)?VARCHAR requires a length on dialect mysql",
schema.CreateTable(t1).compile,
dialect=mysql.dialect(),
)
def test_update_limit(self):
3
Source : test_types.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_bitwise_required_for_empty(self):
assert_raises_message(
exc.ArgumentError,
"Can't use the blank value '' in a SET without setting "
"retrieve_as_bitwise=True",
mysql.SET,
"a",
"b",
"",
)
@testing.provide_metadata
3
Source : test_compiler.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_bindparam_quote_raise_on_expanding(self):
assert_raises_message(
exc.CompileError,
"Can't use expanding feature with parameter name 'uid' on "
"Oracle; it requires quoting which is not supported in this "
"context",
bindparam("uid", expanding=True).compile,
dialect=cx_oracle.dialect(),
)
def test_cte(self):
3
Source : test_compiler.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_column_computed_persisted_true(self):
m = MetaData()
t = Table(
"t",
m,
Column("x", Integer),
Column("y", Integer, Computed("x + 2", persisted=True)),
)
assert_raises_message(
exc.CompileError,
r".*Oracle computed columns do not support 'stored' ",
schema.CreateTable(t).compile,
dialect=oracle.dialect(),
)
class SequenceTest(fixtures.TestBase, AssertsCompiledSQL):
3
Source : test_firebird.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_column_computed_raises(self, persisted):
m = MetaData()
t = Table(
"t",
m,
Column("x", Integer),
Column("y", Integer, Computed("x + 2", persisted=persisted)),
)
assert_raises_message(
exc.CompileError,
"Firebird computed columns do not support a persistence method",
schema.CreateTable(t).compile,
dialect=firebird.dialect(),
)
class TypesTest(fixtures.TestBase):
3
Source : test_sqlite.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_cant_parse_datetime_message(self):
for (typ, disp) in [
(Time, "time"),
(DateTime, "datetime"),
(Date, "date"),
]:
assert_raises_message(
ValueError,
"Couldn't parse %s string." % disp,
lambda: testing.db.execute(
text("select 'ASDF' as value").columns(value=typ)
).scalar(),
)
def test_native_datetime(self):
3
Source : test_sqlite.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_column_computed(self, persisted):
m = MetaData()
kwargs = {"persisted": persisted} if persisted != "ignore" else {}
t = Table(
"t",
m,
Column("x", Integer),
Column("y", Integer, Computed("x + 2", **kwargs)),
)
assert_raises_message(
exc.CompileError,
"SQLite does not support computed columns",
schema.CreateTable(t).compile,
dialect=sqlite.dialect(),
)
class AttachedDBTest(fixtures.TestBase):
3
Source : test_sqlite.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_no_autoinc_on_composite_pk(self):
m = MetaData()
t = Table(
"t",
m,
Column("x", Integer, primary_key=True, autoincrement=True),
Column("y", Integer, primary_key=True),
)
assert_raises_message(
exc.CompileError,
"SQLite does not support autoincrement for composite",
CreateTable(t).compile,
dialect=sqlite.dialect(),
)
def test_in_tuple(self):
3
Source : test_sqlite.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_foreign_key_implicit_missing_parent_reflection(self):
# full Table reflection fails however, which is not a new behavior
m = MetaData()
assert_raises_message(
exc.NoSuchTableError,
"fake_table",
Table,
"implicit_referrer_comp_fake",
m,
autoload_with=testing.db,
)
def test_unnamed_inline_foreign_key(self):
3
Source : test_sybase.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_offset_not_supported(self):
stmt = select([1]).offset(10)
assert_raises_message(
NotImplementedError,
"Sybase ASE does not support OFFSET",
stmt.compile,
dialect=self.__dialect__,
)
def test_delete_extra_froms(self):
3
Source : test_bind.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_create_drop_err_metadata(self):
metadata = MetaData()
Table("test_table", metadata, Column("foo", Integer))
for meth in [metadata.create_all, metadata.drop_all]:
assert_raises_message(
exc.UnboundExecutionError,
"MetaData object is not bound to an Engine or Connection.",
meth,
)
def test_create_drop_err_table(self):
3
Source : test_bind.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_create_drop_err_table(self):
metadata = MetaData()
table = Table("test_table", metadata, Column("foo", Integer))
for meth in [table.exists, table.create, table.drop]:
assert_raises_message(
exc.UnboundExecutionError,
(
"Table object 'test_table' is not bound to an Engine or "
"Connection."
),
meth,
)
@testing.uses_deprecated()
3
Source : test_deprecations.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_dont_touch_non_dbapi_exception_on_contextual_connect(self):
dbapi = self.dbapi
dbapi.connect = Mock(side_effect=TypeError("I'm not a DBAPI error"))
e = create_engine("sqlite://", module=dbapi)
e.dialect.is_disconnect = is_disconnect = Mock()
with testing.expect_deprecated(
r"The Engine.contextual_connect\(\) method is deprecated"
):
assert_raises_message(
TypeError, "I'm not a DBAPI error", e.contextual_connect
)
eq_(is_disconnect.call_count, 0)
def test_invalidate_on_contextual_connect(self):
3
Source : test_execute.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_exception_wrapping_dbapi(self):
conn = testing.db.connect()
for _c in testing.db, conn:
assert_raises_message(
tsa.exc.DBAPIError,
r"not_a_valid_statement",
_c.execute,
"not_a_valid_statement",
)
@testing.requires.sqlite
3
Source : test_execute.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_exception_wrapping_non_dbapi_error(self):
e = create_engine("sqlite://")
e.dialect.is_disconnect = is_disconnect = Mock()
with e.connect() as c:
c.connection.cursor = Mock(
return_value=Mock(
execute=Mock(
side_effect=TypeError("I'm not a DBAPI error")
)
)
)
assert_raises_message(
TypeError, "I'm not a DBAPI error", c.execute, "select "
)
eq_(is_disconnect.call_count, 0)
def test_exception_wrapping_non_standard_dbapi_error(self):
3
Source : test_execute.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_transaction_engine_ctx_rollback(self):
fn = self._trans_rollback_fn()
ctx = testing.db.begin()
assert_raises_message(
Exception,
"breakage",
testing.run_as_contextmanager,
ctx,
fn,
5,
value=8,
)
self._assert_no_data()
def test_transaction_connection_ctx_commit(self):
3
Source : test_execute.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_transaction_connection_ctx_rollback(self):
fn = self._trans_rollback_fn(True)
with testing.db.connect() as conn:
ctx = conn.begin()
assert_raises_message(
Exception,
"breakage",
testing.run_as_contextmanager,
ctx,
fn,
5,
value=8,
)
self._assert_no_data()
def test_connection_as_ctx(self):
3
Source : test_execute.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_transaction_engine_fn_rollback(self):
fn = self._trans_rollback_fn()
assert_raises_message(
Exception, "breakage", testing.db.transaction, fn, 5, value=8
)
self._assert_no_data()
def test_transaction_connection_fn_commit(self):
3
Source : test_execute.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_cant_listen_to_option_engine(self):
from sqlalchemy.engine import base
def evt(*arg, **kw):
pass
assert_raises_message(
tsa.exc.InvalidRequestError,
r"Can't assign an event directly to the "
" < class 'sqlalchemy.engine.base.OptionEngine'> class",
event.listen,
base.OptionEngine,
"before_cursor_execute",
evt,
)
@testing.requires.ad_hoc_engines
3
Source : test_execute.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_dont_touch_non_dbapi_exception_on_connect(self):
dbapi = self.dbapi
dbapi.connect = Mock(side_effect=TypeError("I'm not a DBAPI error"))
e = create_engine("sqlite://", module=dbapi)
e.dialect.is_disconnect = is_disconnect = Mock()
assert_raises_message(TypeError, "I'm not a DBAPI error", e.connect)
eq_(is_disconnect.call_count, 0)
def test_ensure_dialect_does_is_disconnect_no_conn(self):
3
Source : test_logging.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_exception_format_hide_parameters_dbapi_round_trip(self):
assert_raises_message(
tsa.exc.DBAPIError,
r".*INSERT INTO nonexistent \(data\) values \(:data\)\]\n"
r"\[SQL parameters hidden due to hide_parameters=True\]",
lambda: self.no_param_engine.execute(
"INSERT INTO nonexistent (data) values (:data)",
[{"data": str(i)} for i in range(10)],
),
)
def test_exception_format_hide_parameters_nondbapi_round_trip(self):
3
Source : test_logging.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_error_large_dict(self):
assert_raises_message(
tsa.exc.DBAPIError,
r".*INSERT INTO nonexistent \(data\) values \(:data\)\]\n"
r"\[parameters: "
r"\[{'data': '0'}, {'data': '1'}, {'data': '2'}, "
r"{'data': '3'}, {'data': '4'}, {'data': '5'}, "
r"{'data': '6'}, {'data': '7'} ... displaying 10 of "
r"100 total bound parameter sets ... {'data': '98'}, "
r"{'data': '99'}\]",
lambda: self.eng.execute(
"INSERT INTO nonexistent (data) values (:data)",
[{"data": str(i)} for i in range(100)],
),
)
def test_error_large_list(self):
3
Source : test_logging.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_error_large_list(self):
assert_raises_message(
tsa.exc.DBAPIError,
r".*INSERT INTO nonexistent \(data\) values "
r"\(\?\)\]\n\[parameters: \[\('0',\), \('1',\), \('2',\), "
r"\('3',\), \('4',\), \('5',\), \('6',\), \('7',\) "
r"... displaying "
r"10 of 100 total bound parameter sets ... "
r"\('98',\), \('99',\)\]",
lambda: self.eng.execute(
"INSERT INTO nonexistent (data) values (?)",
[(str(i),) for i in range(100)],
),
)
class PoolLoggingTest(fixtures.TestBase):
3
Source : test_pool.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_no_double_checkin(self):
p = self._queuepool_fixture(pool_size=1)
c1 = p.connect()
rec = c1._connection_record
c1.close()
assert_raises_message(
Warning, "Double checkin attempted on %s" % rec, rec.checkin
)
def test_lifo(self):
3
Source : test_processors.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_date_no_string(self):
assert_raises_message(
ValueError,
"Couldn't parse date string '2012' - value is not a string",
self.module.str_to_date,
2012,
)
def test_datetime_no_string(self):
3
Source : test_processors.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_datetime_no_string(self):
assert_raises_message(
ValueError,
"Couldn't parse datetime string '2012' - value is not a string",
self.module.str_to_datetime,
2012,
)
def test_time_no_string(self):
3
Source : test_processors.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_time_no_string(self):
assert_raises_message(
ValueError,
"Couldn't parse time string '2012' - value is not a string",
self.module.str_to_time,
2012,
)
def test_date_invalid_string(self):
3
Source : test_processors.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_date_invalid_string(self):
assert_raises_message(
ValueError,
"Couldn't parse date string: '5:a'",
self.module.str_to_date,
"5:a",
)
def test_datetime_invalid_string(self):
3
Source : test_processors.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_datetime_invalid_string(self):
assert_raises_message(
ValueError,
"Couldn't parse datetime string: '5:a'",
self.module.str_to_datetime,
"5:a",
)
def test_time_invalid_string(self):
3
Source : test_processors.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_time_invalid_string(self):
assert_raises_message(
ValueError,
"Couldn't parse time string: '5:a'",
self.module.str_to_time,
"5:a",
)
class PyDateProcessorTest(_DateProcessorTest):
3
Source : test_reconnect.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_waits_til_exec_wo_ping_db_is_stopped(self):
pool = self._pool_fixture(pre_ping=False)
conn = pool.connect()
conn.close()
self.dbapi.shutdown("execute", stop=True)
conn = pool.connect()
cursor = conn.cursor()
assert_raises_message(
MockDisconnect,
"Lost the DB connection on execute",
cursor.execute,
"foo",
)
def test_waits_til_exec_wo_ping_db_is_restarted(self):
3
Source : test_reconnect.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_invalidated_close(self):
conn = self.db.connect()
self.dbapi.shutdown()
assert_raises(tsa.exc.DBAPIError, conn.execute, select([1]))
conn.close()
assert conn.closed
assert conn.invalidated
assert_raises_message(
tsa.exc.StatementError,
"This Connection is closed",
conn.execute,
select([1]),
)
def test_noreconnect_execute_plus_closewresult(self):
3
Source : test_reconnect.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_noreconnect_execute_plus_closewresult(self):
conn = self.db.connect(close_with_result=True)
self.dbapi.shutdown("execute_no_disconnect")
# raises error
assert_raises_message(
tsa.exc.DBAPIError,
"something broke on execute but we didn't lose the connection",
conn.execute,
select([1]),
)
assert conn.closed
assert not conn.invalidated
def test_noreconnect_rollback_plus_closewresult(self):
3
Source : test_reconnect.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_check_disconnect_no_cursor(self):
conn = self.db.connect()
result = conn.execute(select([1]))
result.cursor.close()
conn.close()
assert_raises_message(
tsa.exc.DBAPIError, "cursor closed", list, result
)
def test_dialect_initialize_once(self):
3
Source : test_reflection.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_fk_error(self):
metadata = MetaData(testing.db)
Table(
"slots",
metadata,
Column("slot_id", sa.Integer, primary_key=True),
Column("pkg_id", sa.Integer, sa.ForeignKey("pkgs.pkg_id")),
Column("slot", sa.String(128)),
)
assert_raises_message(
sa.exc.InvalidRequestError,
"Foreign key associated with column 'slots.pkg_id' "
"could not find table 'pkgs' with which to generate "
"a foreign key to target column 'pkg_id'",
metadata.create_all,
)
def test_composite_pks(self):
3
Source : test_transaction.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_invalid_level(self):
eng = testing_engine(options=dict(isolation_level="FOO"))
assert_raises_message(
exc.ArgumentError,
"Invalid value '%s' for isolation_level. "
"Valid isolation levels for %s are %s"
% (
"FOO",
eng.dialect.name,
", ".join(eng.dialect._isolation_lookup),
),
eng.connect,
)
def test_connection_invalidated(self):
3
Source : test_transaction.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_per_statement_bzzt(self):
assert_raises_message(
exc.ArgumentError,
r"'isolation_level' execution option may only be specified "
r"on Connection.execution_options\(\), or "
r"per-engine using the isolation_level "
r"argument to create_engine\(\).",
select([1]).execution_options,
isolation_level=self._non_default_isolation_level(),
)
def test_per_engine(self):
3
Source : test_basic.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_no_table(self):
def go():
class User(Base):
id = Column("id", Integer, primary_key=True)
assert_raises_message(
sa.exc.InvalidRequestError, "does not have a __table__", go
)
def test_table_args_empty_dict(self):
3
Source : test_basic.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_column_named_twice(self):
def go():
class Foo(Base):
__tablename__ = "foo"
id = Column(Integer, primary_key=True)
x = Column("x", Integer)
y = Column("x", Integer)
assert_raises_message(
sa.exc.SAWarning,
"On class 'Foo', Column object 'x' named directly multiple times, "
"only one will be used: x, y",
go,
)
def test_column_repeated_under_prop(self):
See More Examples