-
Notifications
You must be signed in to change notification settings - Fork 16
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 #76 from KeerthiVasudevan/add_hooks_for_decorator
Add hooks for decorators
- Loading branch information
Showing
28 changed files
with
461 additions
and
2 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
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
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,21 @@ | ||
from dynapyt.analyses.BaseAnalysis import BaseAnalysis | ||
|
||
|
||
class TestAnalysis(BaseAnalysis): | ||
def begin_execution(self) -> None: | ||
print("begin execution") | ||
|
||
def enter_decorator(self, dyn_ast: str, iid: int, decorator: str, args, kwargs) -> None: | ||
print("enter decorator: ", decorator) | ||
|
||
def exit_decorator(self, dyn_ast: str, iid: int, decorator: str, result, args, kwargs) -> None: | ||
print("exit decorator: ", decorator) | ||
|
||
def runtime_event(self, dyn_ast: str, iid: int) -> None: | ||
print("runtime event") | ||
|
||
def control_flow_event(self, dyn_ast: str, iid: int) -> None: | ||
print("control flow event") | ||
|
||
def end_execution(self) -> None: | ||
print("end execution") |
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 @@ | ||
begin execution | ||
runtime event | ||
control flow event | ||
runtime event | ||
runtime event | ||
control flow event | ||
runtime event | ||
runtime event | ||
control flow event | ||
runtime event | ||
control flow event | ||
enter decorator: wrapper | ||
runtime event | ||
control flow event | ||
runtime event | ||
runtime event | ||
control flow event | ||
Decorator function before | ||
runtime event | ||
runtime event | ||
control flow event | ||
runtime event | ||
control flow event | ||
runtime event | ||
runtime event | ||
control flow event | ||
Simple function | ||
runtime event | ||
control flow event | ||
runtime event | ||
runtime event | ||
control flow event | ||
Decorator function after | ||
runtime event | ||
control flow event | ||
runtime event | ||
control flow event | ||
exit decorator: wrapper | ||
end execution |
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,13 @@ | ||
def decorator_function_one(func): | ||
def wrapper(): | ||
print("Decorator function before") | ||
func() | ||
print("Decorator function after") | ||
return wrapper | ||
|
||
@decorator_function_one | ||
def simple_function(): | ||
print("Simple function") | ||
|
||
simple_function() | ||
|
14 changes: 14 additions & 0 deletions
14
tests/trace_single_hook/decorators/builtin_decorator/analysis.py
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,14 @@ | ||
from dynapyt.analyses.BaseAnalysis import BaseAnalysis | ||
|
||
class TestAnalysis(BaseAnalysis): | ||
def begin_execution(self) -> None: | ||
print("begin execution") | ||
|
||
def enter_decorator(self, dyn_ast: str, iid: int, decorator: str, args, kwargs) -> None: | ||
print("enter decorator: ", decorator) | ||
|
||
def exit_decorator(self, dyn_ast: str, iid: int, decorator: str, result, args, kwargs) -> None: | ||
print("exit decorator: ", decorator) | ||
|
||
def end_execution(self) -> None: | ||
print("end execution") |
7 changes: 7 additions & 0 deletions
7
tests/trace_single_hook/decorators/builtin_decorator/expected.txt
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,7 @@ | ||
begin execution | ||
enter decorator: my_context_manager | ||
exit decorator: my_context_manager | ||
Entering context | ||
Inside context | ||
Exiting context | ||
end execution |
13 changes: 13 additions & 0 deletions
13
tests/trace_single_hook/decorators/builtin_decorator/program.py
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,13 @@ | ||
from contextlib import contextmanager | ||
|
||
@contextmanager | ||
def my_context_manager(): | ||
print('Entering context') | ||
yield | ||
print('Exiting context') | ||
|
||
with my_context_manager(): | ||
print('Inside context') | ||
|
||
|
||
|
14 changes: 14 additions & 0 deletions
14
tests/trace_single_hook/decorators/decorator_class_attribute/analysis.py
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,14 @@ | ||
from dynapyt.analyses.BaseAnalysis import BaseAnalysis | ||
|
||
class TestAnalysis(BaseAnalysis): | ||
def begin_execution(self) -> None: | ||
print("begin execution") | ||
|
||
def enter_decorator(self, dyn_ast: str, iid: int, decorator: str, args, kwargs) -> None: | ||
print("enter decorator: ", decorator) | ||
|
||
def exit_decorator(self, dyn_ast: str, iid: int, decorator: str, result, args, kwargs) -> None: | ||
print("exit decorator: ", decorator) | ||
|
||
def end_execution(self) -> None: | ||
print("end execution") |
7 changes: 7 additions & 0 deletions
7
tests/trace_single_hook/decorators/decorator_class_attribute/expected.txt
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,7 @@ | ||
begin execution | ||
enter decorator: wrapper | ||
Decorator function before | ||
Simple function | ||
Decorator function after | ||
exit decorator: wrapper | ||
end execution |
15 changes: 15 additions & 0 deletions
15
tests/trace_single_hook/decorators/decorator_class_attribute/program.py
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 @@ | ||
class foo: | ||
def decorator_func(self, func): | ||
def wrapper(): | ||
print("Decorator function before") | ||
func() | ||
print("Decorator function after") | ||
return wrapper | ||
|
||
f = foo() | ||
|
||
@f.decorator_func | ||
def simple_function(): | ||
print("Simple function") | ||
|
||
simple_function() |
15 changes: 15 additions & 0 deletions
15
tests/trace_single_hook/decorators/decorator_func_with_args/analysis.py
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 @@ | ||
from dynapyt.analyses.BaseAnalysis import BaseAnalysis | ||
|
||
class TestAnalysis(BaseAnalysis): | ||
def begin_execution(self) -> None: | ||
print("begin execution") | ||
|
||
def enter_decorator(self, dyn_ast: str, iid: int, decorator: str, args, kwargs) -> None: | ||
print("enter decorator: ", decorator) | ||
print("args: ", args) | ||
|
||
def exit_decorator(self, dyn_ast: str, iid: int, decorator: str, result, args, kwargs) -> None: | ||
print("exit decorator: ", decorator) | ||
|
||
def end_execution(self) -> None: | ||
print("end execution") |
10 changes: 10 additions & 0 deletions
10
tests/trace_single_hook/decorators/decorator_func_with_args/expected.txt
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,10 @@ | ||
begin execution | ||
enter decorator: wrapper | ||
args: ('foo', 'bar') | ||
Decorator function before | ||
Simple function | ||
parameter 1: foo | ||
parameter 2: bar | ||
Decorator function after | ||
exit decorator: wrapper | ||
end execution |
15 changes: 15 additions & 0 deletions
15
tests/trace_single_hook/decorators/decorator_func_with_args/program.py
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 @@ | ||
def decorator_function_one(func): | ||
def wrapper(*args): | ||
print("Decorator function before") | ||
func(*args) | ||
print("Decorator function after") | ||
return wrapper | ||
|
||
@decorator_function_one | ||
def simple_function(arg1, arg2): | ||
print("Simple function") | ||
print("parameter 1: ", arg1) | ||
print("parameter 2: ", arg2) | ||
|
||
simple_function("foo", "bar") | ||
|
17 changes: 17 additions & 0 deletions
17
tests/trace_single_hook/decorators/decorator_result_modification/analysis.py
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,17 @@ | ||
from dynapyt.analyses.BaseAnalysis import BaseAnalysis | ||
|
||
class TestAnalysis(BaseAnalysis): | ||
def begin_execution(self) -> None: | ||
print("begin execution") | ||
|
||
def enter_decorator(self, dyn_ast: str, iid: int, decorator: str, args, kwargs) -> None: | ||
print("enter decorator: ", decorator) | ||
|
||
def exit_decorator(self, dyn_ast: str, iid: int, decorator: str, result, args, kwargs) -> None: | ||
print("exit decorator: ", decorator) | ||
number = 10 | ||
print("Number returned from exit_decorator: ", number) | ||
return number | ||
|
||
def end_execution(self) -> None: | ||
print("end execution") |
9 changes: 9 additions & 0 deletions
9
tests/trace_single_hook/decorators/decorator_result_modification/expected.txt
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,9 @@ | ||
begin execution | ||
enter decorator: wrapper | ||
Decorator function before | ||
Number returned from function: 2 | ||
Decorator function after | ||
exit decorator: wrapper | ||
Number returned from exit_decorator: 10 | ||
Number returned from decorated function: 10 | ||
end execution |
17 changes: 17 additions & 0 deletions
17
tests/trace_single_hook/decorators/decorator_result_modification/program.py
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,17 @@ | ||
def decorator_function_one(func): | ||
def wrapper(): | ||
print("Decorator function before") | ||
func() | ||
print("Decorator function after") | ||
return wrapper | ||
|
||
@decorator_function_one | ||
def return_number(): | ||
number = 2 | ||
print("Number returned from function: ", number) | ||
return number | ||
|
||
result = return_number() | ||
print("Number returned from decorated function: ", result) | ||
|
||
|
Oops, something went wrong.