-
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 #71 from KeerthiVasudevan/main
Extended with hook to handle multiple items
- Loading branch information
Showing
38 changed files
with
273 additions
and
15 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
tests/trace_single_hook/with/with_multiple_items/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,12 @@ | ||
begin execution | ||
with statement entered | ||
with statement entered | ||
Line read from expected.txt: begin execution | ||
|
||
Line read from analysis.py: from dynapyt.analyses.BaseAnalysis import BaseAnalysis | ||
|
||
content has been read from the files | ||
with statement exited | ||
with statement exited | ||
file has been closed | ||
end execution |
13 changes: 13 additions & 0 deletions
13
tests/trace_single_hook/with/with_multiple_items/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 @@ | ||
import os | ||
|
||
dir_name = os.path.dirname(os.path.realpath(__file__)) | ||
file_path_1 = os.path.join(dir_name, "expected.txt") | ||
file_path_2 = os.path.join(dir_name, "analysis.py") | ||
with open(file_path_1, "r") as file1, open(file_path_2, "r") as file2: | ||
content = file1.readline() | ||
print("Line read from expected.txt: ", content) | ||
content = file2.readline() | ||
print("Line read from analysis.py: ", content) | ||
print("content has been read from the files") | ||
|
||
print("file has been closed") |
14 changes: 14 additions & 0 deletions
14
tests/trace_single_hook/with/with_multiple_items_as_specifier_case_1/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_with(self, dyn_ast: str, iid: int, ctx_manager): | ||
print(f"with statement entered") | ||
|
||
def exit_with(self, dyn_ast: str, iid: int, is_suppressed: bool, exc_value): | ||
print(f"with statement exited") | ||
|
||
def end_execution(self) -> None: | ||
print("end execution") |
11 changes: 11 additions & 0 deletions
11
tests/trace_single_hook/with/with_multiple_items_as_specifier_case_1/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,11 @@ | ||
begin execution | ||
with statement entered | ||
with statement entered | ||
Line read from expected.txt: begin execution | ||
|
||
Line read from analysis.py: from dynapyt.analyses.BaseAnalysis import BaseAnalysis | ||
|
||
content has been read from the files | ||
with statement exited | ||
with statement exited | ||
end execution |
19 changes: 19 additions & 0 deletions
19
tests/trace_single_hook/with/with_multiple_items_as_specifier_case_1/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,19 @@ | ||
import os | ||
|
||
dir_name = os.path.dirname(os.path.realpath(__file__)) | ||
file_path_one = os.path.join(dir_name, "expected.txt") | ||
file_path_two = os.path.join(dir_name, "analysis.py") | ||
|
||
file1 = open(file_path_one, "r") | ||
file2 = open(file_path_two, "r") | ||
with file1, file2: | ||
content = file1.readline() | ||
print("Line read from expected.txt: " + content) | ||
content = file2.readline() | ||
print("Line read from analysis.py: " + content) | ||
print("content has been read from the files") | ||
|
||
|
||
|
||
|
||
|
14 changes: 14 additions & 0 deletions
14
tests/trace_single_hook/with/with_multiple_items_as_specifier_case_2/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_with(self, dyn_ast: str, iid: int, ctx_manager): | ||
print(f"with statement entered") | ||
|
||
def exit_with(self, dyn_ast: str, iid: int, is_suppressed: bool, exc_value): | ||
print(f"with statement exited") | ||
|
||
def end_execution(self) -> None: | ||
print("end execution") |
15 changes: 15 additions & 0 deletions
15
tests/trace_single_hook/with/with_multiple_items_as_specifier_case_2/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,15 @@ | ||
begin execution | ||
with statement entered | ||
with statement entered | ||
with statement entered | ||
Line read from expected.txt: begin execution | ||
|
||
Line read from expected.txt: begin execution | ||
|
||
Line read from analysis.py: from dynapyt.analyses.BaseAnalysis import BaseAnalysis | ||
|
||
content has been read from the files | ||
with statement exited | ||
with statement exited | ||
with statement exited | ||
end execution |
22 changes: 22 additions & 0 deletions
22
tests/trace_single_hook/with/with_multiple_items_as_specifier_case_2/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,22 @@ | ||
import os | ||
|
||
dir_name = os.path.dirname(os.path.realpath(__file__)) | ||
file_path_one = os.path.join(dir_name, "expected.txt") | ||
file_path_two = os.path.join(dir_name, "expected.txt") | ||
file_path_three = os.path.join(dir_name, "analysis.py") | ||
|
||
file1 = open(file_path_one, "r") | ||
file3 = open(file_path_three, "r") | ||
with file1, open(file_path_two, "r") as file2, file3: | ||
content = file1.readline() | ||
print("Line read from expected.txt: " + content) | ||
content = file2.readline() | ||
print("Line read from expected.txt: " + content) | ||
content = file3.readline() | ||
print("Line read from analysis.py: " + content) | ||
print("content has been read from the files") | ||
|
||
|
||
|
||
|
||
|
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
tests/trace_single_hook/with/with_multiple_items_suppress_exception/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,18 @@ | ||
begin execution | ||
with statement entered | ||
ContextManagerOne: __enter__ | ||
with statement entered | ||
ContextManagerTwo: __enter__ | ||
inside with block | ||
context manager one | ||
context manager two | ||
ContextManagerTwo: __exit__ | ||
exc_type: <class 'Exception'> | ||
exc_value: exception raised inside with statement block | ||
with statement exited | ||
ContextManagerOne: __exit__ | ||
exc_type: None | ||
exc_value: None | ||
with statement exited | ||
no exception raised | ||
end execution |
34 changes: 34 additions & 0 deletions
34
tests/trace_single_hook/with/with_multiple_items_suppress_exception/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,34 @@ | ||
class ContextManagerOne: | ||
|
||
def __enter__(self): | ||
print('ContextManagerOne: __enter__') | ||
return "context manager one" | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
print('ContextManagerOne: __exit__') | ||
print("exc_type: ", exc_type) | ||
print("exc_value: ", exc_value) | ||
return True | ||
|
||
class ContextManagerTwo: | ||
|
||
def __enter__(self): | ||
print('ContextManagerTwo: __enter__') | ||
return "context manager two" | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
print('ContextManagerTwo: __exit__') | ||
print("exc_type: ", exc_type) | ||
print("exc_value: ", exc_value) | ||
return True | ||
|
||
try : | ||
with ContextManagerOne() as cm1, ContextManagerTwo() as cm2: | ||
print('inside with block') | ||
print(cm1) | ||
print(cm2) | ||
raise Exception("exception raised inside with statement block") | ||
except Exception as e: | ||
print("exception caught: ", e) | ||
else: | ||
print("no exception raised") |
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
tests/trace_single_hook/with/with_multiple_raise_exception/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,18 @@ | ||
begin execution | ||
with statement entered | ||
ContextManagerOne: __enter__ | ||
with statement entered | ||
ContextManagerTwo: __enter__ | ||
inside with block | ||
context manager one | ||
context manager two | ||
ContextManagerTwo: __exit__ | ||
exc_type: <class 'Exception'> | ||
exc_value: exception raised inside with statement block | ||
with statement exited | ||
ContextManagerOne: __exit__ | ||
exc_type: <class 'Exception'> | ||
exc_value: exception raised inside with statement block | ||
with statement exited | ||
exception caught: exception raised inside with statement block | ||
end execution |
32 changes: 32 additions & 0 deletions
32
tests/trace_single_hook/with/with_multiple_raise_exception/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,32 @@ | ||
class ContextManagerOne: | ||
|
||
def __enter__(self): | ||
print('ContextManagerOne: __enter__') | ||
return "context manager one" | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
print('ContextManagerOne: __exit__') | ||
print("exc_type: ", exc_type) | ||
print("exc_value: ", exc_value) | ||
|
||
class ContextManagerTwo: | ||
|
||
def __enter__(self): | ||
print('ContextManagerTwo: __enter__') | ||
return "context manager two" | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
print('ContextManagerTwo: __exit__') | ||
print("exc_type: ", exc_type) | ||
print("exc_value: ", exc_value) | ||
|
||
try : | ||
with ContextManagerOne() as cm1, ContextManagerTwo() as cm2: | ||
print('inside with block') | ||
print(cm1) | ||
print(cm2) | ||
raise Exception("exception raised inside with statement block") | ||
except Exception as e: | ||
print("exception caught: ", e) | ||
else: | ||
print("no exception raised") |
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
tests/trace_single_hook/with/with_raise_exception/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_with(self, dyn_ast: str, iid: int, ctx_manager): | ||
print(f"with statement entered") | ||
|
||
def exit_with(self, dyn_ast: str, iid: int, is_suppressed: bool, exc_value): | ||
print(f"with statement exited") | ||
|
||
def end_execution(self) -> None: | ||
print("end execution") |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
tests/trace_single_hook/with/with_suppress_exception/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_with(self, dyn_ast: str, iid: int, ctx_manager): | ||
print(f"with statement entered") | ||
|
||
def exit_with(self, dyn_ast: str, iid: int, is_suppressed: bool, exc_value): | ||
print(f"with statement exited") | ||
|
||
def end_execution(self) -> None: | ||
print("end execution") |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
tests/trace_single_hook/with/with_without_as_specifier/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_with(self, dyn_ast: str, iid: int, ctx_manager): | ||
print(f"with statement entered") | ||
|
||
def exit_with(self, dyn_ast: str, iid: int, is_suppressed: bool, exc_value): | ||
print(f"with statement exited") | ||
|
||
def end_execution(self) -> None: | ||
print("end execution") |
File renamed without changes.
File renamed without changes.