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

Python sqltap.start函数代码示例

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

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



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

示例1: test_engine_scoped

    def test_engine_scoped(self):
        """
        Test that calling sqltap.start with a particular engine instance
        properly captures queries only to that engine.
        """
        engine2 = create_engine('sqlite:///:memory:', echo=True)

        Base = declarative_base(bind = engine2)

        class B(Base):
            __tablename__ = "b"
            id = Column("id", Integer, primary_key = True)

        Base.metadata.create_all(engine2)
        Session = sessionmaker(bind=engine2)
        sqltap.start(engine2)

        sess = self.Session()
        sess.query(self.A).all()

        sess2 = Session()
        sess2.query(B).all()

        stats = _startswith(sqltap.collect(), 'SELECT')
        assert len(stats) == 1
开发者ID:dobesv,项目名称:sqltap,代码行数:25,代码来源:test_sqltap.py


示例2: test_engine_global

    def test_engine_global(self):
        """ Test that registering globally for all queries correctly pulls queries
            from multiple engines.
        
            This test passes, but because SQLAlchemy won't ever let us unregister
            our event handlers, this causes side-effects in other tests that will
            break them.
        """
        return
        engine2 = create_engine('sqlite:///:memory:', echo=True)

        Base = declarative_base(bind = engine2)

        class B(Base):
            __tablename__ = "b"
            id = Column("id", Integer, primary_key = True)

        Base.metadata.create_all(engine2)
        Session = sessionmaker(bind=engine2)
        sqltap.start()

        sess = self.Session()
        sess.query(self.A).all()

        sess2 = Session()
        sess2.query(B).all()

        stats = _startswith(sqltap.collect(), 'SELECT')
        assert len(stats) == 2
开发者ID:dobesv,项目名称:sqltap,代码行数:29,代码来源:test_sqltap.py


示例3: test_context_fn_isolation

    def test_context_fn_isolation(self):
        engine2 = create_engine('sqlite:///:memory:', echo=True)

        Base = declarative_base(bind = engine2)

        class B(Base):
            __tablename__ = "b"
            id = Column("id", Integer, primary_key = True)

        Base.metadata.create_all(engine2)
        Session = sessionmaker(bind=engine2)

        sqltap.start(self.engine, lambda *args: 1)
        sqltap.start(engine2, lambda *args: 2)

        sess = self.Session()
        sess.query(self.A).all()

        sess2 = Session()
        sess2.query(B).all()

        stats = sqltap.collect()

        ctxs = [qstats.user_context for qstats in _startswith(stats, 'SELECT')]
        assert ctxs.count(1) == 1
        assert ctxs.count(2) == 1
开发者ID:dobesv,项目名称:sqltap,代码行数:26,代码来源:test_sqltap.py


示例4: test_select

    def test_select(self):
        """ Simple test that sqltap collects a select query. """
        sqltap.start(self.engine)

        sess = self.Session()
        sess.query(self.A).all()

        stats = sqltap.collect()
        assert len(_startswith(stats, 'SELECT')) == 1
开发者ID:dobesv,项目名称:sqltap,代码行数:9,代码来源:test_sqltap.py


示例5: test_stop

    def test_stop(self):
        """ Ensure queries after you call sqltap.stop() are not recorded. """
        sqltap.start(self.engine)
        sess = self.Session()
        sess.query(self.A).all()
        sqltap.stop(self.engine)
        sess.query(self.A).all()

        assert len(sqltap.collect()) == 1
开发者ID:dobesv,项目名称:sqltap,代码行数:9,代码来源:test_sqltap.py


示例6: test_insert

    def test_insert(self):
        """ Simple test that sqltap collects an insert query. """
        sqltap.start(self.engine)

        sess = self.Session()
        sess.add(self.A())
        sess.flush()

        stats = sqltap.collect()
        assert len(_startswith(stats, 'INSERT')) == 1
开发者ID:dobesv,项目名称:sqltap,代码行数:10,代码来源:test_sqltap.py


示例7: test_context_fn

    def test_context_fn(self):
        sqltap.start(self.engine, lambda *args: 1)

        sess = self.Session()
        q = sess.query(self.A)
        q.all()
        stats = sqltap.collect()

        ctxs = [qstats.user_context for qstats in _startswith(stats, 'SELECT')]
        assert ctxs[0] == 1
开发者ID:dobesv,项目名称:sqltap,代码行数:10,代码来源:test_sqltap.py


示例8: test_report

    def test_report(self):
        sqltap.start(self.engine)

        sess = self.Session()
        q = sess.query(self.A)
        qtext = str(q)
        q.all()


        report = sqltap.report(sqltap.collect())
        assert 'SQLTap Report' in report
        assert qtext in report
开发者ID:dobesv,项目名称:sqltap,代码行数:12,代码来源:test_sqltap.py


示例9: test_start_twice

    def test_start_twice(self):
        """ Ensure that if multiple calls to sqltap.start on the same
            engine do not cause us to record more than one event per query.
        """
        sqltap.start(self.engine)
        sqltap.start(self.engine)

        sess = self.Session()
        sess.query(self.A).all()

        stats = _startswith(sqltap.collect(), 'SELECT')
        assert len(stats) == 1
开发者ID:dobesv,项目名称:sqltap,代码行数:12,代码来源:test_sqltap.py


示例10: test_stop_global

    def test_stop_global(self):
        """ Ensure queries after you call sqltap.stop() are not recorded when passing
            in the 'global' Engine object to record queries across all engines.
        
            This test passes, but because SQLAlchemy won't ever let us unregister
            our event handlers, this causes side-effects in other tests and will.
        """
        return
        sqltap.start()
        sess = self.Session()
        sess.query(self.A).all()
        sqltap.stop()
        sess.query(self.A).all()

        assert len(sqltap.collect()) == 1
开发者ID:dobesv,项目名称:sqltap,代码行数:15,代码来源:test_sqltap.py


示例11: test_collect_fn_execption_on_collect

    def test_collect_fn_execption_on_collect(self):
        def noop():
            pass

        profiler = sqltap.start(self.engine, collect_fn=noop)
        profiler.collect()
        profiler.stop()
开发者ID:assembl,项目名称:sqltap,代码行数:7,代码来源:test_sqltap.py


示例12: test_report_aggregation_w_different_param_sets

    def test_report_aggregation_w_different_param_sets(self):
        """
        Test that report rendering works with groups of queries
        containing different parameter sets
        """

        sess = self.Session()

        a1 = self.A(name=uuid.uuid4().hex, description="")
        a2 = self.A(name=uuid.uuid4().hex, description="")
        sess.add_all([a1, a2])
        sess.commit()

        a1 = sess.query(self.A).get(a1.id)
        a2 = sess.query(self.A).get(a2.id)

        profiler = sqltap.start(self.engine)
        # this will create queries with the same text, but different param sets
        # (different query.params.keys() collections)
        a1.name = uuid.uuid4().hex
        a2.description = uuid.uuid4().hex
        sess.flush()

        report = sqltap.report(profiler.collect())
        print(report)
        profiler.stop()
        self.check_report(report)
开发者ID:assembl,项目名称:sqltap,代码行数:27,代码来源:test_sqltap.py


示例13: f

        def f():
            engine2 = create_engine('sqlite:///:memory:', echo=True)

            Base = declarative_base(bind = engine2)

            class B(Base):
                __tablename__ = "b"
                id = Column("id", Integer, primary_key = True)

            Base.metadata.create_all(engine2)
            Session = sessionmaker(bind=engine2)
            sqltap.start(engine2)

            sqltap.start(self.engine)
            sess2 = Session()
            sess2.query(B).all()
开发者ID:dobesv,项目名称:sqltap,代码行数:16,代码来源:test_sqltap.py


示例14: wrapper

	def wrapper(*args, **kwargs):
		if not request.query.do_log:
			return callback(*args, **kwargs)

		import os

		fname = 'logs/{}.html'.format(request.path
			.replace('/', '.')
			.replace('<', '')
			.replace('>', '')
			.lstrip('.')
		)
		try:
			os.remove(fname)
		except:
			pass

		import sqltap

		profiler = sqltap.start()

		try:
			return callback(*args, **kwargs)
		finally:
			try:
				statistics = profiler.collect()
				profiler.stop()
				sqltap.report(statistics, fname)
			except Exception:
				raise
开发者ID:eric-wieser,项目名称:caius-rooms,代码行数:30,代码来源:server.py


示例15: test_engine_global

    def test_engine_global(self):
        """
        Test that registering globally for all queries correctly pulls queries
        from multiple engines.
        """
        engine2 = create_engine('sqlite:///:memory:', echo=True)

        Base = declarative_base(bind=engine2)

        class B(Base):
            __tablename__ = "b"
            id = Column("id", Integer, primary_key=True)

        Base.metadata.create_all(engine2)
        Session = sessionmaker(bind=engine2)
        profiler = sqltap.start()

        sess = self.Session()
        sess.query(self.A).all()

        sess2 = Session()
        sess2.query(B).all()

        stats = _startswith(profiler.collect(), 'SELECT')
        assert len(stats) == 2
        profiler.stop()
开发者ID:YAtOff,项目名称:sqltap,代码行数:26,代码来源:test_sqltap.py


示例16: test_stop

    def test_stop(self):
        """ Ensure queries after you call ProfilingSession.stop() are not recorded. """
        profiler = sqltap.start(self.engine)
        sess = self.Session()
        sess.query(self.A).all()
        profiler.stop()
        sess.query(self.A).all()

        assert len(profiler.collect()) == 1
开发者ID:julianpistorius,项目名称:sqltap,代码行数:9,代码来源:test_sqltap.py


示例17: test_select

    def test_select(self):
        """ Simple test that sqltap collects a select query. """
        profiler = sqltap.start(self.engine)

        sess = self.Session()
        sess.query(self.A).all()

        stats = profiler.collect()
        assert len(_startswith(stats, "SELECT")) == 1
        profiler.stop()
开发者ID:assembl,项目名称:sqltap,代码行数:10,代码来源:test_sqltap.py


示例18: test_report

    def test_report(self):
        profiler = sqltap.start(self.engine)

        sess = self.Session()
        q = sess.query(self.A)
        qtext = str(q)
        q.all()

        report = sqltap.report(profiler.collect())
        assert 'sqltap profile report' in report
        assert qtext in report
开发者ID:julianpistorius,项目名称:sqltap,代码行数:11,代码来源:test_sqltap.py


示例19: test_stop_global

    def test_stop_global(self):
        """ Ensure queries after you call ProfilingSession.stop() are not recorded
            when passing in the 'global' Engine object to record queries across all engines.
        """
        profiler = sqltap.start()
        sess = self.Session()
        sess.query(self.A).all()
        profiler.stop()
        sess.query(self.A).all()

        assert len(profiler.collect()) == 1
开发者ID:julianpistorius,项目名称:sqltap,代码行数:11,代码来源:test_sqltap.py


示例20: test_insert

    def test_insert(self):
        """ Simple test that sqltap collects an insert query. """
        profiler = sqltap.start(self.engine)

        sess = self.Session()
        sess.add(self.A())
        sess.flush()

        stats = profiler.collect()
        assert len(_startswith(stats, "INSERT")) == 1
        profiler.stop()
开发者ID:assembl,项目名称:sqltap,代码行数:11,代码来源:test_sqltap.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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