Skip to content

Commit

Permalink
Apply code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ccruzagralopes committed Dec 11, 2023
1 parent 5d80b24 commit 83b19a2
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
import ast
from pathlib import Path
from typing import List
from typing import List, Optional

from test_collections.sdk_tests.support.models.matter_test_models import (
MatterTestStep,
Expand Down Expand Up @@ -78,26 +78,20 @@ def __parse_test_case_from_class(
tc_steps = []
tc_pics = []

try:
desc_method = next(m for m in methods if desc_method_name in m.name)
desc_method = __get_method_by_name(desc_method_name, methods)
if desc_method:
tc_desc = desc_method.body[BODY_INDEX].value.value # type: ignore
except StopIteration: # Raised when `next` doesn't find a matching method
pass

try:
steps_method = next(m for m in methods if steps_method_name in m.name)
# If the python test does not implement the steps template method,
# the test case will be presented in UI and the whole test case will be
# executed as one step
steps_method = __get_method_by_name(steps_method_name, methods)
if steps_method:
tc_steps = __retrieve_steps(steps_method)
except StopIteration: # Raised when `next` doesn't find a matching method
# If the python test does not implement the steps template method,
# the test case will be presented in UI and the whole test case will be
# executed as one step
pass

try:
pics_method = next(m for m in methods if pics_method_name in m.name)
pics_method = __get_method_by_name(pics_method_name, methods)
if pics_method:
tc_pics = __retrieve_pics(pics_method)
except StopIteration: # Raised when `next` doesn't find a matching method
pass

return PythonTest(
name=tc_name,
Expand All @@ -110,6 +104,12 @@ def __parse_test_case_from_class(
)


def __get_method_by_name(
name: str, methods: list[ast.FunctionDef]
) -> Optional[ast.FunctionDef]:
return next((m for m in methods if name in m.name), None)


def __retrieve_steps(method: ast.FunctionDef) -> List[MatterTestStep]:
python_steps: List[MatterTestStep] = []
for step in method.body[BODY_INDEX].value.elts: # type: ignore
Expand Down

0 comments on commit 83b19a2

Please sign in to comment.