本文整理汇总了Python中test.lib.testing.assert_raises_message函数的典型用法代码示例。如果您正苦于以下问题:Python assert_raises_message函数的具体用法?Python assert_raises_message怎么用?Python assert_raises_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_raises_message函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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
)
示例2: test_set_illegal
def test_set_illegal(self):
f1 = Foo()
assert_raises_message(
ValueError,
"Attribute 'data' does not accept objects",
setattr, f1, 'data', 'foo'
)
示例3: test_invalidate_trans
def test_invalidate_trans(self):
conn = db.connect()
trans = conn.begin()
dbapi.shutdown()
try:
conn.execute(select([1]))
assert False
except tsa.exc.DBAPIError:
pass
# assert was invalidated
gc_collect()
assert len(dbapi.connections) == 0
assert not conn.closed
assert conn.invalidated
assert trans.is_active
assert_raises_message(
tsa.exc.StatementError,
"Can't reconnect until invalid transaction is rolled back",
conn.execute,
select([1]),
)
assert trans.is_active
try:
trans.commit()
assert False
except tsa.exc.InvalidRequestError, e:
assert str(e) == "Can't reconnect until invalid transaction is " "rolled back"
示例4: 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"
)
示例5: test_child_row_switch_two
def test_child_row_switch_two(self):
P = self.classes.P
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'
if testing.db.dialect.supports_sane_rowcount:
assert_raises_message(
orm.exc.StaleDataError,
r"UPDATE statement on table 'p' expected to update "
r"1 row\(s\); 0 were matched.",
sess2.commit
)
else:
sess2.commit
示例6: test_auto_detach_on_gc_session
def test_auto_detach_on_gc_session(self):
users, User = self.tables.users, self.classes.User
mapper(User, users)
sess = Session()
u1 = User(name='u1')
sess.add(u1)
sess.commit()
# can't add u1 to Session,
# already belongs to u2
s2 = Session()
assert_raises_message(
sa.exc.InvalidRequestError,
r".*is already attached to session",
s2.add, u1
)
# garbage collect sess
del sess
gc_collect()
# s2 lets it in now despite u1 having
# session_key
s2.add(u1)
assert u1 in s2
示例7: test_versioncheck
def test_versioncheck(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)
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)
示例8: 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
)
示例9: test_star_must_be_alone
def test_star_must_be_alone(self):
sess = self._downgrade_fixture()
User = self.classes.User
assert_raises_message(
sa.exc.ArgumentError,
"Wildcard identifier '\*' must be specified alone.",
sa.orm.subqueryload, '*', User.addresses
)
示例10: test_invalid_level
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)
示例11: test_persistence_check
def test_persistence_check(self):
users, User = self.tables.users, self.classes.User
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", lambda: s.refresh(u))
示例12: test_update_one_elem_varg
def test_update_one_elem_varg(self):
a1 = self.A()
assert_raises_message(
ValueError,
"dictionary update sequence requires "
"2-element tuples",
a1.elements.update, (("B", 3), 'elem2')
)
示例13: test_name_blank
def test_name_blank(self):
c = Column('', Integer)
assert_raises_message(
exc.ArgumentError,
"Column must be constructed with a non-blank name or assign a "
"non-blank .name ",
Table, 't', MetaData(), c)
示例14: test_nondeletable
def test_nondeletable(self):
A = self._fixture(False)
a1 = A(_value=5)
assert_raises_message(
AttributeError,
"can't delete attribute",
delattr, a1, 'value'
)
示例15: test_dupe_column
def test_dupe_column(self):
c = Column('x', Integer)
t = Table('t', MetaData(), c)
assert_raises_message(
exc.ArgumentError,
"Column object already assigned to Table 't'",
Table, 'q', MetaData(), c)