Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
update: test has update walker feature
Browse files Browse the repository at this point in the history
  • Loading branch information
AshishMahendra committed Aug 30, 2024
1 parent 2cd6179 commit e5fa3dc
Showing 1 changed file with 51 additions and 5 deletions.
56 changes: 51 additions & 5 deletions jaclang/tests/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,14 +954,60 @@ def test_list_methods(self) -> None:

def test_walker_dynamic_update(self) -> None:
"""Test dynamic update of a walker during runtime."""
session = self.fixture_abs_path("bar_walk.session")
bar_file_path = self.fixture_abs_path("bar.jac")
captured_output = io.StringIO()
sys.stdout = captured_output

cli.run(
filename=self.fixture_abs_path("walker_reload/foo.jac"),
cli.enter(
filename=bar_file_path,
session=session,
entrypoint="bar_walk",
args=[],
)
sys.stdout = sys.__stdout__
stdout_value = captured_output.getvalue()
print(f"Stdout: {stdout_value}")
expected_output = "bar_walk has been updated with new behavior!"
expected_output = "Created 5 items."
self.assertIn(expected_output, stdout_value.split("\n"))
# Define the new behavior to be added
new_behavior = """
# New behavior added during runtime
can end with `root exit {
"bar_walk has been updated with new behavior!" |> print;
disengage;
}
}
"""

# Backup the original file content
with open(bar_file_path, "r") as bar_file:
original_content = bar_file.read()

# Update the bar.jac file with new behavior
with open(bar_file_path, "r+") as bar_file:
content = bar_file.read()
last_brace_index = content.rfind("}")
if last_brace_index != -1:
updated_content = content[:last_brace_index] + new_behavior
bar_file.seek(0)
bar_file.write(updated_content)
bar_file.truncate()

captured_output = io.StringIO()
sys.stdout = captured_output

try:
cli.enter(
filename=bar_file_path,
session=session,
entrypoint="bar_walk",
args=[],
)
sys.stdout = sys.__stdout__
stdout_value = captured_output.getvalue()
expected_output = "bar_walk has been updated with new behavior!"
self.assertIn(expected_output, stdout_value.split("\n"))
finally:
# Restore the original content of bar.jac
with open(bar_file_path, "w") as bar_file:

bar_file.write(original_content)

0 comments on commit e5fa3dc

Please sign in to comment.