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

Python assertions.assert_raises函数代码示例

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

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



在下文中一共展示了assert_raises函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_on_conflict_do_update_exotic_targets_five

    def test_on_conflict_do_update_exotic_targets_five(self):
        users = self.tables.users_xtra

        with testing.db.connect() as conn:
            self._exotic_targets_fixture(conn)
            # try bogus index
            i = insert(users)
            i = i.on_conflict_do_update(
                index_elements=self.bogus_index.columns,
                index_where=self.bogus_index.dialect_options["postgresql"][
                    "where"
                ],
                set_=dict(
                    name=i.excluded.name, login_email=i.excluded.login_email
                ),
            )

            assert_raises(
                exc.ProgrammingError,
                conn.execute,
                i,
                dict(
                    id=1,
                    name="namebogus",
                    login_email="[email protected]",
                    lets_index_this="bogus",
                ),
            )
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:28,代码来源:test_on_conflict.py


示例2: test_from_only

    def test_from_only(self):
        m = MetaData()
        tbl1 = Table('testtbl1', m, Column('id', Integer))
        tbl2 = Table('testtbl2', m, Column('id', Integer))

        stmt = tbl1.select().with_hint(tbl1, 'ONLY', 'postgresql')
        expected = 'SELECT testtbl1.id FROM ONLY testtbl1'
        self.assert_compile(stmt, expected)

        talias1 = tbl1.alias('foo')
        stmt = talias1.select().with_hint(talias1, 'ONLY', 'postgresql')
        expected = 'SELECT foo.id FROM ONLY testtbl1 AS foo'
        self.assert_compile(stmt, expected)

        stmt = select([tbl1, tbl2]).with_hint(tbl1, 'ONLY', 'postgresql')
        expected = ('SELECT testtbl1.id, testtbl2.id FROM ONLY testtbl1, '
                    'testtbl2')
        self.assert_compile(stmt, expected)

        stmt = select([tbl1, tbl2]).with_hint(tbl2, 'ONLY', 'postgresql')
        expected = ('SELECT testtbl1.id, testtbl2.id FROM testtbl1, ONLY '
                    'testtbl2')
        self.assert_compile(stmt, expected)

        stmt = select([tbl1, tbl2])
        stmt = stmt.with_hint(tbl1, 'ONLY', 'postgresql')
        stmt = stmt.with_hint(tbl2, 'ONLY', 'postgresql')
        expected = ('SELECT testtbl1.id, testtbl2.id FROM ONLY testtbl1, '
                    'ONLY testtbl2')
        self.assert_compile(stmt, expected)

        stmt = update(tbl1, values=dict(id=1))
        stmt = stmt.with_hint('ONLY', dialect_name='postgresql')
        expected = 'UPDATE ONLY testtbl1 SET id=%(id)s'
        self.assert_compile(stmt, expected)

        stmt = delete(tbl1).with_hint(
            'ONLY', selectable=tbl1, dialect_name='postgresql')
        expected = 'DELETE FROM ONLY testtbl1'
        self.assert_compile(stmt, expected)

        tbl3 = Table('testtbl3', m, Column('id', Integer), schema='testschema')
        stmt = tbl3.select().with_hint(tbl3, 'ONLY', 'postgresql')
        expected = 'SELECT testschema.testtbl3.id FROM '\
            'ONLY testschema.testtbl3'
        self.assert_compile(stmt, expected)

        assert_raises(
            exc.CompileError,
            tbl3.select().with_hint(tbl3, "FAKE", "postgresql").compile,
            dialect=postgresql.dialect()
        )
开发者ID:Attsun1031,项目名称:sqlalchemy,代码行数:52,代码来源:test_compiler.py


示例3: test_cursor_close_w_failed_rowproc

    def test_cursor_close_w_failed_rowproc(self):
        User = self.classes.User
        s = Session()

        q = s.query(User)

        ctx = q._compile_context()
        cursor = mock.Mock()
        q._entities = [
            mock.Mock(row_processor=mock.Mock(side_effect=Exception("boom")))
        ]
        assert_raises(Exception, list, loading.instances(q, cursor, ctx))
        assert cursor.close.called, "Cursor wasn't closed"
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:13,代码来源:test_loading.py


示例4: test_unknown_types

    def test_unknown_types(self):
        from sqlalchemy.databases import postgresql
        ischema_names = postgresql.PGDialect.ischema_names
        postgresql.PGDialect.ischema_names = {}
        try:
            m2 = MetaData(testing.db)
            assert_raises(exc.SAWarning, Table, 'testtable', m2,
                          autoload=True)

            @testing.emits_warning('Did not recognize type')
            def warns():
                m3 = MetaData(testing.db)
                t3 = Table('testtable', m3, autoload=True)
                assert t3.c.answer.type.__class__ == sa.types.NullType
        finally:
            postgresql.PGDialect.ischema_names = ischema_names
开发者ID:DeepakAlevoor,项目名称:sqlalchemy,代码行数:16,代码来源:test_reflection.py


示例5: test_from_only

    def test_from_only(self):
        m = MetaData()
        tbl1 = Table("testtbl1", m, Column("id", Integer))
        tbl2 = Table("testtbl2", m, Column("id", Integer))

        stmt = tbl1.select().with_hint(tbl1, "ONLY", "postgresql")
        expected = "SELECT testtbl1.id FROM ONLY testtbl1"
        self.assert_compile(stmt, expected)

        talias1 = tbl1.alias("foo")
        stmt = talias1.select().with_hint(talias1, "ONLY", "postgresql")
        expected = "SELECT foo.id FROM ONLY testtbl1 AS foo"
        self.assert_compile(stmt, expected)

        stmt = select([tbl1, tbl2]).with_hint(tbl1, "ONLY", "postgresql")
        expected = "SELECT testtbl1.id, testtbl2.id FROM ONLY testtbl1, " "testtbl2"
        self.assert_compile(stmt, expected)

        stmt = select([tbl1, tbl2]).with_hint(tbl2, "ONLY", "postgresql")
        expected = "SELECT testtbl1.id, testtbl2.id FROM testtbl1, ONLY " "testtbl2"
        self.assert_compile(stmt, expected)

        stmt = select([tbl1, tbl2])
        stmt = stmt.with_hint(tbl1, "ONLY", "postgresql")
        stmt = stmt.with_hint(tbl2, "ONLY", "postgresql")
        expected = "SELECT testtbl1.id, testtbl2.id FROM ONLY testtbl1, " "ONLY testtbl2"
        self.assert_compile(stmt, expected)

        stmt = update(tbl1, values=dict(id=1))
        stmt = stmt.with_hint("ONLY", dialect_name="postgresql")
        expected = "UPDATE ONLY testtbl1 SET id=%(id)s"
        self.assert_compile(stmt, expected)

        stmt = delete(tbl1).with_hint("ONLY", selectable=tbl1, dialect_name="postgresql")
        expected = "DELETE FROM ONLY testtbl1"
        self.assert_compile(stmt, expected)

        tbl3 = Table("testtbl3", m, Column("id", Integer), schema="testschema")
        stmt = tbl3.select().with_hint(tbl3, "ONLY", "postgresql")
        expected = "SELECT testschema.testtbl3.id FROM " "ONLY testschema.testtbl3"
        self.assert_compile(stmt, expected)

        assert_raises(
            exc.CompileError, tbl3.select().with_hint(tbl3, "FAKE", "postgresql").compile, dialect=postgresql.dialect()
        )
开发者ID:EvaSDK,项目名称:sqlalchemy,代码行数:45,代码来源:test_compiler.py


示例6: test_bad_args

 def test_bad_args(self):
     assert_raises(
         ValueError,
         insert(self.tables.users).on_conflict_do_nothing,
         constraint='id', index_elements=['id']
     )
     assert_raises(
         ValueError,
         insert(self.tables.users).on_conflict_do_update,
         constraint='id', index_elements=['id']
     )
     assert_raises(
         ValueError,
         insert(self.tables.users).on_conflict_do_update, constraint='id'
     )
     assert_raises(
         ValueError,
         insert(self.tables.users).on_conflict_do_update
     )
开发者ID:rlugojr,项目名称:sqlalchemy,代码行数:19,代码来源:test_on_conflict.py


示例7: test_bad_args

 def test_bad_args(self):
     assert_raises(
         ValueError,
         insert(self.tables.foos, values={}).on_duplicate_key_update,
     )
     assert_raises(
         exc.ArgumentError,
         insert(self.tables.foos, values={}).on_duplicate_key_update,
         {"id": 1, "bar": "b"},
         id=1,
         bar="b",
     )
     assert_raises(
         exc.ArgumentError,
         insert(self.tables.foos, values={}).on_duplicate_key_update,
         {"id": 1, "bar": "b"},
         {"id": 2, "bar": "baz"},
     )
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:18,代码来源:test_on_duplicate.py


示例8: test_numeric_raise

 def test_numeric_raise(self):
     stmt = text("select cast('hi' as char) as hi", typemap={"hi": Numeric})
     assert_raises(exc.InvalidRequestError, testing.db.execute, stmt)
开发者ID:fuzzball81,项目名称:sqlalchemy,代码行数:3,代码来源:test_dialect.py


示例9: test_numeric_raise

 def test_numeric_raise(self):
     stmt = text("select cast('hi' as char) as hi").columns(hi=Numeric)
     assert_raises(exc.InvalidRequestError, testing.db.execute, stmt)
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:3,代码来源:test_dialect.py


示例10: test_get_view_names_empty

 def test_get_view_names_empty(self):
     insp = inspect(testing.db)
     assert_raises(ValueError, insp.get_view_names, include=())
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:3,代码来源:test_reflection.py


示例11: test_bad_args

 def test_bad_args(self):
     assert_raises(
         ValueError,
         insert(self.tables.foos, values={}).on_duplicate_key_update
     )
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:5,代码来源:test_on_duplicate.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python assertions.eq_函数代码示例发布时间:2022-05-27
下一篇:
Python testing.ne_函数代码示例发布时间: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