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


Python sqltap.start函数代码示例

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


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


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