本文整理汇总了Python中sqlalchemy.test.testing.assert_raises_message函数的典型用法代码示例。如果您正苦于以下问题:Python assert_raises_message函数的具体用法?Python assert_raises_message怎么用?Python assert_raises_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_raises_message函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_persistence_check
def test_persistence_check(self):
mapper(User, users)
s = create_session()
u = s.query(User).get(7)
s.expunge_all()
assert_raises_message(sa_exc.InvalidRequestError, r"is not persistent within this Session", s.expire, u)
示例2: test_list_assignment
def test_list_assignment(self):
sess = create_session()
u = User(name='jack', orders=[
Order(description='someorder'),
Order(description='someotherorder')])
sess.add(u)
sess.flush()
sess.expunge_all()
u = sess.query(User).get(u.id)
eq_(u, User(name='jack',
orders=[Order(description='someorder'),
Order(description='someotherorder')]))
u.orders=[Order(description="order 3"), Order(description="order 4")]
sess.flush()
sess.expunge_all()
u = sess.query(User).get(u.id)
eq_(u, User(name='jack',
orders=[Order(description="order 3"),
Order(description="order 4")]))
eq_(sess.query(Order).order_by(Order.id).all(),
[Order(description="order 3"), Order(description="order 4")])
o5 = Order(description="order 5")
sess.add(o5)
assert_raises_message(orm_exc.FlushError, "is an orphan", sess.flush)
示例3: test_child_row_switch_two
def test_child_row_switch_two(self):
Session = sessionmaker()
# TODO: not sure this test is
# testing exactly what its looking for
sess1 = Session()
sess1.add(P(id='P1', data='P version 1'))
sess1.commit()
sess1.close()
p1 = sess1.query(P).first()
sess2 = Session()
p2 = sess2.query(P).first()
sess1.delete(p1)
sess1.commit()
# this can be removed and it still passes
sess1.add(P(id='P1', data='P version 2'))
sess1.commit()
p2.data = 'P overwritten by concurrent tx'
assert_raises_message(
orm.exc.StaleDataError,
r"UPDATE statement on table 'p' expected to update "
r"1 row\(s\); 0 were matched.",
sess2.commit
)
示例4: test_versioncheck
def test_versioncheck(self):
"""query.with_lockmode performs a 'version check' on an already loaded instance"""
s1 = create_session(autocommit=False)
mapper(Foo, version_table, version_id_col=version_table.c.version_id)
f1s1 = Foo(value='f1 value')
s1.add(f1s1)
s1.commit()
s2 = create_session(autocommit=False)
f1s2 = s2.query(Foo).get(f1s1.id)
f1s2.value='f1 new value'
s2.commit()
# load, version is wrong
assert_raises_message(
sa.orm.exc.StaleDataError,
r"Instance .* has version id '\d+' which does not "
r"match database-loaded version id '\d+'",
s1.query(Foo).with_lockmode('read').get, f1s1.id
)
# reload it - this expires the old version first
s1.refresh(f1s1, lockmode='read')
# now assert version OK
s1.query(Foo).with_lockmode('read').get(f1s1.id)
# assert brand new load is OK too
s1.close()
s1.query(Foo).with_lockmode('read').get(f1s1.id)
示例5: test_limit_offset_for_update
def test_limit_offset_for_update(self):
# oracle can't actually do the ROWNUM thing with FOR UPDATE
# very well.
t = Table('t1', metadata, Column('id', Integer, primary_key=True),
Column('data', Integer)
)
metadata.create_all()
t.insert().execute(
{'id':1, 'data':1},
{'id':2, 'data':7},
{'id':3, 'data':12},
{'id':4, 'data':15},
{'id':5, 'data':32},
)
# here, we can't use ORDER BY.
eq_(
t.select(for_update=True).limit(2).execute().fetchall(),
[(1, 1),
(2, 7)]
)
# here, its impossible. But we'd prefer it to raise ORA-02014
# instead of issuing a syntax error.
assert_raises_message(
exc.DatabaseError,
"ORA-02014",
t.select(for_update=True).limit(2).offset(3).execute
)
示例6: test_session_unbound
def test_session_unbound(self):
sess = create_session()
sess.add(Foo())
assert_raises_message(
sa.exc.UnboundExecutionError,
('Could not locate a bind configured on Mapper|Foo|test_table '
'or this Session'),
sess.flush)
示例7: test_missing_many_param
def test_missing_many_param(self):
assert_raises_message(exc.InvalidRequestError,
"A value is required for bind parameter 'col7', in parameter group 1",
t.insert().execute,
{'col4':7, 'col7':12, 'col8':19},
{'col4':7, 'col8':19},
{'col4':7, 'col7':12, 'col8':19},
)
示例8: test_fk_error
def test_fk_error(self):
metadata = MetaData(testing.db)
slots_table = 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(tsa.exc.InvalidRequestError, "Could not find table 'pkgs' with which to generate a foreign key", metadata.create_all)
示例9: test_map_to_table_not_string
def test_map_to_table_not_string(self):
db = sqlsoup.SqlSoup(engine)
table = Table('users', db._metadata, Column('id', Integer, primary_key=True))
assert_raises_message(
exc.ArgumentError,
"'tablename' argument must be a string.",
db.map_to, 'users', tablename=table
)
示例10: test_map_to_table_or_selectable
def test_map_to_table_or_selectable(self):
db = sqlsoup.SqlSoup(engine)
table = Table('users', db._metadata, Column('id', Integer, primary_key=True))
assert_raises_message(
exc.ArgumentError,
"'tablename' and 'selectable' arguments are mutually exclusive",
db.map_to, 'users', tablename='users', selectable=table
)
示例11: test_map_to_no_pk_selectable
def test_map_to_no_pk_selectable(self):
db = sqlsoup.SqlSoup(engine)
table = Table('users', db._metadata, Column('id', Integer))
assert_raises_message(
sqlsoup.PKNotFoundError,
"table 'users' does not have a primary ",
db.map_to, 'users', selectable=table
)
示例12: test_map_to_attr_present
def test_map_to_attr_present(self):
db = sqlsoup.SqlSoup(engine)
users = db.users
assert_raises_message(
exc.InvalidRequestError,
"Attribute 'users' is already mapped",
db.map_to, 'users', tablename='users'
)
示例13: test_source_modified_no_unmapped
def test_source_modified_no_unmapped(self):
uowcommit, a1, b1, a_mapper, b_mapper = self._fixture()
pairs = [(b_mapper.c.id, b_mapper.c.id,)]
assert_raises_message(
orm_exc.UnmappedColumnError,
"Can't execute sync rule for source column 't2.id'; "
r"mapper 'Mapper\|A\|t1' does not map this column.",
sync.source_modified, uowcommit, a1, a_mapper, pairs
)
示例14: test_error
def test_error(self):
mapper(Place, place, properties={
'transitions':relation(Transition, secondary=place_input, backref='places')
})
mapper(Transition, transition, properties={
'places':relation(Place, secondary=place_input, backref='transitions')
})
assert_raises_message(sa.exc.ArgumentError, "Error creating backref",
sa.orm.compile_mappers)
示例15: test_single_down
def test_single_down(self):
class A(object): pass
attributes.register_class(A)
mgr_factory = lambda cls: attributes.ClassManager(cls)
class B(A):
__sa_instrumentation_manager__ = staticmethod(mgr_factory)
assert_raises_message(TypeError, "multiple instrumentation implementations", attributes.register_class, B)