Skip to content

Commit

Permalink
Version bump.
Browse files Browse the repository at this point in the history
  • Loading branch information
aminusfu committed Jul 11, 2019
1 parent 1bca882 commit c1534ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="diagnose",
version="2.0.0",
version="2.1.0",
author="Robert Brewer",
author_email="dev@crunch.io",
description="A library for instrumenting Python code at runtime.",
Expand Down
6 changes: 1 addition & 5 deletions src/diagnose/probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,7 @@ def probe_wrapper(*args, **kwargs):
if instruments_by_event["return"]:
end = time.time()
elapsed = end - start
_locals.update({
"result": result,
"end": end,
"elapsed": elapsed,
})
_locals.update({"result": result, "end": end, "elapsed": elapsed})

for instrument in instruments_by_event["return"]:
try:
Expand Down
37 changes: 11 additions & 26 deletions tests/test_probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@

class TestReturnEvent(ProbeTestCase):
def test_return_event_result(self):
with self.probe(
"test", "do", "diagnose.test_fixtures.Thing.do", "result"
) as p:
with self.probe("test", "do", "diagnose.test_fixtures.Thing.do", "result") as p:
result = Thing().do("ok")

assert result == "<ok>"
Expand All @@ -60,10 +58,7 @@ def test_return_event_elapsed(self):

def test_return_event_locals(self):
with self.probe(
"test",
"do",
"diagnose.test_fixtures.Thing.do",
"sorted(locals().keys())",
"test", "do", "diagnose.test_fixtures.Thing.do", "sorted(locals().keys())"
) as p:
result = Thing().do("ok")

Expand Down Expand Up @@ -122,7 +117,9 @@ def test_call_event_elapsed(self):
"test", "do", "diagnose.test_fixtures.Thing.do", "elapsed", event="call"
) as p:
errs = []
p.instruments.values()[0].handle_error = lambda probe: errs.append(sys.exc_info()[1].message)
p.instruments.values()[0].handle_error = lambda probe: errs.append(
sys.exc_info()[1].message
)
result = Thing().do("ok")

assert result == "<ok>"
Expand All @@ -138,26 +135,15 @@ def test_call_event_locals(self):
"do",
"diagnose.test_fixtures.Thing.do",
"sorted(locals().keys())",
event="call"
event="call",
) as p:
result = Thing().do("ok")

assert result == "<ok>"

# The probe MUST have logged an entry
assert p.instruments.values()[0].results == [
(
[],
[
"arg",
"args",
"frame",
"kwargs",
"now",
"self",
"start",
],
)
([], ["arg", "args", "frame", "kwargs", "now", "self", "start"])
]

def test_call_event_locals_frame(self):
Expand Down Expand Up @@ -216,7 +202,9 @@ def test_end_event_exception_in_value(self):
try:
errs = []
old_handle_error = diagnose.manager.handle_error
diagnose.manager.handle_error = lambda probe, instr: errs.append(sys.exc_info()[1].message)
diagnose.manager.handle_error = lambda probe, instr: errs.append(
sys.exc_info()[1].message
)
probe.start()
probe.instruments["instrument1"] = i = ProbeTestInstrument(
expires=datetime.datetime.utcnow() + datetime.timedelta(minutes=10),
Expand Down Expand Up @@ -425,10 +413,7 @@ def test_probe_nonfunc(self):

def test_patch_staticmethod(self):
with self.probe(
"test",
"quantile",
"diagnose.test_fixtures.Thing.static",
"result",
"test", "quantile", "diagnose.test_fixtures.Thing.static", "result"
) as p:
assert Thing().static() == 15
assert p.instruments.values()[0].results == [([], 15)]
Expand Down

0 comments on commit c1534ba

Please sign in to comment.