当前位置: 首页>>代码示例>>Python>>正文


Python assertions.assert_raises函数代码示例

本文整理汇总了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;未经允许,请勿转载。