本文整理汇总了Python中sqlalchemy.test.testing.assert_raises_message函数的典型用法代码示例。如果您正苦于以下问题:Python assert_raises_message函数的具体用法?Python assert_raises_message怎么用?Python assert_raises_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_raises_message函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:obeattie,项目名称:sqlalchemy,代码行数:7,代码来源:test_expire.py
示例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)
开发者ID:AndryulE,项目名称:kitsune,代码行数:29,代码来源:test_cascade.py
示例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
)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:30,代码来源:test_versioning.py
示例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)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:32,代码来源:test_versioning.py
示例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
)
开发者ID:gaguilarmi,项目名称:sqlalchemy,代码行数:31,代码来源:test_oracle.py
示例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)
开发者ID:AndryulE,项目名称:kitsune,代码行数:8,代码来源:test_bind.py
示例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},
)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:8,代码来源:test_defaults.py
示例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)
开发者ID:gajop,项目名称:springgrid,代码行数:9,代码来源:test_reflection.py
示例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
)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:9,代码来源:test_sqlsoup.py
示例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
)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:9,代码来源:test_sqlsoup.py
示例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
)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:9,代码来源:test_sqlsoup.py
示例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'
)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:9,代码来源:test_sqlsoup.py
示例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
)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:9,代码来源:test_sync.py
示例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)
开发者ID:clones,项目名称:sqlalchemy,代码行数:9,代码来源:test_manytomany.py
示例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)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:9,代码来源:test_instrumentation.py
示例16: test_map_to_nothing
def test_map_to_nothing(self):
db = sqlsoup.SqlSoup(engine)
assert_raises_message(
exc.ArgumentError,
"'tablename' or 'selectable' argument is "
"required.",
db.map_to, 'users',
)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:9,代码来源:test_sqlsoup.py
示例17: test_no_populate
def test_no_populate(self):
mapper(User, users, properties={
'addresses':dynamic_loader(mapper(Address, addresses))
})
u1 = User()
assert_raises_message(
NotImplementedError,
"Dynamic attributes don't support collection population.",
attributes.set_committed_value, u1, 'addresses', []
)
开发者ID:AndryulE,项目名称:kitsune,代码行数:10,代码来源:test_dynamic.py
示例18: test_map_to_invalid_schema
def test_map_to_invalid_schema(self):
db = sqlsoup.SqlSoup(engine)
table = Table('users', db._metadata, Column('id', Integer))
assert_raises_message(
exc.ArgumentError,
"'tablename' argument is required when "
"using 'schema'.",
db.map_to, 'users', selectable=table, schema='hoho'
)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:10,代码来源:test_sqlsoup.py
示例19: test_diamond_b1
def test_diamond_b1(self):
mgr_factory = lambda cls: attributes.ClassManager(cls)
class A(object): pass
class B1(A): pass
class B2(A):
__sa_instrumentation_manager__ = staticmethod(mgr_factory)
class C(object): pass
assert_raises_message(TypeError, "multiple instrumentation implementations", attributes.register_class, B1)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:10,代码来源:test_instrumentation.py
示例20: test_update_unmapped
def test_update_unmapped(self):
uowcommit, a1, b1, a_mapper, b_mapper = self._fixture()
pairs = [(b_mapper.c.id, b_mapper.c.id,)]
dest = {}
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.update, a1, a_mapper, dest, "old_", pairs
)
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:10,代码来源:test_sync.py
注:本文中的sqlalchemy.test.testing.assert_raises_message函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论