Skip to content

Commit

Permalink
Update some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ccruzagralopes committed Nov 30, 2023
1 parent 0a769fb commit 3939680
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 8 deletions.
5 changes: 2 additions & 3 deletions app/tests/chip_tool/test_chip_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ async def test_start_container_using_paa_certs() -> None:
@pytest.mark.asyncio
async def test_not_start_container_when_running() -> None:
chip_tool = ChipTool()
test_type = ChipToolTestType.CHIP_TOOL

with mock.patch.object(
target=chip_tool, attribute="is_running", return_value=True
Expand All @@ -120,7 +119,7 @@ async def test_not_start_container_when_running() -> None:
) as mock_create_container, mock.patch.object(
target=chip_tool, attribute="start_chip_server"
) as mock_start_chip_server:
await chip_tool.start_server(test_type)
await chip_tool.start_container()

mock_create_container.assert_not_called()
mock_start_chip_server.assert_not_called()
Expand Down Expand Up @@ -432,7 +431,7 @@ async def test_set_pics() -> None:
"PICS_USER_PROMPT=1"
)
expected_command = (
f"{SHELL_PATH} {SHELL_OPTION} \"echo '{expected_pics_data}\n' "
f"{SHELL_PATH} {SHELL_OPTION} \"echo '{expected_pics_data}' "
f'> {PICS_FILE_PATH}"'
)

Expand Down
79 changes: 74 additions & 5 deletions app/tests/python_tests/test_python_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

import pytest

from app.chip_tool.chip_tool import ChipToolTestType
from app.chip_tool.chip_tool import ChipTool
from app.models.test_suite_execution import TestSuiteExecution
from app.schemas import PICS
from app.test_engine.logger import test_engine_logger
from app.tests.utils.test_pics_data import create_random_pics
from test_collections.sdk_tests.support.python_testing.models.test_suite import (
PythonTestSuite,
SuiteType,
Expand Down Expand Up @@ -59,6 +61,8 @@ def test_python_test_suite_python_version() -> None:

@pytest.mark.asyncio
async def test_suite_setup_log_python_version() -> None:
chip_tool: ChipTool = ChipTool()

"""Test that test suite python version is logged to test engine logger in setup."""
for type in list(SuiteType):
python_test_version = "best_version"
Expand All @@ -69,17 +73,82 @@ async def test_suite_setup_log_python_version() -> None:

suite_instance = suite_class(TestSuiteExecution())

# We're patching ChipToolSuite.setup to avoid starting chip-tool
with mock.patch.object(
target=test_engine_logger, attribute="info"
) as logger_info, mock.patch(
"app.chip_tool.test_suite.ChipToolSuite.setup"
) as _:
) as logger_info, mock.patch.object(
target=chip_tool, attribute="start_container"
), mock.patch(
target="test_collections.sdk_tests.support.python_testing.models.test_suite"
".PythonTestSuite.pics",
new_callable=PICS,
):
await suite_instance.setup()
logger_info.assert_called()
logger_info.assert_any_call(f"Python Test Version: {python_test_version}")


@pytest.mark.asyncio
async def test_suite_setup_without_pics() -> None:
chip_tool: ChipTool = ChipTool()

"""Test that test suite python version is logged to test engine logger in setup."""
for type in list(SuiteType):
python_test_version = "best_version"
# Create a subclass of PythonTestSuite
suite_class: Type[PythonTestSuite] = PythonTestSuite.class_factory(
suite_type=type, name="SomeSuite", python_test_version=python_test_version
)

suite_instance = suite_class(TestSuiteExecution())

with mock.patch(
"app.chip_tool.test_suite.ChipToolSuite.setup"
), mock.patch.object(target=chip_tool, attribute="start_container"), mock.patch(
target="test_collections.sdk_tests.support.python_testing.models.test_suite"
".PythonTestSuite.pics",
new_callable=PICS,
), mock.patch.object(
target=chip_tool, attribute="set_pics"
) as mock_set_pics, mock.patch.object(
target=chip_tool, attribute="reset_pics_state"
) as mock_reset_pics_state:
await suite_instance.setup()

mock_set_pics.assert_not_called()
mock_reset_pics_state.assert_called_once()


@pytest.mark.asyncio
async def test_suite_setup_with_pics() -> None:
chip_tool: ChipTool = ChipTool()

"""Test that test suite python version is logged to test engine logger in setup."""
for type in list(SuiteType):
python_test_version = "best_version"
# Create a subclass of PythonTestSuite
suite_class: Type[PythonTestSuite] = PythonTestSuite.class_factory(
suite_type=type, name="SomeSuite", python_test_version=python_test_version
)

suite_instance = suite_class(TestSuiteExecution())

with mock.patch(
"app.chip_tool.test_suite.ChipToolSuite.setup"
), mock.patch.object(target=chip_tool, attribute="start_container"), mock.patch(
target="test_collections.sdk_tests.support.python_testing.models.test_suite"
".PythonTestSuite.pics",
new_callable=create_random_pics,
), mock.patch.object(
target=chip_tool, attribute="set_pics"
) as mock_set_pics, mock.patch.object(
target=chip_tool, attribute="reset_pics_state"
) as mock_reset_pics_state:
await suite_instance.setup()

mock_set_pics.assert_called_once()
mock_reset_pics_state.assert_not_called()


@pytest.mark.asyncio
async def test_chip_tool_suite_setup() -> None:
"""Test that PythonTestSuite.setup is called when PythonChipToolsSuite.setup is called.
Expand Down

0 comments on commit 3939680

Please sign in to comment.