diff --git a/app/core/config.py b/app/core/config.py index c6dd5ee5..ce41af1a 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -90,7 +90,7 @@ def get_emails_enabled(cls, v: bool, values: Dict[str, Any]) -> bool: # Logging LOGGING_PATH: str = "./logs" LOGGING_FILENAME: str = "{time:YYYY-MM-DD}.log" - LOGGING_LEVEL: str = "info" + LOGGING_LEVEL: str = "debug" LOGGING_ROTATION: str = "20 days" LOGGING_RETENTION: str = "1 months" LOGGING_FORMAT: str = ( diff --git a/app/tests/python_tests/test_python_test_suite.py b/app/tests/python_tests/test_python_test_suite.py new file mode 100644 index 00000000..cd45323e --- /dev/null +++ b/app/tests/python_tests/test_python_test_suite.py @@ -0,0 +1,111 @@ +# +# 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. +# +from typing import Type +from unittest import mock + +import pytest + +from app.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.python_testing.models.test_suite import ( + ChipToolPythonTestSuite, + SuiteType, + PythonTestSuite, +) + + +def test_python_suite_class_factory_name() -> None: + """Test that test suite name is set.""" + name = "AnotherTestSuite" + + # Create a subclass of PythonTestSuite + suite_class: Type[PythonTestSuite] = PythonTestSuite.class_factory( + suite_type=SuiteType.AUTOMATED, name=name, python_test_version="version" + ) + + assert suite_class.__name__ == name + assert suite_class.public_id() == name + assert suite_class.metadata["title"] == name + assert suite_class.metadata["description"] == name + + +def test_python_test_suite_python_version() -> None: + """Test that test suite python version is set correctly in class factory.""" + python_test_version = "best_version" + # Create a subclass of PythonTestSuite + suite_class: Type[PythonTestSuite] = PythonTestSuite.class_factory( + suite_type=SuiteType.AUTOMATED, name="SomeSuite", python_test_version=python_test_version + ) + + assert suite_class.python_test_version == python_test_version + + +def test_automated_suite_subclass() -> None: + """Test that for suite type automated class factory creates a subclass of + ChipToolPythonTestSuite, and that test_type is set to CHIP_TOOL""" + type = SuiteType.AUTOMATED + # Create a subclass of PythonTestSuite + suite_class: Type[PythonTestSuite] = PythonTestSuite.class_factory( + suite_type=type, name="SomeSuite", python_test_version="some_version" + ) + assert issubclass(suite_class, ChipToolPythonTestSuite) + assert suite_class.test_type == ChipToolTestType.PYTHON_TEST + + +@pytest.mark.asyncio +async def test_suite_setup_log_python_version() -> None: + """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()) + + # 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 _: + 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_chip_tool_suite_setup() -> None: + """Test that both PythonTestSuite.setup and ChipToolSuite.setup are called when + PythonChipToolsSuite.setup is called. We do this as PythonChipToolsSuite inherits from + both PythonTestSuite and ChipToolSuite.""" + + suite_class: Type[PythonTestSuite] = PythonTestSuite.class_factory( + suite_type=SuiteType.AUTOMATED, name="SomeSuite", python_test_version="Some version" + ) + + suite_instance = suite_class(TestSuiteExecution()) + + with mock.patch( + "test_collections.sdk_tests.support.python_testing.models.test_suite.PythonTestSuite.setup" + ) as python_suite_setup, mock.patch( + "app.chip_tool.test_suite.ChipToolSuite.setup" + ) as chip_tool_suite_setup: + await suite_instance.setup() + python_suite_setup.assert_called_once() + chip_tool_suite_setup.assert_called_once() diff --git a/app/tests/yaml_tests/test_sdk_yaml_collection.py b/app/tests/yaml_tests/test_sdk_yaml_collection.py index db81d4cc..d5891120 100644 --- a/app/tests/yaml_tests/test_sdk_yaml_collection.py +++ b/app/tests/yaml_tests/test_sdk_yaml_collection.py @@ -34,7 +34,6 @@ VERSION_FILE_FILENAME = ".version" VERSION_FILE_PATH = Path("/app/backend/test_collections/sdk_tests/sdk_checkout/") - @pytest.fixture def yaml_collection() -> YamlCollectionDeclaration: test_sdk_yaml_path = Path(__file__).parent / "test_yamls" diff --git a/app/tests/yaml_tests/test_yaml_folder.py b/app/tests/yaml_tests/test_yaml_folder.py index 65a5012e..81f77273 100644 --- a/app/tests/yaml_tests/test_yaml_folder.py +++ b/app/tests/yaml_tests/test_yaml_folder.py @@ -31,7 +31,9 @@ def test_yaml_folder_version() -> None: with mock.patch( "test_collections.sdk_tests.support.yaml_tests.models.yaml_test_folder.open", new=mock.mock_open(read_data=version_file_content), - ), mock.patch.object(target=Path, attribute="exists", return_value=True) as _: + ), mock.patch.object( + target=Path, attribute="exists", return_value=True + ) as _: yaml_folder = YamlTestFolder(test_yaml_path) assert yaml_folder.version == version_file_content @@ -39,7 +41,9 @@ def test_yaml_folder_version() -> None: def test_yaml_folder_version_missing() -> None: expected_version = "Unknown" - with mock.patch.object(target=Path, attribute="exists", return_value=False) as _: + with mock.patch.object( + target=Path, attribute="exists", return_value=False + ) as _: yaml_folder = YamlTestFolder(test_yaml_path) assert yaml_folder.version == expected_version diff --git a/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py b/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py index ebc35e8d..517977ce 100644 --- a/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py +++ b/test_collections/sdk_tests/support/yaml_tests/sdk_yaml_tests.py @@ -31,9 +31,8 @@ ### # This file hosts logic load and parse YAML test-cases, located in -# `test_collections/sdk_tests/sdk_checkout/yaml_tests/yaml/sdk`. -# The `sdk` sub-folder here is automatically maintained using the -# `test_collections/sdk_tests/fetch_sdk_tests_and_runner.sh` script. +# `test_collections/yaml_tests/yaml/sdk`. The `sdk` sub-folder here is automatically +# maintained using the `scripts/fetch_sdk_yaml_tests_and_runner.sh` script. # # The YAML Tests are organized into 3 Test Suites: # - Automated and Semi-Automated using Chip-Tool