From 3148d14065bfe60885a7771438c3af19d9a34a39 Mon Sep 17 00:00:00 2001 From: Aryaz Eghbali Date: Fri, 27 Oct 2023 15:53:38 +0200 Subject: [PATCH] Added tests for write hook --- tests/trace_single_hook/write/analysis.py | 13 +++++++++++++ tests/trace_single_hook/write/expected.txt | 5 +++++ tests/trace_single_hook/write/program.py | 3 +++ 3 files changed, 21 insertions(+) create mode 100644 tests/trace_single_hook/write/analysis.py create mode 100644 tests/trace_single_hook/write/expected.txt create mode 100644 tests/trace_single_hook/write/program.py diff --git a/tests/trace_single_hook/write/analysis.py b/tests/trace_single_hook/write/analysis.py new file mode 100644 index 0000000..a096cb4 --- /dev/null +++ b/tests/trace_single_hook/write/analysis.py @@ -0,0 +1,13 @@ +from typing import Optional +from dynapyt.analyses.BaseAnalysis import BaseAnalysis + + +class TestAnalysis(BaseAnalysis): + def begin_execution(self) -> None: + print("begin execution") + + def end_execution(self) -> None: + print("end execution") + + def write(self, dyn_ast, iid, old_values, new_value): + print(f"Writing {new_value} to {[ov.__code__.co_names for ov in old_values]}") diff --git a/tests/trace_single_hook/write/expected.txt b/tests/trace_single_hook/write/expected.txt new file mode 100644 index 0000000..15c0b03 --- /dev/null +++ b/tests/trace_single_hook/write/expected.txt @@ -0,0 +1,5 @@ +begin execution +Writing 10 to [('a',)] +Writing test to [('b',)] +Writing testtesttesttesttesttesttesttesttesttest to [('c',)] +end execution \ No newline at end of file diff --git a/tests/trace_single_hook/write/program.py b/tests/trace_single_hook/write/program.py new file mode 100644 index 0000000..dae9558 --- /dev/null +++ b/tests/trace_single_hook/write/program.py @@ -0,0 +1,3 @@ +a = 10 +b = "test" +c = a * b