Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
hiltonlima committed Sep 16, 2024
1 parent 2512a11 commit e53dc0d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
)
from test_collections.matter.sdk_tests.support.sdk_container import SDKContainer

# .../test_collections/matter/sdk_tests
SDK_TESTS_PATH = Path(__file__).parent.parent.parent
PYTHON_TESTING_PATH = SDK_TESTS_PATH / "sdk_checkout/python_testing"
JSON_OUTPUT_FILE_PATH = PYTHON_TESTING_PATH / "data.json"
COMPLETE_JSON_OUTPUT_FILE_FOLDER = SDK_TESTS_PATH
PYTHON_SCRIPTS_PATH = PYTHON_TESTING_PATH / "scripts/sdk"
PYTHON_SCRIPTS_FOLDER = SDKTestFolder(path=PYTHON_SCRIPTS_PATH, filename_pattern="TC*")

CONTAINER_GET_TEST_INFO_COMMAND = "--get_test_info"
CONTAINER_TH_CLIENT_EXEC = (
"python3 /root/python_testing/scripts/sdk/test_harness_client.py"
)
Expand Down Expand Up @@ -71,7 +71,7 @@ def get_command_list() -> list:
for test_class in test_classes:
script_command = [f"{parent_folder}/{python_test_file.stem}"]
script_command.append(f"{test_class.name}")
script_command.append("--get_test_info")
script_command.append(CONTAINER_GET_TEST_INFO_COMMAND)
python_script_commands.append(script_command)

return python_script_commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def main() -> None:
json.dump(info, f, indent=4)
print(info)
else:
# TODO: find a better solution. This is a temporary workaround since Python Tests
# TODO: find a better solution. This is a temporary workaround since Python Tests
# are generating a big amount of log
with open("/root/python_testing/test_output.txt", "w") as f:
with redirect_stdout(f):
Expand All @@ -65,8 +65,7 @@ def main() -> None:
def get_test_info(script_path: str, class_name: str, config: MatterTestConfig):
module = importlib.import_module(script_path.replace("/", "."))
TestClassReference = getattr(module, class_name)
v = get_test_info_support(TestClassReference, config)
return v
return get_test_info_support(TestClassReference, config)


def run_test(script_path: str, class_name: str, config: MatterTestConfig) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import json
from pathlib import Path
from typing import Optional

from test_collections.matter.config import matter_settings
from test_collections.matter.sdk_tests.support.models.matter_test_models import (
MatterTestStep,
)

from ..models.sdk_test_folder import SDKTestFolder
from ..paths import SDK_CHECKOUT_PATH
from .models.python_test_models import PythonTestType
from ..paths import SDK_CHECKOUT_PATH, SDK_TESTS_ROOT
from .models.python_test_models import PythonTest, PythonTestType
from .models.python_test_parser import parse_python_script
from .models.test_declarations import (
PythonCaseDeclaration,
Expand Down Expand Up @@ -48,6 +54,10 @@
path=CUSTOM_PYTHON_TEST_PATH, filename_pattern="TC*"
)

PYTHON_TESTS_PARSED_FILE = (
SDK_TESTS_ROOT / f"python_tests_{matter_settings.SDK_SHA}.json"
)


def _init_test_suites(
python_test_version: str,
Expand Down Expand Up @@ -97,6 +107,44 @@ def __parse_python_tests(
) -> list[PythonSuiteDeclaration]:
suites = _init_test_suites(python_test_version)

with open(PYTHON_TESTS_PARSED_FILE, "r") as json_file:
parsed_scripts = json.load(json_file)

python_tests: list[PythonTest] = []

for script in parsed_scripts:
script_info = dict(script)
test_function = script_info["function"]
test_description = script_info["desc"]
test_pics = script_info["pics"]
test_steps = []
parsed_steps = script_info["steps"]
is_commssioning = False
for index, step in enumerate(parsed_steps):
if index == 1:
is_commssioning = step["is_commissioning"]

test_steps.append(
MatterTestStep(
label=step["description"],
is_commissioning=is_commssioning,
)
)

python_tests.append(
PythonTest(
name=test_function,
description=test_description,
steps=test_steps,
config={}, # Currently config is not configured in Python Testing
PICS=test_pics,
path=test_command[0],

Check failure on line 141 in test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py

View workflow job for this annotation

GitHub Actions / Flake8

test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py#L141

Undefined name 'test_command' (F821)

Check failure on line 141 in test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py

View workflow job for this annotation

GitHub Actions / Mypy

test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py#L141

Name "test_command" is not defined [name-defined]
type=MatterTestType.AUTOMATED,

Check failure on line 142 in test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py

View workflow job for this annotation

GitHub Actions / Flake8

test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py#L142

Undefined name 'MatterTestType' (F821)

Check failure on line 142 in test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py

View workflow job for this annotation

GitHub Actions / Mypy

test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py#L142

Name "MatterTestType" is not defined [name-defined]
class_name=test_command[1],

Check failure on line 143 in test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py

View workflow job for this annotation

GitHub Actions / Flake8

test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py#L143

Undefined name 'test_command' (F821)

Check failure on line 143 in test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py

View workflow job for this annotation

GitHub Actions / Mypy

test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py#L143

Name "test_command" is not defined [name-defined]
python_test_type=python_test_type,

Check failure on line 144 in test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py

View workflow job for this annotation

GitHub Actions / Flake8

test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py#L144

Undefined name 'python_test_type' (F821)

Check failure on line 144 in test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py

View workflow job for this annotation

GitHub Actions / Mypy

test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py#L144

Cannot determine type of "python_test_type" [has-type]
)
)

for python_test_file in python_test_files:
test_cases = _parse_python_script_to_test_case_declarations(
python_test_path=python_test_file,
Expand Down

0 comments on commit e53dc0d

Please sign in to comment.