def test_tracer_install(fakesys): """ Tracer's install method will install itself globally using sys.setprofile. """ t = Tracer() t.install() assert fakesys.tracer == t._trace
def test_tracer_uninstall(fakesys): """ Tracer's install method will uninstall itself as well. """ t = Tracer() t.install() t.uninstall() assert fakesys.tracer is None
def test_tracer_uninstall_with_other_hook_previously_installed(fakesys): """ If another profile hook was installed before the Tracer was installed, then the profile hook will be restored to that profile hook. """ t = Tracer() fakesys.tracer = sentinel = object() t.install() t.uninstall() assert fakesys.tracer is sentinel
def test_tracer_uninstall_with_other_hook(fakesys): """ If another profile hook was installed after the Tracer was installed, then the profile hook will remain unchanged. """ t = Tracer() t.install() fakesys.tracer = sentinel = object() t.uninstall() assert fakesys.tracer is sentinel
def test_tracer_wrapped_hook(fakesys): """ If a profile hook was set prior to calling Tracer's install method, it will continue to be called by Tracer. """ calls = [] def tracer(frame, event, arg): calls.append((frame, event, arg)) fakesys.tracer = tracer t = Tracer() t.install() sentinel = object() t._trace(sentinel, 'call', sentinel) assert calls == [(sentinel, 'call', sentinel)]
from functools import wraps import couchbase_core._libcouchbase as LCB from couchbase_core._libcouchbase import (Event, TimerEvent, IOEvent, LCB_READ_EVENT, LCB_WRITE_EVENT, LCB_RW_EVENT, PYCBC_EVSTATE_ACTIVE, PYCBC_EVACTION_WATCH, PYCBC_EVACTION_UNWATCH, PYCBC_EVACTION_CLEANUP) import os THESEUS_LOGFILE = os.getenv("PYCBC_THESEUS_LOGFILE") if THESEUS_LOGFILE: from theseus._tracer import Tracer t = Tracer() t.install() theseus_log = open(THESEUS_LOGFILE, 'w') import twisted.internet.base twisted.internet.base.DelayedCall.debug = True def update_theseus(func): @wraps(func) def wrapper(*args, **kwargs): t.write_data(theseus_log) theseus_log.flush() return func(*args, **kwargs) return wrapper if THESEUS_LOGFILE else func