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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from .utils import (
EXECUTABLE,
RUNNER_CLASS_PATH,
TEST_OUTPUT_FILE_PATH,
DUTCommissioningError,
PromptOption,
commission_device,
Expand All @@ -65,9 +66,6 @@
LOG_BATCH_SIZE = 50 # Number of log lines to send per batch
LOG_BATCH_DELAY = 0.01 # Delay in seconds between batches (10ms)

# Test output file path relative to sdk_tests directory
TEST_OUTPUT_FILE_PATH = "sdk_checkout/python_testing/test_output.txt"

# Custom type variable used to annotate the factory method in PythonTestCase.
T = TypeVar("T", bound="PythonTestCase")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
RUNNER_CLASS_PATH = "/root/python_testing/scripts/sdk/matter_testing_infrastructure/chip/testing/test_harness_client.py" # noqa
EXECUTABLE = "python3"

# Test output file path relative to sdk_tests directory
TEST_OUTPUT_FILE_PATH = "sdk_checkout/python_testing/test_output.txt"

TEST_PARAMETER_STORAGE_PATH_KEY = "storage-path"


Expand Down Expand Up @@ -157,13 +160,38 @@ def __copy_admin_storage_file(
)


def log_test_output_file(logger: loguru.Logger) -> None:
"""Log the entire content of test_output.txt file.

Args:
logger: Logger instance to write logs to
"""
try:
# Navigate up 3 levels from utils.py to sdk_tests directory
sdk_tests_path = next(
(p for p in Path(__file__).resolve().parents if p.name == "sdk_tests"),
Path(__file__).parents[3],
)
file_output_path = sdk_tests_path / TEST_OUTPUT_FILE_PATH

if file_output_path.exists():
with open(file_output_path, "r") as f:
content = f.read()
if content.strip(): # Only log if there's actual content
logger.log(PYTHON_TEST_LEVEL, content)
else:
logger.debug(f"test_output.txt not found at {file_output_path}")
except (OSError, IndexError) as e:
logger.warning(f"Could not read test_output.txt: {e}")


async def commission_device(
config: TestEnvironmentConfigMatter,
logger: loguru.Logger,
) -> None:
sdk_container = SDKContainer(logger)

command = [f"{RUNNER_CLASS_PATH} commission"]
command = [f"{RUNNER_CLASS_PATH} --commission"]
Comment thread
antonio-amjr marked this conversation as resolved.
command_arguments = await generate_command_arguments(config)
command.extend(command_arguments)

Expand All @@ -181,6 +209,11 @@ async def commission_device(
if exit_code:
raise DUTCommissioningError("Failed to commission DUT")

# Print all content from test_output.txt file after commissioning
logger.info("---- Start of commissioning test output ----")
log_test_output_file(logger)
logger.info("---- End of commissioning test output ----")

# Copy admin_storage.json file from container, in case the user wants to
# reuse this information in the next execution
__copy_admin_storage_file(config, logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ async def test_commission_device() -> None:
sdk_container: SDKContainer = SDKContainer()

command_args = ["arg1", "arg2", "arg3"]
expected_command = [f"{RUNNER_CLASS_PATH} commission"]
expected_command = [f"{RUNNER_CLASS_PATH} --commission"]
expected_command.extend(command_args)
mock_result = ExecResultExtended(0, "log output".encode(), "ID", mock.MagicMock())

Expand All @@ -451,7 +451,10 @@ async def test_commission_device() -> None:
), mock.patch(
target="test_collections.matter.sdk_tests.support.python_testing.models.utils"
".handle_logs"
) as mock_handle_logs, mock.patch.object(
) as mock_handle_logs, mock.patch(
target="test_collections.matter.sdk_tests.support.python_testing.models.utils"
".log_test_output_file"
) as mock_log_test_output, mock.patch.object(
target=sdk_container, attribute="exec_exit_code", return_value=0
):
await commission_device(
Expand All @@ -462,14 +465,15 @@ async def test_commission_device() -> None:
expected_command, prefix=EXECUTABLE, is_stream=True, is_socket=False
)
mock_handle_logs.assert_called_once()
mock_log_test_output.assert_called_once()


@pytest.mark.asyncio
async def test_commission_device_failure() -> None:
sdk_container: SDKContainer = SDKContainer()

command_args = ["arg1", "arg2", "arg3"]
expected_command = [f"{RUNNER_CLASS_PATH} commission"]
expected_command = [f"{RUNNER_CLASS_PATH} --commission"]
expected_command.extend(command_args)
mock_result = ExecResultExtended(0, "log output".encode(), "ID", mock.MagicMock())

Expand Down