This repository has been archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from luzfcb/add-decorator
Add first decorator
- Loading branch information
Showing
7 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ dist/ | |
|
||
*.pyc | ||
__pycache__ | ||
.idea | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import functools | ||
|
||
from .pycallgraph import PyCallGraph | ||
|
||
|
||
def trace(output=None, config=None): | ||
def inner(func): | ||
@functools.wraps(func) | ||
def exec_func(*args, **kw_args): | ||
with(PyCallGraph(output, config)): | ||
return func(*args, **kw_args) | ||
|
||
return exec_func | ||
|
||
return inner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[wheel] | ||
universal = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import pytest | ||
|
||
import pycallgraph | ||
from pycallgraph import PyCallGraphException | ||
from pycallgraph.output import GephiOutput, GraphvizOutput | ||
|
||
|
||
@pycallgraph.decorators.trace(output=GraphvizOutput()) | ||
def print_something(): | ||
print("hello") | ||
|
||
|
||
@pycallgraph.decorators.trace(output=GephiOutput()) | ||
def print_foo(): | ||
print("foo") | ||
|
||
|
||
@pycallgraph.decorators.trace() | ||
def print_bar(): | ||
print("bar") | ||
|
||
|
||
def test_trace_decorator_graphviz_output(): | ||
print_something() | ||
|
||
|
||
def test_trace_decorator_gephi_output(): | ||
print_foo() | ||
|
||
|
||
def test_trace_decorator_parameter(): | ||
with pytest.raises(PyCallGraphException): | ||
print_bar() | ||
|
||
|
||
if __name__ == "__main__": | ||
test_trace_decorator_graphviz_output() | ||
test_trace_decorator_gephi_output() | ||
test_trace_decorator_parameter() |