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

Python testing.assert_warnings函数代码示例

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

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



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

示例1: test_warning_on_using_inactive_session_rollback_evt

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

        mapper(User, users)
        sess = Session()
        u1 = User(id=1, name='u1')
        sess.add(u1)
        sess.commit()

        u3 = User(name='u3')

        @event.listens_for(sess, "after_rollback")
        def evt(s):
            sess.add(u3)

        sess.add(User(id=1, name='u2'))

        def go():
            assert_raises(
                orm_exc.FlushError, sess.flush
            )

        assert_warnings(go,
                        ["Session's state has been changed on a "
                         "non-active transaction - this state "
                         "will be discarded."],
                        )
        assert u3 not in sess
开发者ID:LynYang,项目名称:sqlalchemy,代码行数:28,代码来源:test_transaction.py


示例2: test_columnadapter_anonymized

    def test_columnadapter_anonymized(self):
        """test issue #3148

        Testing the anonymization applied from the ColumnAdapter.columns
        collection, typically as used in eager loading.

        """
        exprs = [
            table1.c.myid,
            table1.c.name.label('t1name'),
            func.foo("hoho").label('x')]

        ta = table1.alias()
        adapter = sql_util.ColumnAdapter(ta, anonymize_labels=True)

        s1 = select([adapter.columns[expr] for expr in exprs]).\
            apply_labels().order_by("myid", "t1name", "x")

        def go():
            # the labels here are anonymized, so label naming
            # can't catch these.
            self.assert_compile(
                s1,
                "SELECT mytable_1.myid AS mytable_1_myid, "
                "mytable_1.name AS name_1, foo(:foo_2) AS foo_1 "
                "FROM mytable AS mytable_1 ORDER BY mytable_1.myid, t1name, x"
            )

        assert_warnings(
            go,
            ["Can't resolve label reference 't1name'",
             "Can't resolve label reference 'x'"], regex=True)
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:32,代码来源:test_text.py


示例3: test_index_reflection

    def test_index_reflection(self):
        """ Reflecting partial & expression-based indexes should warn
        """

        metadata = self.metadata

        t1 = Table(
            "party",
            metadata,
            Column("id", String(10), nullable=False),
            Column("name", String(20), index=True),
            Column("aname", String(20)),
        )
        metadata.create_all()
        testing.db.execute(
            """
          create index idx1 on party ((id || name))
        """
        )
        testing.db.execute(
            """
          create unique index idx2 on party (id) where name = 'test'
        """
        )
        testing.db.execute(
            """
            create index idx3 on party using btree
                (lower(name::text), lower(aname::text))
        """
        )

        def go():
            m2 = MetaData(testing.db)
            t2 = Table("party", m2, autoload=True)
            assert len(t2.indexes) == 2

            # Make sure indexes are in the order we expect them in

            tmp = [(idx.name, idx) for idx in t2.indexes]
            tmp.sort()
            r1, r2 = [idx[1] for idx in tmp]
            assert r1.name == "idx2"
            assert r1.unique is True
            assert r2.unique is False
            assert [t2.c.id] == r1.columns
            assert [t2.c.name] == r2.columns

        testing.assert_warnings(
            go,
            [
                "Skipped unsupported reflection of "
                "expression-based index idx1",
                "Predicate of partial index idx2 ignored during " "reflection",
                "Skipped unsupported reflection of "
                "expression-based index idx3",
            ],
        )
开发者ID:vrajmohan,项目名称:sqlalchemy,代码行数:57,代码来源:test_reflection.py


示例4: test_warning_on_using_inactive_session_delete

 def test_warning_on_using_inactive_session_delete(self):
     sess, u1 = self._inactive_flushed_session_fixture()
     sess.delete(u1)
     def go():
         sess.rollback()
     assert_warnings(go,
         ["Session's state has been changed on a "
         "non-active transaction - this state "
         "will be discarded."],
     )
     assert u1 in sess
     assert u1 not in sess.deleted
开发者ID:23andMe,项目名称:sqlalchemy,代码行数:12,代码来源:test_transaction.py


示例5: test_warning_on_using_inactive_session_new

    def test_warning_on_using_inactive_session_new(self):
        User = self.classes.User

        sess, u1 = self._inactive_flushed_session_fixture()
        u2 = User(name='u2')
        sess.add(u2)
        def go():
            sess.rollback()
        assert_warnings(go,
            ["Session's state has been changed on a "
            "non-active transaction - this state "
            "will be discarded."],
        )
        assert u2 not in sess
        assert u1 in sess
开发者ID:23andMe,项目名称:sqlalchemy,代码行数:15,代码来源:test_transaction.py


示例6: _test_round_trip

    def _test_round_trip(self, fixture, warnings=False):
        from sqlalchemy import inspect
        conn = testing.db.connect()
        for from_, to_ in self._fixture_as_string(fixture):
            inspector = inspect(conn)
            conn.execute("CREATE TABLE foo (data %s)" % from_)
            try:
                if warnings:
                    def go():
                        return inspector.get_columns("foo")[0]
                    col_info = testing.assert_warnings(go,
                                    ["Could not instantiate"], regex=True)
                else:
                    col_info = inspector.get_columns("foo")[0]
                expected_type = type(to_)
                is_(type(col_info['type']), expected_type)

                # test args
                for attr in ("scale", "precision", "length"):
                    if getattr(to_, attr, None) is not None:
                        eq_(
                            getattr(col_info['type'], attr),
                            getattr(to_, attr, None)
                        )
            finally:
                conn.execute("DROP TABLE foo")
开发者ID:Callek,项目名称:sqlalchemy,代码行数:26,代码来源:test_sqlite.py


示例7: test_pyodbc_host_no_driver

    def test_pyodbc_host_no_driver(self):
        dialect = pyodbc.dialect()
        u = url.make_url("mssql://username:[email protected]/database")

        def go():
            return dialect.create_connect_args(u)

        connection = assert_warnings(
            go,
            [
                "No driver name specified; this is expected by "
                "PyODBC when using DSN-less connections"
            ],
        )

        eq_(
            [
                [
                    "Server=hostspec;Database=database;UI"
                    "D=username;PWD=password"
                ],
                {},
            ],
            connection,
        )
开发者ID:monetate,项目名称:sqlalchemy,代码行数:25,代码来源:test_engine.py


示例8: _test_lookup_direct

 def _test_lookup_direct(self, fixture, warnings=False):
     dialect = sqlite.dialect()
     for from_, to_ in self._fixture_as_string(fixture):
         if warnings:
             def go():
                 return dialect._resolve_type_affinity(from_)
             final_type = testing.assert_warnings(go,
                             ["Could not instantiate"], regex=True)
         else:
             final_type = dialect._resolve_type_affinity(from_)
         expected_type = type(to_)
         is_(type(final_type), expected_type)
开发者ID:Callek,项目名称:sqlalchemy,代码行数:12,代码来源:test_sqlite.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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