Skip to content

Commit

Permalink
Python tests parser workaround (#61)
Browse files Browse the repository at this point in the history
* Updated version to 2.10-beta2.1+spring2024

* Updted python test parser

* Fix import sorting

* Workaround code in order to validate some python tests that are not in the correct template

* Fixed code formating

* Fixed word spelling

* Fixed mypy violation

* Include in code comment the related issue for the workaround

* Include in code comment the related issue for the workaround
  • Loading branch information
rquidute authored Jan 24, 2024
1 parent 934e3bd commit 2dcc9cb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@
KEYWORD_IS_COMISSIONING_INDEX = 0

TC_FUNCTION_PATTERN = re.compile(r"[\S]+_TC_[\S]+")
# This constant is a temporary fix for TE2
# Issue: https://github.com/project-chip/certification-tool/issues/152
TC_FUNCTION_PATTERN_WORKAROUND = re.compile(r"[\S]+_[\S]+")
TC_TEST_FUNCTION_PATTERN = re.compile(r"test_(?P<title>TC_[\S]+)")
# This constant is a temporary fix for TE2
# Issue: https://github.com/project-chip/certification-tool/issues/152
TC_TEST_FUNCTION_PATTERN_WORKAROUND = re.compile(r"test_(?P<title>[\S]+_[0-9]+_[0-9]+)")


FunctionDefType = Union[ast.FunctionDef, ast.AsyncFunctionDef]

Expand Down Expand Up @@ -107,7 +114,13 @@ def __test_methods(class_def: ast.ClassDef) -> list[FunctionDefType]:
]
for m in methods:
if isinstance(m.name, str):
if re.match(TC_FUNCTION_PATTERN, m.name):
# THIS IS A WORKAROUND CODE for TE2
# Some Python tests written in SDK repo are not following the test method
# template, test_TC_[TC_name]
# So this code temporaly code to consider other methods signature as a
# python test script.
# Issue: https://github.com/project-chip/certification-tool/issues/152
if re.match(TC_FUNCTION_PATTERN_WORKAROUND, m.name):
all_methods.append(m)

return all_methods
Expand All @@ -129,6 +142,15 @@ def __test_case_names(methods: list[FunctionDefType]) -> list[str]:
if match := re.match(TC_TEST_FUNCTION_PATTERN, m.name):
if name := match["title"]:
test_names.append(name)
# THIS IS A WORKAROUND CODE for TE2
# Some Python tests written in SDK repo are not following the test method
# template, test_TC_[TC_name]
# So this code temporaly code to consider other methods signature as a
# python test script.
# Issue: https://github.com/project-chip/certification-tool/issues/152
elif match := re.match(TC_TEST_FUNCTION_PATTERN_WORKAROUND, m.name):
if name := match["title"]:
test_names.append("TC_" + name)

return test_names

Expand Down Expand Up @@ -174,6 +196,12 @@ def __parse_test_case(
elif desc_method:
python_test_type = PythonTestType.NO_COMMISSIONING

# THIS IS A WORKAROUND CODE for TE2
# The TC_DGGEN_2_4 test case is not following the test method template
if tc_name == "TC_GEN_2_4":
tc_name = "TC_DGGEN_2_4"
tc_desc = "TC_DGGEN_2_4"

return PythonTest(
name=tc_name,
description=tc_desc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,22 @@ async def execute(self) -> None:
f"Missing file path for python test {self.python_test.name}"
)

# THIS IS A WORKAROUND CODE for TE2
# Issue: https://github.com/project-chip/certification-tool/issues/152
test_name = self.python_test.name
if test_name == "TC_DGGEN_2_4":
test_name = "TC_GEN_2_4"
elif test_name in [
"TC_DT_1_1",
"TC_IDM_10_1",
"TC_IDM_11_1",
"TC_DESC_2_2",
]:
test_name = test_name[3:]

command = [
f"{RUNNER_CLASS_PATH} {self.python_test.path.stem}"
f" {self.python_test.class_name} --tests test_{self.python_test.name}"
f" {self.python_test.class_name} --tests test_{test_name}"
]

# Generate the command argument by getting the test_parameters from
Expand Down

0 comments on commit 2dcc9cb

Please sign in to comment.