• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python testing.assert_raises_message函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中test.lib.testing.assert_raises_message函数的典型用法代码示例。如果您正苦于以下问题:Python assert_raises_message函数的具体用法?Python assert_raises_message怎么用?Python assert_raises_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了assert_raises_message函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
        )
开发者ID:onetera,项目名称:scandatatransfer,代码行数:7,代码来源:test_sqlsoup.py


示例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'
     )
开发者ID:NoNo1234,项目名称:the_walking_project,代码行数:7,代码来源:test_mutable.py


示例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"
开发者ID:onetera,项目名称:scandatatransfer,代码行数:29,代码来源:test_reconnect.py


示例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"
        )
开发者ID:onetera,项目名称:scandatatransfer,代码行数:7,代码来源:test_sqlsoup.py


示例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
开发者ID:NoNo1234,项目名称:the_walking_project,代码行数:35,代码来源:test_versioning.py


示例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
开发者ID:ioram7,项目名称:keystone-federado-pgid2013,代码行数:28,代码来源:test_session.py


示例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)
开发者ID:NoNo1234,项目名称:the_walking_project,代码行数:33,代码来源:test_versioning.py


示例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
        )
开发者ID:onetera,项目名称:scandatatransfer,代码行数:7,代码来源:test_sqlsoup.py


示例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
     )
开发者ID:NoNo1234,项目名称:the_walking_project,代码行数:8,代码来源:test_default_strategies.py


示例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)
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:8,代码来源:test_transaction.py


示例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))
开发者ID:NoNo1234,项目名称:the_walking_project,代码行数:8,代码来源:test_expire.py


示例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')
     )
开发者ID:NoNo1234,项目名称:the_walking_project,代码行数:8,代码来源:test_associationproxy.py


示例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)
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:8,代码来源:test_metadata.py


示例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'
     )
开发者ID:sleepsonthefloor,项目名称:sqlalchemy,代码行数:8,代码来源:test_hybrid.py


示例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)
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:8,代码来源:test_metadata.py


示例16: test_transient_no_load

    def test_transient_no_load(self):
        users, User = self.tables.users, self.classes.User

        mapper(User, users)

        sess = create_session()
        u = User()
        assert_raises_message(sa.exc.InvalidRequestError, "load=False option does not support", sess.merge, u, load=False)
开发者ID:onetera,项目名称:scandatatransfer,代码行数:8,代码来源:test_merge.py


示例17: test_nonassignable

 def test_nonassignable(self):
     A = self._fixture(False)
     a1 = A(_value=5)
     assert_raises_message(
         AttributeError, 
         "can't set attribute",
         setattr, a1, 'value', 10
     )
开发者ID:sleepsonthefloor,项目名称:sqlalchemy,代码行数:8,代码来源:test_hybrid.py


示例18: test_missing_many_param

 def test_missing_many_param(self):
     assert_raises_message(exc.StatementError, 
         "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:onetera,项目名称:scandatatransfer,代码行数:8,代码来源:test_defaults.py


示例19: test_update_multi_elem_varg

 def test_update_multi_elem_varg(self):
     a1 = self.A()
     assert_raises_message(
         TypeError,
         "update expected at most 1 arguments, got 2",
         a1.elements.update,
         (("B", 3), 'elem2'), (("C", 4), "elem3")
     )
开发者ID:NoNo1234,项目名称:the_walking_project,代码行数:8,代码来源:test_associationproxy.py


示例20: 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:ContextLogic,项目名称:sqlalchemy,代码行数:9,代码来源:test_sqlsoup.py



注:本文中的test.lib.testing.assert_raises_message函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testing.eq_函数代码示例发布时间:2022-05-27
下一篇:
Python testing.assert_raises函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap