Skip to content

Commit

Permalink
Reverted minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rquidute committed Nov 8, 2023
1 parent 91fdbf9 commit df0e129
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
111 changes: 111 additions & 0 deletions app/tests/python_tests/test_python_test_suite.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 0 additions & 1 deletion app/tests/yaml_tests/test_sdk_yaml_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 6 additions & 2 deletions app/tests/yaml_tests/test_yaml_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ 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


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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df0e129

Please sign in to comment.