本文整理汇总了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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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()
示例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)
示例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()
示例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
示例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()