Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions render_machine/actions/run_conformance_tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import Any

import render_machine.render_utils as render_utils
Expand All @@ -16,6 +17,8 @@ class RunConformanceTests(BaseAction):
UNRECOVERABLE_ERROR_OUTCOME = "unrecoverable_error_occurred"

def execute(self, render_context: RenderContext, _previous_action_payload: Any | None):
conformance_tests_script = os.path.normpath(render_context.conformance_tests_script)

if render_context.module_name == render_context.conformance_tests_running_context.current_testing_module_name:
conformance_tests_folder_name = (
render_context.conformance_tests_running_context.get_current_conformance_test_folder_name()
Expand All @@ -32,14 +35,14 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |

if render_context.verbose:
console.info(
f"Running conformance tests script {render_context.conformance_tests_script} "
f"Running conformance tests script {conformance_tests_script} "
+ f"for {conformance_tests_folder_name} ("
+ f"functionality {render_context.conformance_tests_running_context.current_testing_frid} "
+ f"in module {render_context.conformance_tests_running_context.current_testing_module_name}"
+ ")."
)
exit_code, conformance_tests_issue, conformance_tests_temp_file_path = render_utils.execute_script(
render_context.conformance_tests_script,
conformance_tests_script,
[render_context.build_folder, conformance_tests_folder_name],
render_context.verbose,
"Conformance Tests",
Expand Down Expand Up @@ -72,9 +75,9 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |
RenderError.encode(
message=conformance_tests_issue,
error_type="ENVIRONMENT_ERROR",
exit_code=exit_code,
script=render_context.conformance_tests_script,
script=conformance_tests_script,
frid=render_context.conformance_tests_running_context.current_testing_frid,
issue=conformance_tests_issue,
).to_payload(),
)

Expand Down
12 changes: 8 additions & 4 deletions render_machine/actions/run_unit_tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import Any

import render_machine.render_utils as render_utils
Expand All @@ -15,12 +16,14 @@ class RunUnitTests(BaseAction):
UNRECOVERABLE_ERROR_OUTCOME = "unrecoverable_error_occurred"

def execute(self, render_context: RenderContext, _previous_action_payload: Any | None):
unittests_script = os.path.normpath(render_context.unittests_script)

if render_context.verbose:
console.info(
f"Running unit tests script {render_context.unittests_script}. (attempt: {render_context.unit_tests_running_context.fix_attempts + 1})"
f"Running unit tests script {unittests_script}. (attempt: {render_context.unit_tests_running_context.fix_attempts + 1})"
)
exit_code, unittests_issue, unittests_temp_file_path = render_utils.execute_script(
render_context.unittests_script,
unittests_script,
[render_context.build_folder],
render_context.verbose,
"Unit Tests",
Expand All @@ -35,13 +38,14 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |

elif exit_code in UNRECOVERABLE_ERROR_EXIT_CODES:
console.error(unittests_issue)

return (
self.UNRECOVERABLE_ERROR_OUTCOME,
RenderError.encode(
message="Unit tests script failed due to problems in the environment setup. Please check your environment or update the script for running unittests.",
error_type="ENVIRONMENT_ERROR",
exit_code=exit_code,
script=render_context.unittests_script,
script=unittests_script,
issue=unittests_issue,
).to_payload(),
)
else:
Expand Down
6 changes: 5 additions & 1 deletion render_machine/render_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ def format_for_display(self) -> str:
if self.details:
lines.append("\nDetails:")
for detail_name, detail_value in self.details.items():
lines.append(f" {detail_name}: {detail_value}")
if detail_name == "issue":
detail_value_indented = "\n".join(" " + line for line in detail_value.splitlines())
lines.append(detail_value_indented)
else:
lines.append(f" {detail_name.capitalize()}: {detail_value}")

return "\n".join(lines)

Expand Down
18 changes: 16 additions & 2 deletions render_machine/render_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import signal
import subprocess
import sys
Expand Down Expand Up @@ -70,6 +71,17 @@ def _kill_process(proc: subprocess.Popen) -> None:
proc.kill()


def _sanitize_script_output(script_output: str) -> str:
# this function removes the escape codes that clear the console
clear_console_escape_codes_pattern = r"(?:\033\[[^a-zA-Z]*[a-zA-Z])*\033\[2J(?:\033\[[^a-zA-Z]*[a-zA-Z])*"

pattern = re.compile(clear_console_escape_codes_pattern)
parts = pattern.split(script_output)

# take only the part after the last clear console escape code
return parts[-1] if len(parts) > 1 else script_output


def execute_script( # noqa: C901
script: str,
scripts_args: list[str],
Expand Down Expand Up @@ -125,13 +137,15 @@ def execute_script( # noqa: C901
stdout = ""
elapsed_time = time.time() - start_time

sanitized_script_output = _sanitize_script_output(stdout)

# Log the info about the script execution
if verbose:
with tempfile.NamedTemporaryFile(
mode="w+", encoding="utf-8", delete=False, suffix=".script_output"
) as temp_file:
temp_file.write(f"\n═════════════════════════ {script_type} Script Output ═════════════════════════\n")
temp_file.write(stdout)
temp_file.write(sanitized_script_output)
temp_file.write("\n══════════════════════════════════════════════════════════════════════\n")
temp_file_path = temp_file.name
if proc.returncode != 0:
Expand Down Expand Up @@ -159,7 +173,7 @@ def execute_script( # noqa: C901
else:
console.info(f"[#79FC96]All {script_type} scripts have passed successfully.[/#79FC96]")

return proc.returncode, stdout, temp_file_path
return proc.returncode, sanitized_script_output, temp_file_path

except RenderCancelledError:
raise
Expand Down
1 change: 1 addition & 0 deletions test_scripts/run_unittests_golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cp -R $1/* $GO_BUILD_SUBFOLDER
cd "$GO_BUILD_SUBFOLDER" 2>/dev/null

if [ $? -ne 0 ]; then
clear
printf "Error: Go build folder '$GO_BUILD_SUBFOLDER' does not exist.\n"
exit $UNRECOVERABLE_ERROR_EXIT_CODE
fi
Expand Down
1 change: 1 addition & 0 deletions test_scripts/run_unittests_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ cp -R $1/* $PYTHON_BUILD_SUBFOLDER
cd "$PYTHON_BUILD_SUBFOLDER" 2>/dev/null

if [ $? -ne 0 ]; then
clear
printf "Error: Python build folder '$PYTHON_BUILD_SUBFOLDER' does not exist.\n"
exit $UNRECOVERABLE_ERROR_EXIT_CODE
fi
Expand Down
1 change: 1 addition & 0 deletions test_scripts/run_unittests_react.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ cp -R $1/* $NODE_SUBFOLDER
cd "$NODE_SUBFOLDER" 2>/dev/null

if [ $? -ne 0 ]; then
clear
echo "Error: Subfolder '$1' does not exist."
exit $UNRECOVERABLE_ERROR_EXIT_CODE
fi
Expand Down
Loading