Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
rquidute committed Nov 14, 2024
1 parent 1cd9918 commit a3438f5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
19 changes: 19 additions & 0 deletions app/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (c) 2024 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.
#
# isort: split - DO NOT MOVE THIS IMPORT, this should be before any app.*
from .sdk_container_mock import mock_instance

# isort: split
11 changes: 2 additions & 9 deletions app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
import contextlib
import sys
from importlib import import_module
from pathlib import Path
from typing import AsyncGenerator, Generator
from unittest import mock
from unittest.mock import AsyncMock, Mock, patch

import pytest
import pytest_asyncio
Expand All @@ -32,11 +30,6 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import Session, sessionmaker

# isort: split - DO NOT MOVE THIS IMPORT, this should be before any app.*
from .sdk_container_mock import mock_instance # Mock is already setup when this imports

# isort: split

from app.core.config import settings
from app.db.base_class import Base
from app.db.init_db import create_app_database
Expand Down Expand Up @@ -137,7 +130,7 @@ def block_on_serial_marker(request: pytest.FixtureRequest) -> Generator:


@contextlib.contextmanager

Check failure on line 132 in app/tests/conftest.py

View workflow job for this annotation

GitHub Actions / Mypy

app/tests/conftest.py#L132

Argument 1 to "contextmanager" has incompatible type "Callable[[], SDKContainer]"; expected "Callable[[], Iterator[<nothing>]]" [arg-type]
def use_real_sdk_container():
def use_real_sdk_container() -> SDKContainer:

Check failure on line 133 in app/tests/conftest.py

View workflow job for this annotation

GitHub Actions / Mypy

app/tests/conftest.py#L133

The return type of a generator function should be "Generator" or one of its supertypes [misc]
"""Context manager to temporarily use the real SDKContainer"""
# Store the mock module
mock_module = sys.modules["test_collections.matter.sdk_tests.support.sdk_container"]
Expand All @@ -159,7 +152,7 @@ def use_real_sdk_container():


@pytest.fixture
def real_sdk_container():
def real_sdk_container() -> SDKContainer:

Check failure on line 155 in app/tests/conftest.py

View workflow job for this annotation

GitHub Actions / Mypy

app/tests/conftest.py#L155

The return type of a generator function should be "Generator" or one of its supertypes [misc]
"""Use the real SDKContainer in a test"""
with use_real_sdk_container() as real_module:

Check failure on line 157 in app/tests/conftest.py

View workflow job for this annotation

GitHub Actions / Mypy

app/tests/conftest.py#L157

Need type annotation for "real_module" [var-annotated]
yield real_module.SDKContainer()
4 changes: 2 additions & 2 deletions app/tests/sdk_container_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ class SDKContainerRetrieveExitCodeError(Exception):

# Create mock SDKContainer class
class MockSDKContainer:
def __new__(cls, *args, **kwargs):
def __new__(cls, *args, **kwargs) -> None:

Check failure on line 63 in app/tests/sdk_container_mock.py

View workflow job for this annotation

GitHub Actions / Mypy

app/tests/sdk_container_mock.py#L63

"__new__" must return a class instance (got "None") [misc]

Check failure on line 63 in app/tests/sdk_container_mock.py

View workflow job for this annotation

GitHub Actions / Mypy

app/tests/sdk_container_mock.py#L63

Function is missing a type annotation for one or more arguments [no-untyped-def]
return mock_instance

Check failure on line 64 in app/tests/sdk_container_mock.py

View workflow job for this annotation

GitHub Actions / Mypy

app/tests/sdk_container_mock.py#L64

No return value expected [return-value]


# Store mock for access
sys.mock_sdk_container = mock_instance
sys.mock_sdk_container = mock_instance # type: ignore

# Create and setup mock module
mock_module = type(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ async def proccess_commands_sdk_container(

async def generate_python_test_json_file(
test_folder: SDKTestFolder = PYTHON_SCRIPTS_FOLDER,
json_output_file=COMPLETE_JSON_OUTPUT_FILE_FOLDER / "python_tests_info.json",
json_output_file: Path = COMPLETE_JSON_OUTPUT_FILE_FOLDER
/ "python_tests_info.json",
) -> None:
python_scripts_command_list = get_command_list(test_folder=test_folder)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
# type: ignore
# Ignore mypy type check for this file

from unittest import TestCase, mock
from unittest import mock

import pytest

from app.container_manager import container_manager
from app.tests.conftest import real_sdk_container
from app.tests.conftest import real_sdk_container # noqa: F401
from app.tests.utils.docker import make_fake_container
from test_collections.matter.config import matter_settings

from ..exec_run_in_container import ExecResultExtended
from ..sdk_container import SDKContainer, SDKContainerNotRunning
from ..sdk_container import SDKContainer


@pytest.mark.asyncio
Expand Down

0 comments on commit a3438f5

Please sign in to comment.