本文整理汇总了Python中test.lib.testing.assert_raises函数的典型用法代码示例。如果您正苦于以下问题:Python assert_raises函数的具体用法?Python assert_raises怎么用?Python assert_raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_raises函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_versioncheck_for_update
def test_versioncheck_for_update(self):
"""query.with_lockmode performs a 'version check' on an already loaded instance"""
Foo = self.classes.Foo
s1 = self._fixture()
f1s1 = Foo(value='f1 value')
s1.add(f1s1)
s1.commit()
s2 = create_session(autocommit=False)
f1s2 = s2.query(Foo).get(f1s1.id)
s2.refresh(f1s2, lockmode='update')
f1s2.value='f1 new value'
assert_raises(
exc.DBAPIError,
s1.refresh, f1s1, lockmode='update_nowait'
)
s1.rollback()
s2.commit()
s1.refresh(f1s1, lockmode='update_nowait')
assert f1s1.version_id == f1s2.version_id
开发者ID:NoNo1234,项目名称:the_walking_project,代码行数:25,代码来源:test_versioning.py
示例2: test_literal_interpretation
def test_literal_interpretation(self):
t = table('test', column('col1'))
assert_raises(exc.ArgumentError, case, [("x", "y")])
self.assert_compile(case([("x", "y")], value=t.c.col1), "CASE test.col1 WHEN :param_1 THEN :param_2 END")
self.assert_compile(case([(t.c.col1==7, "y")], else_="z"), "CASE WHEN (test.col1 = :col1_1) THEN :param_1 ELSE :param_2 END")
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:7,代码来源:test_case_statement.py
示例3: test_pk_violation_with_savepoint
def test_pk_violation_with_savepoint(self):
User, Address = self.classes.User, self.classes.Address
s = self.session()
a1 = Address(email_address='foo')
u1 = User(id=1, name='ed', addresses=[a1])
s.add(u1)
s.commit()
a2 = Address(email_address='bar')
u2 = User(id=1, name='jack', addresses=[a2])
u1.name = 'edward'
a1.email_address = 'foober'
s.begin_nested()
s.add(u2)
assert_raises(sa_exc.FlushError, s.commit)
assert_raises(sa_exc.InvalidRequestError, s.commit)
s.rollback()
assert u2 not in s
assert a2 not in s
assert u1 in s
assert a1 in s
s.commit()
eq_(
s.query(User).all(),
[User(id=1, name='edward',
addresses=[Address(email_address='foober')])]
)
开发者ID:ioram7,项目名称:keystone-federado-pgid2013,代码行数:29,代码来源:test_transaction.py
示例4: test_accounting_commit_fails_delete
def test_accounting_commit_fails_delete(self):
User = self.classes.User
sess = create_session(autocommit=True)
fail = False
def fail_fn(*arg, **kw):
if fail:
raise Exception("commit fails")
event.listen(sess, "after_flush_postexec", fail_fn)
u1 = User(name='ed')
sess.add(u1)
sess.flush()
sess.delete(u1)
fail = True
assert_raises(
Exception,
sess.flush
)
fail = False
assert u1 in sess
assert u1 not in sess.deleted
sess.delete(u1)
sess.flush()
assert u1 not in sess
eq_(
sess.query(User.name).order_by(User.name).all(),
[]
)
开发者ID:ioram7,项目名称:keystone-federado-pgid2013,代码行数:31,代码来源:test_transaction.py
示例5: test_noninherited_warning
def test_noninherited_warning(self):
A, B, b_table, a_table, Dest, dest_table = (self.classes.A,
self.classes.B,
self.tables.b_table,
self.tables.a_table,
self.classes.Dest,
self.tables.dest_table)
mapper(A, a_table, properties={'some_dest': relationship(Dest)})
mapper(B, b_table, inherits=A, concrete=True)
mapper(Dest, dest_table)
b = B()
dest = Dest()
assert_raises(AttributeError, setattr, b, 'some_dest', dest)
clear_mappers()
mapper(A, a_table, properties={'a_id': a_table.c.id})
mapper(B, b_table, inherits=A, concrete=True)
mapper(Dest, dest_table)
b = B()
assert_raises(AttributeError, setattr, b, 'a_id', 3)
clear_mappers()
mapper(A, a_table, properties={'a_id': a_table.c.id})
mapper(B, b_table, inherits=A, concrete=True)
mapper(Dest, dest_table)
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:26,代码来源:test_concrete.py
示例6: test_explode_in_initializer
def test_explode_in_initializer(self):
engine = engines.testing_engine()
def broken_initialize(connection):
connection.execute("select fake_stuff from _fake_table")
engine.dialect.initialize = broken_initialize
# raises a DBAPIError, not an AttributeError
assert_raises(exc.DBAPIError, engine.connect)
# dispose connections so we get a new one on
# next go
engine.dispose()
p1 = engine.pool
def is_disconnect(e, conn, cursor):
return True
engine.dialect.is_disconnect = is_disconnect
# invalidate() also doesn't screw up
assert_raises(exc.DBAPIError, engine.connect)
# pool was recreated
assert engine.pool is not p1
开发者ID:onetera,项目名称:scandatatransfer,代码行数:27,代码来源:test_reconnect.py
示例7: test_rollback_hook
def test_rollback_hook(self):
User, users = self.classes.User, self.tables.users
sess, canary = self._listener_fixture()
mapper(User, users)
u = User(name="u1", id=1)
sess.add(u)
sess.commit()
u2 = User(name="u1", id=1)
sess.add(u2)
assert_raises(sa.orm.exc.FlushError, sess.commit)
sess.rollback()
eq_(
canary,
[
"after_attach",
"before_commit",
"before_flush",
"after_begin",
"after_flush",
"after_flush_postexec",
"after_commit",
"after_attach",
"before_commit",
"before_flush",
"after_begin",
"after_rollback",
"after_soft_rollback",
"after_soft_rollback",
],
)
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:32,代码来源:test_events.py
示例8: test_precolumns
def test_precolumns(self):
dialect = self.__dialect__
def gen(distinct=None, prefixes=None):
kw = {}
if distinct is not None:
kw['distinct'] = distinct
if prefixes is not None:
kw['prefixes'] = prefixes
return str(select(['q'], **kw).compile(dialect=dialect))
eq_(gen(None), 'SELECT q')
eq_(gen(True), 'SELECT DISTINCT q')
assert_raises(
exc.SADeprecationWarning,
gen, 'DISTINCT'
)
eq_(gen(prefixes=['ALL']), 'SELECT ALL q')
eq_(gen(prefixes=['DISTINCTROW']),
'SELECT DISTINCTROW q')
# Interaction with CUBRID prefix extensions
eq_(
gen(None, ['straight_join']),
'SELECT straight_join q')
eq_(
gen(False, ['HIGH_PRIORITY', 'SQL_SMALL_RESULT', 'ALL']),
'SELECT HIGH_PRIORITY SQL_SMALL_RESULT ALL q')
eq_(
gen(True, ['high_priority', sql.text('sql_cache')]),
'SELECT high_priority sql_cache DISTINCT q')
开发者ID:zzzeek,项目名称:sqlalchemy_cubrid,代码行数:33,代码来源:test_cubrid.py
示例9: test_existing_plus_useexisting_raises
def test_existing_plus_useexisting_raises(self):
meta2 = self._useexisting_fixture()
assert_raises(
exc.ArgumentError,
Table, 'users', meta2, useexisting=True,
extend_existing=True
)
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:7,代码来源:test_metadata.py
示例10: test_can_use_session_in_outer_rollback_hook
def test_can_use_session_in_outer_rollback_hook(self):
User, users = self.classes.User, self.tables.users
mapper(User, users)
sess = Session()
assertions = []
@event.listens_for(sess, "after_soft_rollback")
def do_something(session, previous_transaction):
if session.is_active:
assertions.append('name' not in u.__dict__)
assertions.append(u.name == 'u1')
u = User(name='u1', id=1)
sess.add(u)
sess.commit()
u2 = User(name='u1', id=1)
sess.add(u2)
assert_raises(
sa.orm.exc.FlushError,
sess.commit
)
sess.rollback()
eq_(assertions, [True, True])
开发者ID:sleepsonthefloor,项目名称:sqlalchemy,代码行数:25,代码来源:test_events.py
示例11: test_clauseelement
def test_clauseelement(self):
metadata = MetaData()
table = Table('test_table', metadata,
Column('foo', Integer))
metadata.create_all(bind=testing.db)
try:
for elem in [
table.select,
lambda **kwargs: sa.func.current_timestamp(**kwargs).select(),
# func.current_timestamp().select,
lambda **kwargs:text("select * from test_table", **kwargs)
]:
for bind in (
testing.db,
testing.db.connect()
):
try:
e = elem(bind=bind)
assert e.bind is bind
e.execute().close()
finally:
if isinstance(bind, engine.Connection):
bind.close()
e = elem()
assert e.bind is None
assert_raises(
exc.UnboundExecutionError,
e.execute
)
finally:
if isinstance(bind, engine.Connection):
bind.close()
metadata.drop_all(bind=testing.db)
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:34,代码来源:test_bind.py
示例12: test_deleted_flag
def test_deleted_flag(self):
users, User = self.tables.users, self.classes.User
mapper(User, users)
sess = sessionmaker()()
u1 = User(name="u1")
sess.add(u1)
sess.commit()
sess.delete(u1)
sess.flush()
assert u1 not in sess
assert_raises(sa.exc.InvalidRequestError, sess.add, u1)
sess.rollback()
assert u1 in sess
sess.delete(u1)
sess.commit()
assert u1 not in sess
assert_raises(sa.exc.InvalidRequestError, sess.add, u1)
make_transient(u1)
sess.add(u1)
sess.commit()
eq_(sess.query(User).count(), 1)
开发者ID:vishvananda,项目名称:sqlalchemy,代码行数:28,代码来源:test_session.py
示例13: test_rollback_recover
def test_rollback_recover(self):
users, User = self.tables.users, self.classes.User
mapper(User, users)
session = sessionmaker()()
u1, u2, u3= \
User(name='u1'),\
User(name='u2'),\
User(name='u3')
session.add_all([u1, u2, u3])
session.commit()
session.delete(u2)
u4 = User(name='u2')
session.add(u4)
session.flush()
u5 = User(name='u3')
session.add(u5)
assert_raises(orm_exc.FlushError, session.flush)
assert u5 not in session
assert u2 not in session.deleted
session.rollback()
开发者ID:ioram7,项目名称:keystone-federado-pgid2013,代码行数:29,代码来源:test_transaction.py
示例14: test_too_long_idx_name
def test_too_long_idx_name(self):
dialect = testing.db.dialect.__class__()
for max_ident, max_index in [(22, None), (256, 22)]:
dialect.max_identifier_length = max_ident
dialect.max_index_name_length = max_index
for tname, cname, exp in [
('sometable', 'this_name_is_too_long', 'ix_sometable_t_09aa'),
('sometable', 'this_name_alsois_long', 'ix_sometable_t_3cf1'),
]:
t1 = Table(tname, MetaData(),
Column(cname, Integer, index=True),
)
ix1 = list(t1.indexes)[0]
self.assert_compile(
schema.CreateIndex(ix1),
"CREATE INDEX %s "
"ON %s (%s)" % (exp, tname, cname),
dialect=dialect
)
dialect.max_identifier_length = 22
dialect.max_index_name_length = None
t1 = Table('t', MetaData(), Column('c', Integer))
assert_raises(
exc.IdentifierError,
schema.CreateIndex(Index(
"this_other_name_is_too_long_for_what_were_doing",
t1.c.c)).compile,
dialect=dialect
)
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:35,代码来源:test_constraints.py
示例15: test_mapped_managerattr
def test_mapped_managerattr(self):
t = Table('t', MetaData(),
Column('id', Integer, primary_key=True),
Column(instrumentation.ClassManager.MANAGER_ATTR, Integer))
class T(object): pass
assert_raises(KeyError, mapper, T, t)
开发者ID:onetera,项目名称:scandatatransfer,代码行数:7,代码来源:test_instrumentation.py
示例16: test_retval_flag
def test_retval_flag(self):
canary = []
def tracker(name):
def go(conn, *args, **kw):
canary.append(name)
return go
def execute(conn, clauseelement, multiparams, params):
canary.append('execute')
return clauseelement, multiparams, params
def cursor_execute(conn, cursor, statement,
parameters, context, executemany):
canary.append('cursor_execute')
return statement, parameters
engine = engines.testing_engine()
assert_raises(
tsa.exc.ArgumentError,
event.listen, engine, "begin", tracker("begin"), retval=True
)
event.listen(engine, "before_execute", execute, retval=True)
event.listen(engine, "before_cursor_execute", cursor_execute, retval=True)
engine.execute(select([1]))
eq_(
canary, ['execute', 'cursor_execute']
)
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:29,代码来源:test_execute.py
示例17: test_notcallable
def test_notcallable(self):
class Point(object):
pass
table = self.point_map(Point)
alias = aliased(Point)
assert_raises(TypeError, alias)
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:7,代码来源:test_utils.py
示例18: test_raise_index_nonexistent_name
def test_raise_index_nonexistent_name(self):
m = MetaData()
# the KeyError isn't ideal here, a nicer message
# perhaps
assert_raises(
KeyError,
Table, 't', m, Column('x', Integer), Index("foo", "q")
)
开发者ID:NoNo1234,项目名称:the_walking_project,代码行数:8,代码来源:test_constraints.py
示例19: test_dont_persist_alias
def test_dont_persist_alias(self):
db = sqlsoup.SqlSoup(engine)
MappedBooks = db.books
b = db.books._table
s = select([b.c.published_year, func.count("*").label("n")], from_obj=[b], group_by=[b.c.published_year])
s = s.alias("years_with_count")
years_with_count = db.map(s, primary_key=[s.c.published_year])
assert_raises(exc.InvalidRequestError, years_with_count.insert, published_year="2007", n=1)
开发者ID:onetera,项目名称:scandatatransfer,代码行数:8,代码来源:test_sqlsoup.py
示例20: test_ad_hoc_schema_equiv_fk
def test_ad_hoc_schema_equiv_fk(self):
m = MetaData()
t1 = Table('t1', m, Column('x', Integer), schema="foo")
t2 = Table('t2', m, Column('x', Integer, ForeignKey('t1.x')), schema="foo")
assert_raises(
exc.NoReferencedTableError,
lambda: t2.c.x.references(t1.c.x)
)
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:8,代码来源:test_metadata.py
注:本文中的test.lib.testing.assert_raises函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论