Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python tests model classes #19

Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f50fa34
Created model classes for SDK python tests
rquidute Nov 6, 2023
6a77265
Added parser implementation to python test
rquidute Nov 8, 2023
d54d375
Changed init from sdk_tests
rquidute Nov 8, 2023
790c528
Merge branch 'main' into feature/74_phase3-add_python_tests_model_cla…
rquidute Nov 8, 2023
1985230
Minor changes
rquidute Nov 8, 2023
91fdbf9
Disable support to list python test cases
rquidute Nov 8, 2023
df0e129
Reverted minor changes
rquidute Nov 8, 2023
fe24421
Added Unit tests
rquidute Nov 8, 2023
e8c6ef7
Minor change
rquidute Nov 8, 2023
e6871e0
Merge with main
rquidute Nov 8, 2023
b682e0d
Fix merge conflict
rquidute Nov 8, 2023
1b8e180
Fix CI issues
rquidute Nov 8, 2023
6b1bc86
Fix mypy and flake violations
rquidute Nov 8, 2023
ba061c2
Fix mypy and flake violations
rquidute Nov 9, 2023
817f72a
Fix mypy and flake violations
rquidute Nov 9, 2023
beb46b3
Fixed unit tests
rquidute Nov 9, 2023
8da8227
Add iniial code for Python Test runner
rquidute Nov 10, 2023
879b7de
Fix code violation and add code to chip_tool for python runner
rquidute Nov 10, 2023
5872265
Fix code violation
rquidute Nov 10, 2023
8a89c18
Changes after code review
rquidute Nov 13, 2023
118cc89
Removed unsued code
rquidute Nov 13, 2023
b914e19
Few tweeks based on observation running end to end.
gladystonfranca Nov 13, 2023
939bf15
Merge branch 'main' into feature/74_phase3-add_python_tests_model_cla…
rquidute Nov 14, 2023
ba9c21e
Created top level classes for test models
rquidute Nov 14, 2023
8f5f77c
Fix code violation
rquidute Nov 14, 2023
e0dc0da
Code changes after review
rquidute Nov 16, 2023
bfa0725
Merge branch 'project-chip:main' into feature/74_phase3-add_python_te…
rquidute Nov 17, 2023
352f80b
Code changes after code review
rquidute Nov 22, 2023
7f34cbf
Putting back .version_information
rquidute Nov 22, 2023
1502f2e
Putting back .version_information
rquidute Nov 22, 2023
10ac46b
Fixed mypy violations
rquidute Nov 22, 2023
17ec11a
Removed unused imports
rquidute Nov 22, 2023
77cf574
adding rpc client code and mounting new volumes on sdk container
gladystonfranca Nov 27, 2023
63e39e2
Merge branch 'project-chip:main' into feature/74_phase3-add_python_te…
rquidute Nov 27, 2023
2135ffd
Fixing sdk rpc file path
gladystonfranca Nov 27, 2023
cee194f
Code changed after code review
rquidute Nov 29, 2023
01d9d57
Update app/tests/python_tests/test_python_test_suite.py
rquidute Nov 29, 2023
030da70
Code changes after review
rquidute Nov 29, 2023
de0c0c4
Remove whitespace from a blank line
rquidute Nov 29, 2023
e78a09d
Merge branch 'project-chip:main' into feature/74_phase3-add_python_te…
rquidute Nov 30, 2023
0a769fb
Add support for PICS in python tests
ccruzagralopes Nov 30, 2023
c7ad322
Update some unit tests
ccruzagralopes Nov 30, 2023
edcf2cd
Merge pull request #1 from ccruzagralopes/add_support_for_PICS_in_pyt…
rquidute Nov 30, 2023
5904c9d
Get python test parameters from project config
rquidute Dec 1, 2023
3198ecd
Fix Unit tests
rquidute Dec 1, 2023
f35d043
Updated unit tests
rquidute Dec 4, 2023
9bb424f
Removed unused test files
rquidute Dec 4, 2023
e5dfd63
Code updated due to code review
rquidute Dec 5, 2023
1e1ae77
Make PICS optional for python tests
rquidute Dec 6, 2023
890cf2e
Added SDKPythonTestResult class in order to handle the python test re…
rquidute Dec 6, 2023
8a116d1
Create SDKPythonTestResultBase and make subclass for each result
rquidute Dec 6, 2023
eceb15b
Make default attribute type set in SDKPythonTestResultBase subclasses
rquidute Dec 6, 2023
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
55 changes: 36 additions & 19 deletions app/chip_tool/chip_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@
XML_SPEC_DEFINITION_PATH = TEST_COLLECTION_SDK_CHECKOUT_PATH / Path(
"sdk_runner/specifications/chip/"
)
# Python Testing Folder
# LOCAL_PYTHON_TESTING_PATH = TEST_COLLECTION_SDK_CHECKOUT_PATH / Path(
# "python_testing/scripts/sdk"
# )
# DOCKER_PYTHON_TESTING_PATH = "/root/python_testing"

# RPC Client Running on SDK Container
LOCAL_RPC_PYTHON_TESTING_PATH = BACKEND_ROOT / Path(
"test_collections/sdk_tests/support/python_testing/models/rpc_client/"
)
DOCKER_RPC_PYTHON_TESTING_PATH = "/root/python_testing/rpc_client"


# Docker Network
Expand All @@ -132,6 +143,7 @@ class ChipToolUnknownTestType(Exception):
class ChipToolTestType(str, Enum):
CHIP_TOOL = "chip-tool"
CHIP_APP = "chip-app"
PYTHON_TEST = "python-test"
rquidute marked this conversation as resolved.
Show resolved Hide resolved


class ChipTool(metaclass=Singleton):
Expand Down Expand Up @@ -168,6 +180,10 @@ class ChipTool(metaclass=Singleton):
"bind": DOCKER_CREDENTIALS_DEVELOPMENT_PATH,
"mode": "ro",
},
LOCAL_RPC_PYTHON_TESTING_PATH: {
"bind": DOCKER_RPC_PYTHON_TESTING_PATH,
"mode": "rw",
},
},
}

Expand Down Expand Up @@ -347,46 +363,47 @@ def __get_gateway_ip(self) -> str:
.get(DOCKER_GATEWAY_KEY, "")
)

async def start_container(
self, test_type: ChipToolTestType, use_paa_certs: bool = False
) -> None:
"""Creates the chip-tool container.

Returns only when the container is created and all chip-tool services start.
async def start_container(self) -> None:
"""
Creates the chip-tool container without any server running
(ChipTool or ChipApp).
"""

if self.is_running():
self.logger.info(
"chip-tool container already running, no need to start a new container"
)
return

ccruzagralopes marked this conversation as resolved.
Show resolved Hide resolved
# Ensure there's no existing container running using the same name.
self.__destroy_existing_container()

# Async return when the container is running
self.__chip_tool_container = await container_manager.create_container(
self.image_tag, self.run_parameters
)

# Reset any previous states
self.__last_exec_id = None
self.__pics_file_created = False

# Generate new random node id for the DUT
self.__reset_node_id()
self.logger.info(f"New Node Id generated: {hex(self.node_id)}")

self.logger.info(
f"""
chip-tool started: {self.container_name}
with configuration: {self.run_parameters}
"""
)

# Server started is false after spinning up a new container.
self.__server_started = False

async def start_server(
self, test_type: ChipToolTestType, use_paa_certs: bool = False
) -> None:
"""Creates the chip-tool container.

Returns only when the container is created and all chip-tool services start.
"""
if self.is_running():
self.logger.info(
"chip-tool container already running, no need to start a new container"
)
return

await self.start_container()

web_socket_config = WebSocketRunnerConfig()
web_socket_config.server_address = self.__get_gateway_ip()
self.__test_harness_runner = WebSocketRunner(config=web_socket_config)
Expand Down Expand Up @@ -590,7 +607,7 @@ async def run_test(

if test_type == ChipToolTestType.CHIP_TOOL:
test_path = f"{YAML_TESTS_PATH}/{test_id}.yaml"
else:
elif test_type == ChipToolTestType.CHIP_APP:
rquidute marked this conversation as resolved.
Show resolved Hide resolved
test_path = f"{YAML_TESTS_PATH}/{test_id}_Simulated.yaml"

parser_config = TestParserConfig(pics_path, self.specifications, test_options)
Expand Down
3 changes: 2 additions & 1 deletion app/chip_tool/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
logger.info("Setting up chip_tool")
# Use test engine logger to log all events to test run.
self.chip_tool.logger = logger
await self.chip_tool.start_container(
await self.chip_tool.start_server(
self.test_type, self.config.dut_config.chip_tool_use_paa_certs
)

Expand Down Expand Up @@ -280,3 +280,4 @@
f"Received unknown prompt option for \
decommissioning step: {prompt_response.response}"
)

Check failure on line 283 in app/chip_tool/test_suite.py

View workflow job for this annotation

GitHub Actions / Flake8

app/chip_tool/test_suite.py#L283

Blank line at end of file (W391)
35 changes: 18 additions & 17 deletions app/tests/chip_tool/test_chip_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
) as mock_create_container, mock.patch.object(
target=chip_tool, attribute="start_chip_server"
) as mock_start_chip_server:
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

mock_create_container.assert_called_once_with(docker_image, ChipTool.run_parameters)
mock_start_chip_server.assert_awaited_once_with(test_type, False)
Expand Down Expand Up @@ -98,7 +98,7 @@
) as mock_create_container, mock.patch.object(
target=chip_tool, attribute="start_chip_server"
) as mock_start_chip_server:
await chip_tool.start_container(test_type, use_paa_certs=True)
await chip_tool.start_server(test_type, use_paa_certs=True)

mock_create_container.assert_called_once_with(docker_image, ChipTool.run_parameters)
mock_start_chip_server.assert_awaited_once_with(test_type, True)
Expand All @@ -120,7 +120,7 @@
) as mock_create_container, mock.patch.object(
target=chip_tool, attribute="start_chip_server"
) as mock_start_chip_server:
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

mock_create_container.assert_not_called()
mock_start_chip_server.assert_not_called()
Expand Down Expand Up @@ -359,8 +359,8 @@
), mock.patch.object(
target=chip_tool, attribute="start_chip_server"
):
await chip_tool.start_container(test_type)
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)
await chip_tool.start_server(test_type)

assert chip_tool._ChipTool__chip_tool_container is not None

Expand Down Expand Up @@ -403,7 +403,7 @@
), mock.patch.object(
target=chip_tool, attribute="start_chip_server"
):
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

await chip_tool.destroy_device()
await chip_tool.destroy_device()
Expand Down Expand Up @@ -452,7 +452,7 @@
target="app.chip_tool.chip_tool.subprocess.run",
return_value=CompletedProcess(expected_command, 0),
) as mock_run:
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

chip_tool.set_pics(pics)

Expand Down Expand Up @@ -505,7 +505,7 @@
target="app.chip_tool.chip_tool.exec_run_in_container",
return_value=mock_result,
) as mock_exec_run:
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

result = chip_tool.send_command(cmd, prefix=chip_tool_prefix)

Expand Down Expand Up @@ -548,7 +548,7 @@
target="app.chip_tool.chip_tool.exec_run_in_container",
return_value=mock_result,
) as mock_exec_run:
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

result = chip_tool.send_command(cmd, prefix=chip_tool_prefix)

Expand Down Expand Up @@ -592,7 +592,7 @@
target="app.chip_tool.chip_tool.WebSocketRunner.run",
return_value=True,
) as mock_run:
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

await chip_tool.run_test(
test_step_interface=TestRunnerHooks(),
Expand Down Expand Up @@ -649,7 +649,7 @@
target="app.chip_tool.chip_tool.WebSocketRunner.run",
return_value=True,
) as mock_run:
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

await chip_tool.run_test(
test_step_interface=TestRunnerHooks(),
Expand Down Expand Up @@ -700,7 +700,7 @@
target="app.chip_tool.chip_tool.WebSocketRunner.run",
return_value=True,
) as mock_run:
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

await chip_tool.run_test(
test_step_interface=TestRunnerHooks(),
Expand Down Expand Up @@ -752,7 +752,7 @@
target="app.chip_tool.chip_tool.WebSocketRunner.run",
return_value=True,
) as mock_run:
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

await chip_tool.run_test(
test_step_interface=TestRunnerHooks(),
Expand Down Expand Up @@ -803,7 +803,7 @@
target="app.chip_tool.chip_tool.WebSocketRunner.run",
return_value=True,
) as mock_run:
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

await chip_tool.run_test(
test_step_interface=TestRunnerHooks(),
Expand Down Expand Up @@ -862,7 +862,7 @@
attribute="send_websocket_command",
return_value='{"results": []}',
) as mock_send_websocket_command:
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

# Send on-network pairing command
result = await chip_tool.pairing_on_network(
Expand Down Expand Up @@ -913,7 +913,7 @@
attribute="send_websocket_command",
return_value='{"results": []}',
) as mock_send_websocket_command:
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

# Send BLE-WIFI pairing command
result = await chip_tool.pairing_ble_wifi(
Expand Down Expand Up @@ -968,7 +968,7 @@
return_value='{"results": []}',
# '{ "results": [{ "error": "FAILURE" }]
) as mock_send_websocket_command:
await chip_tool.start_container(test_type)
await chip_tool.start_server(test_type)

# Send BLE-THREAD pairing command
result = await chip_tool.pairing_ble_thread(
Expand All @@ -988,3 +988,4 @@
# clean up:
chip_tool._ChipTool__chip_tool_container = None
settings.CHIP_TOOL_TRACE = original_trace_setting_value

Check failure on line 991 in app/tests/chip_tool/test_chip_tool.py

View workflow job for this annotation

GitHub Actions / Flake8

app/tests/chip_tool/test_chip_tool.py#L991

Blank line at end of file (W391)
58 changes: 58 additions & 0 deletions app/tests/python_tests/test_python_folder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# Copyright (c) 2023 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# flake8: noqa
from pathlib import Path
from unittest import mock

from test_collections.sdk_tests.support.models.sdk_test_folder import SDKTestFolder

test_python_path = Path("/test/python")


def test_python_folder_version() -> None:
version_file_content = "python_test_version"

# We mock open to read version_file_content and Path exists to ignore that we're
# testing with a fake path
with mock.patch(
"test_collections.sdk_tests.support.models.sdk_test_folder.open",
new=mock.mock_open(read_data=version_file_content),
), mock.patch.object(target=Path, attribute="exists", return_value=True) as _:
python_test_folder = SDKTestFolder(test_python_path)

assert python_test_folder.version == version_file_content


def test_python_folder_version_missing() -> None:
expected_version = "Unknown"
with mock.patch.object(target=Path, attribute="exists", return_value=False) as _:
python_folder = SDKTestFolder(test_python_path)
assert python_folder.version == expected_version


def test_python_folder_filename_pattern() -> None:
"""Test SDKTestFolder will search for files with filename pattern."""
with mock.patch.object(target=Path, attribute="glob") as path_glob:
# Default file_name_pattern: *
python_folder = SDKTestFolder(test_python_path)
_ = python_folder.file_paths(extension=".py")
path_glob.assert_called_once_with("*.py")

path_glob.reset_mock()
pattern = "TC_*"
python_test_folder = SDKTestFolder(test_python_path, filename_pattern=pattern)
_ = python_test_folder.file_paths(extension=".py")
path_glob.assert_called_once_with(f"{pattern}.py")
Loading
Loading