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

Commit

Permalink
[CI] Improve GitHub Actions Log info (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrr1999 authored Jul 20, 2023
1 parent d3f7642 commit 6668085
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 10 deletions.
10 changes: 8 additions & 2 deletions examples/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ export STRICT_MODE=1
for file in ./*.py; do
# 检查文件是否为 Python 文件
if [ -f "$file" ]; then
echo "============================================================="
echo Running: LOG_LEVEL=3 PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file
if [[ -n "$GITHUB_ACTIONS" ]]; then
echo ::group::example Running: LOG_LEVEL=3 PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file
else
echo Running: LOG_LEVEL=3 PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file
fi
# 执行文件
python "$file"
if [ $? -ne 0 ]; then
echo "run $file failed"
exit 1
fi
if [[ -n "$GITHUB_ACTIONS" ]]; then
echo "::endgroup::"
fi
fi
done
1 change: 1 addition & 0 deletions sot/opcode_translator/executor/variables/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class VariableBase:
"""

tracker: Tracker # An attribute to store the Tracker object associated with the variable
value: Any
name_generator = NameGenerator(
"object_"
) # A class-level attribute to generate names for new variables
Expand Down
3 changes: 3 additions & 0 deletions sot/opcode_translator/executor/variables/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def get_items(self) -> list[VariableBase]:
'ContainerVariable.get_items do not implement'
)

def get_wrapped_items(self):
raise NotImplementException()

def __len__(self):
raise NotImplementException(
'ContainerVariable.__len__ do not implement'
Expand Down
16 changes: 16 additions & 0 deletions tests/extract_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import re
import sys

runtime_error_msg = sys.stdin.read()

pattern = r'File "?(.*?)"?, line (\d+),.*\n(.*?)\n(.*?)$'
for match in re.finditer(pattern, runtime_error_msg, re.MULTILINE):
file = match.group(1)
if file.startswith("./"):
file = f"tests/{file[2:]}"
line = match.group(2)
error_info = match.group(4)
if "AssertionError" not in error_info:
# error_info = match.group(3) + '\n' + match.group(4)
output = f"::error file={file},line={line}::Error"
print(output)
20 changes: 16 additions & 4 deletions tests/run_all.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# 遍历目录下的所有 Python 文件
# 遍历目录下的所有 python 文件
export PYTHONPATH=$PYTHONPATH:../
export STRICT_MODE=1

failed_tests=()

for file in ./test_*.py; do
# 检查文件是否为 Python 文件
# 检查文件是否为 python 文件
if [ -f "$file" ]; then
echo Running: PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file
if [[ -n "$GITHUB_ACTIONS" ]]; then
echo ::group::Running: PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file
else
echo Running: PYTHONPATH=$PYTHONPATH " STRICT_MODE=1 python " $file
fi
# 执行文件
python "$file"
python_output=$(python $file 2>&1)

if [ $? -ne 0 ]; then
echo "run $file failed"
failed_tests+=("$file")
if [[ -n "$GITHUB_ACTIONS" ]]; then
echo -e "$python_output" | python ./extract_errors.py
fi
echo -e "$python_output"
fi
if [[ -n "$GITHUB_ACTIONS" ]]; then
echo "::endgroup::"
fi
fi
done
Expand Down
43 changes: 39 additions & 4 deletions tests/test_case_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import contextlib
import copy
import inspect
import os
import unittest

Expand All @@ -20,19 +21,52 @@ def test_instruction_translator_cache_context():
cache.clear()


def github_action_error_msg(msg: str):
if 'GITHUB_ACTIONS' in os.environ:
frame = inspect.currentframe()
if frame is not None:
# find the first frame that is in the test folder
while frame.f_back is not None:
filename = frame.f_code.co_filename
if filename.startswith("./"):
filename = f"tests/{filename[2:]}"
lineno = frame.f_lineno
output = f"\n::error file={filename},line={lineno}::{msg}"
return output
frame = frame.f_back
return None


class TestCaseBase(unittest.TestCase):
def assertIs(self, x, y, msg=None):
super().assertIs(x, y, msg=msg)
if msg is None:
msg = f"Assert Is, x is {x}, y is {y}"
msg = github_action_error_msg(msg)
if msg is not None:
print(msg)

def assertEqual(self, x, y, msg=None):
super().assertEqual(x, y, msg=msg)
if msg is None:
msg = f"Assert Equal, x is {x}, y is {y}"
msg = github_action_error_msg(msg)
if msg is not None:
print(msg)

def assert_nest_match(self, x, y):
cls_x = type(x)
cls_y = type(y)
self.assertIs(
cls_x, cls_y, msg=f"type mismatch, x is {cls_x}, y is {cls_y}"
)
msg = f"type mismatch, x is {cls_x}, y is {cls_y}"
self.assertIs(cls_x, cls_y, msg=msg)

container_types = (tuple, list, dict, set)
if cls_x in container_types:
msg = f"length mismatch, x is {len(x)}, y is {len(y)}"
self.assertEqual(
len(x),
len(y),
msg=f"length mismatch, x is {len(x)}, y is {len(y)}",
msg=msg,
)
if cls_x in (tuple, list):
for x_item, y_item in zip(x, y):
Expand All @@ -45,6 +79,7 @@ def assert_nest_match(self, x, y):
# TODO: Nested set is not supported yet
self.assertEqual(x, y)
elif cls_x in (np.ndarray, paddle.Tensor):
# TODO: support assert_allclose github error log
np.testing.assert_allclose(x, y)
else:
self.assertEqual(x, y)
Expand Down

0 comments on commit 6668085

Please sign in to comment.