Skip to content

Commit

Permalink
Move chiptool test code under test_collections
Browse files Browse the repository at this point in the history
  • Loading branch information
ccruzagralopes committed Nov 10, 2023
1 parent 03052ff commit dbbbdf9
Show file tree
Hide file tree
Showing 28 changed files with 76 additions and 64 deletions.
4 changes: 3 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[run]
omit = */app/tests/*
omit =
*/app/tests/*
*/test_collections/sdk_tests/support/tests/*
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"python.testing.pytestPath": "/usr/local/bin/pytest",
"python.testing.pytestArgs": [
"app/tests",
"test_collections/sdk_tests/support/tests",
"--no-cov"
],
"python.linting.ignorePatterns": [
Expand Down
44 changes: 20 additions & 24 deletions scripts/test-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,39 @@
set -e
set -x

#
# 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.


#
# 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.

#!/bin/sh
for arg in "$@"
do
for arg in "$@"; do
case $arg in
--run-platform-dependant)
--run-platform-dependant)
RUN_ALL_TESTS=1
shift # Remove --run-all from processing
;;
*)
*)
OTHER_ARGUMENTS+=("$1")
shift # Remove generic argument from processing
;;
esac
done

if [[ $RUN_ALL_TESTS -eq 1 ]]
then
if [[ $RUN_ALL_TESTS -eq 1 ]]; then
echo "Running all tests"
pytest --cov-config=.coveragerc --cov=app --cov=test_collections --cov-report=term-missing app/tests "${@}"
pytest --cov-config=.coveragerc --cov=app --cov=test_collections --cov-report=term-missing app/tests test_collections/sdk_tests/support/tests "${@}"
else
echo "Skipping platform dependant tests"
pytest --cov-config=.coveragerc --cov=app --cov=test_collections --cov-report=term-missing --ignore=app/tests/platform_dependent_tests app/tests "${@}"
pytest --cov-config=.coveragerc --cov=app --cov=test_collections --cov-report=term-missing --ignore=app/tests/platform_dependent_tests app/tests test_collections/sdk_tests/support/tests "${@}"
fi
4 changes: 2 additions & 2 deletions test_collections/sdk_tests/support/chip_tool/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from matter_yamltests.hooks import TestParserHooks, TestRunnerHooks
from matter_yamltests.parser import PostProcessResponseResult, TestStep

from test_collections.sdk_tests.support.chip_tool import ChipTool
from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType
from app.models import TestStateEnum
from app.models.test_case_execution import TestCaseExecution
from app.test_engine.logger import CHIP_LOG_FORMAT, CHIPTOOL_LEVEL, test_engine_logger
Expand All @@ -36,6 +34,8 @@
from app.user_prompt_support.uploaded_file_support import UploadFile
from app.user_prompt_support.user_prompt_manager import user_prompt_manager
from app.user_prompt_support.user_prompt_support import UserPromptSupport
from test_collections.sdk_tests.support.chip_tool import ChipTool
from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType

CHIP_TOOL_DEFAULT_PROMPT_TIMEOUT_S = 60 # seconds
OUTCOME_TIMEOUT_S = 60 * 10 # Seconds
Expand Down
6 changes: 3 additions & 3 deletions test_collections/sdk_tests/support/chip_tool/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#
from typing import Optional

from test_collections.sdk_tests.support.chip_tool import ChipTool
from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType
from test_collections.sdk_tests.support.chip_tool.test_case import PromptOption
from app.models import TestSuiteExecution
from app.otbr_manager.otbr_manager import ThreadBorderRouter
from app.schemas.test_environment_config import (
Expand All @@ -29,6 +26,9 @@
from app.test_engine.models import TestSuite
from app.user_prompt_support.prompt_request import OptionsSelectPromptRequest
from app.user_prompt_support.user_prompt_support import UserPromptSupport
from test_collections.sdk_tests.support.chip_tool import ChipTool
from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType
from test_collections.sdk_tests.support.chip_tool.test_case import PromptOption

CHIP_APP_PAIRING_CODE = "CHIP:SVR: Manual pairing code:"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
from matter_yamltests.parser_builder import TestParserBuilderConfig
from matter_yamltests.runner import TestRunnerConfig

from app.container_manager import container_manager
from app.core.config import settings
from app.schemas.pics import PICSError
from app.tests.utils.docker import make_fake_container
from app.tests.utils.test_pics_data import create_random_pics
from test_collections.sdk_tests.support.chip_tool import ChipTool
from test_collections.sdk_tests.support.chip_tool.chip_tool import (
CHIP_APP_EXE,
Expand All @@ -45,11 +50,6 @@
from test_collections.sdk_tests.support.chip_tool.exec_run_in_container import (
ExecResultExtended,
)
from app.container_manager import container_manager
from app.core.config import settings
from app.schemas.pics import PICSError
from app.tests.utils.docker import make_fake_container
from app.tests.utils.test_pics_data import create_random_pics


@pytest.mark.asyncio
Expand All @@ -65,7 +65,8 @@ async def test_start_container() -> None:
), mock.patch.object(
target=container_manager, attribute="get_container", return_value=None
), mock.patch(
target="test_collections.sdk_tests.support.chip_tool.chip_tool.backend_container"
target="test_collections.sdk_tests.support.chip_tool.chip_tool."
"backend_container"
), mock.patch.object(
target=container_manager, attribute="create_container"
) as mock_create_container, mock.patch.object(
Expand Down Expand Up @@ -94,7 +95,8 @@ async def test_start_container_using_paa_certs() -> None:
), mock.patch.object(
target=container_manager, attribute="get_container", return_value=None
), mock.patch(
target="test_collections.sdk_tests.support.chip_tool.chip_tool.backend_container"
target="test_collections.sdk_tests.support.chip_tool.chip_tool."
"backend_container"
), mock.patch.object(
target=container_manager, attribute="create_container"
) as mock_create_container, mock.patch.object(
Expand Down Expand Up @@ -395,7 +397,8 @@ async def test_destroy_container_once() -> None:
), mock.patch.object(
target=container_manager, attribute="get_container", return_value=None
), mock.patch(
target="test_collections.sdk_tests.support.chip_tool.chip_tool.backend_container"
target="test_collections.sdk_tests.support.chip_tool.chip_tool."
"backend_container"
), mock.patch.object(
target=container_manager, attribute="destroy"
) as mock_destroy, mock.patch.object(
Expand Down Expand Up @@ -504,7 +507,8 @@ async def test_send_command_default_prefix() -> None:
), mock.patch.object(
target=chip_tool, attribute="start_chip_server"
), mock.patch(
target="test_collections.sdk_tests.support.chip_tool.chip_tool.exec_run_in_container",
target="test_collections.sdk_tests.support.chip_tool.chip_tool."
"exec_run_in_container",
return_value=mock_result,
) as mock_exec_run:
await chip_tool.start_container(test_type)
Expand Down Expand Up @@ -547,7 +551,8 @@ async def test_send_command_custom_prefix() -> None:
), mock.patch.object(
target=chip_tool, attribute="start_chip_server"
), mock.patch(
target="test_collections.sdk_tests.support.chip_tool.chip_tool.exec_run_in_container",
target="test_collections.sdk_tests.support.chip_tool.chip_tool."
"exec_run_in_container",
return_value=mock_result,
) as mock_exec_run:
await chip_tool.start_container(test_type)
Expand Down Expand Up @@ -588,7 +593,8 @@ async def test_run_test_default_config() -> None:
), mock.patch.object(
target=chip_tool, attribute="start_chip_server"
), mock.patch(
target="test_collections.sdk_tests.support.chip_tool.chip_tool.WebSocketRunner.run",
target="test_collections.sdk_tests.support.chip_tool.chip_tool.WebSocketRunner."
"run",
return_value=True,
) as mock_run:
await chip_tool.start_container(test_type)
Expand Down Expand Up @@ -642,7 +648,8 @@ async def test_run_test_custom_timeout() -> None:
), mock.patch.object(
target=chip_tool, attribute="start_chip_server"
), mock.patch(
target="test_collections.sdk_tests.support.chip_tool.chip_tool.WebSocketRunner.run",
target="test_collections.sdk_tests.support.chip_tool.chip_tool.WebSocketRunner."
"run",
return_value=True,
) as mock_run:
await chip_tool.start_container(test_type)
Expand Down Expand Up @@ -690,7 +697,8 @@ async def test_run_test_with_custom_parameter() -> None:
), mock.patch.object(
target=chip_tool, attribute="start_chip_server"
), mock.patch(
target="test_collections.sdk_tests.support.chip_tool.chip_tool.WebSocketRunner.run",
target="test_collections.sdk_tests.support.chip_tool.chip_tool.WebSocketRunner."
"run",
return_value=True,
) as mock_run:
await chip_tool.start_container(test_type)
Expand Down Expand Up @@ -739,7 +747,8 @@ async def test_run_test_with_endpoint_parameter() -> None:
), mock.patch.object(
target=chip_tool, attribute="start_chip_server"
), mock.patch(
target="test_collections.sdk_tests.support.chip_tool.chip_tool.WebSocketRunner.run",
target="test_collections.sdk_tests.support.chip_tool.chip_tool.WebSocketRunner."
"run",
return_value=True,
) as mock_run:
await chip_tool.start_container(test_type)
Expand Down Expand Up @@ -787,7 +796,8 @@ async def test_run_test_with_nodeID_and_cluster_parameters() -> None:
), mock.patch.object(
target=chip_tool, attribute="start_chip_server"
), mock.patch(
target="test_collections.sdk_tests.support.chip_tool.chip_tool.WebSocketRunner.run",
target="test_collections.sdk_tests.support.chip_tool.chip_tool.WebSocketRunner."
"run",
return_value=True,
) as mock_run:
await chip_tool.start_container(test_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#
from typing import Generator

from app.tests.utils.docker import make_fake_container
from test_collections.sdk_tests.support.chip_tool.exec_run_in_container import (
exec_run_in_container,
)
from app.tests.utils.docker import make_fake_container


def test_exec_run_in_container_not_stream() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

import pytest

from app.models.test_suite_execution import TestSuiteExecution
from app.user_prompt_support.constants import UserResponseStatusEnum
from app.user_prompt_support.prompt_response import PromptResponse
from test_collections.sdk_tests.support.chip_tool.test_case import PromptOption
from test_collections.sdk_tests.support.chip_tool.test_suite import (
ChipToolSuite,
DUTCommissioningError,
SuiteSetupError,
)
from app.models.test_suite_execution import TestSuiteExecution
from app.user_prompt_support.constants import UserResponseStatusEnum
from app.user_prompt_support.prompt_response import PromptResponse

RETRY_PROMPT_RESPONSE = PromptResponse(
response=PromptOption.RETRY, status_code=UserResponseStatusEnum.OKAY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

import pytest

from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType
from test_collections.sdk_tests.support.chip_tool.test_case import TestError
from app.models.test_case_execution import TestCaseExecution
from app.test_engine.logger import test_engine_logger
from app.test_engine.models.manual_test_case import ManualVerificationTestStep
from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType
from test_collections.sdk_tests.support.chip_tool.test_case import TestError
from test_collections.sdk_tests.support.yaml_tests.models import YamlTestCase
from test_collections.sdk_tests.support.yaml_tests.models.test_case import (
YamlChipToolTestCase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import pytest

from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType
from app.models.test_suite_execution import TestSuiteExecution
from app.test_engine.logger import test_engine_logger
from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType
from test_collections.sdk_tests.support.yaml_tests.models.test_suite import (
ChipToolYamlTestSuite,
ManualYamlTestSuite,
Expand Down Expand Up @@ -159,7 +159,8 @@ async def test_chip_tool_suite_setup() -> None:
"test_collections.sdk_tests.support.yaml_tests.models."
"test_suite.YamlTestSuite.setup"
) as yaml_suite_setup, mock.patch(
"test_collections.sdk_tests.support.chip_tool.test_suite.ChipToolSuite.setup"
"test_collections.sdk_tests.support.chip_tool.test_suite.ChipToolSuite."
"setup"
) as chip_tool_suite_setup:
await suite_instance.setup()
yaml_suite_setup.assert_called_once()
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import pytest
from pydantic.error_wrappers import ValidationError

from app.tests.yaml_tests.test_test_case import yaml_test_instance
from test_collections.sdk_tests.support.tests.yaml_tests.test_test_case import (
yaml_test_instance,
)
from test_collections.sdk_tests.support.yaml_tests.models.yaml_test_models import (
YamlTestStep,
YamlTestType,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
import re
from typing import Any, Type, TypeVar

from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType
from test_collections.sdk_tests.support.chip_tool.test_case import (
ChipToolManualPromptTest,
ChipToolTest,
)
from app.test_engine.logger import test_engine_logger
from app.test_engine.models import (
ManualTestCase,
ManualVerificationTestStep,
TestCase,
TestStep,
)
from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType
from test_collections.sdk_tests.support.chip_tool.test_case import (
ChipToolManualPromptTest,
ChipToolTest,
)

from .yaml_test_models import YamlTest, YamlTestStep, YamlTestType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from enum import Enum
from typing import Type, TypeVar

from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType
from test_collections.sdk_tests.support.chip_tool.test_suite import ChipToolSuite
from app.test_engine.logger import test_engine_logger as logger
from app.test_engine.models import TestSuite
from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType
from test_collections.sdk_tests.support.chip_tool.test_suite import ChipToolSuite


class YamlTestSuiteFactoryError(Exception):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType
from test_collections.sdk_tests.support.chip_tool.test_case import ChipToolTest
from app.default_environment_config import default_environment_config
from app.schemas.test_environment_config import TestEnvironmentConfig
from app.test_engine.logger import test_engine_logger as logger
from app.test_engine.models import TestStep
from test_collections.sdk_tests.support.chip_tool.chip_tool import ChipToolTestType
from test_collections.sdk_tests.support.chip_tool.test_case import ChipToolTest


class TCTRChipToolLogParsing(ChipToolTest):
Expand Down

0 comments on commit dbbbdf9

Please sign in to comment.