From 48ad49bba93b5c03b0c7f87a397140d74504639d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20M=C3=B8ller?= Date: Wed, 8 Nov 2023 13:11:57 -0800 Subject: [PATCH] Enable github workflows for main branch (#17) * Enable github workflows for main branch * Ignore Dockerfile * mypy: ignore python_testing in sdk_collection * minor linting issues fixed * ignore .devcontainer in spell checker * move .env file back in root * Update reference to fetch_sdk_tests_and_runner.sh * Use `pull_request_target` event to support forks --- .devcontainer/docker-compose.yml | 4 ++-- .devcontainer/.env => .env | 0 .github/workflows/python-lint.yml | 10 ++++------ .github/workflows/spell-check.yml | 6 +++--- .github/workflows/unittests.yml | 18 +++++++++--------- app/chip_tool/chip_tool.py | 4 +++- app/test_engine/models/manual_test_case.py | 7 +++++-- .../yaml_tests/test_sdk_yaml_collection.py | 1 + app/tests/yaml_tests/test_test_declarations.py | 6 ++++-- app/tests/yaml_tests/test_test_suite.py | 9 ++++++--- app/tests/yaml_tests/test_yaml_folder.py | 8 ++------ cspell.json | 5 +++-- mypy.ini | 3 ++- test_collections/sdk_tests/__init__.py | 2 +- .../sdk_tests/support/yaml_tests/__init__.py | 6 ++++-- .../yaml_tests/models/yaml_test_folder.py | 1 + .../support/yaml_tests/sdk_yaml_tests.py | 5 +++-- 17 files changed, 53 insertions(+), 42 deletions(-) rename .devcontainer/.env => .env (100%) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index ce61ab79..e5575eeb 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -59,7 +59,7 @@ services: volumes: - app-db-data:/var/lib/postgresql/data/pgdata env_file: - - .env + - ../.env environment: - PGDATA=/var/lib/postgresql/data/pgdata deploy: @@ -74,7 +74,7 @@ services: depends_on: - db env_file: - - .env + - ../.env environment: - SERVER_NAME=${DOMAIN?Variable not set} - SERVER_HOST=https://${DOMAIN?Variable not set} diff --git a/.devcontainer/.env b/.env similarity index 100% rename from .devcontainer/.env rename to .env diff --git a/.github/workflows/python-lint.yml b/.github/workflows/python-lint.yml index 024a5bfa..b7de53f3 100644 --- a/.github/workflows/python-lint.yml +++ b/.github/workflows/python-lint.yml @@ -1,13 +1,12 @@ name: Python Linting on: - pull_request: - branches: - - develop - - "release/**" + pull_request_target: + types: [opened, synchronize, reopened] push: branches: - develop + - main - "release/**" jobs: @@ -40,9 +39,8 @@ jobs: types-pyyaml==6.0.12.10 types-retry==0.9.9.4 - name: Run linters - uses: wearerequired/lint-action@v1 + uses: wearerequired/lint-action@v2 with: - github_token: ${{ secrets.github_token }} # Enable linters black: true flake8: true diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index b5b44322..5089c57b 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -1,11 +1,11 @@ name: "Check spelling" on: # rebuild any PRs and main branch changes - pull_request: - branches: - - develop + pull_request_target: + types: [opened, synchronize, reopened] push: branches: - develop + - main jobs: spellcheck: # run the action runs-on: ubuntu-latest diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index abe196fc..418f344d 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -1,12 +1,12 @@ name: Unit Tests on: - pull_request: - branches: - - develop + pull_request_target: + types: [opened, synchronize, reopened] push: branches: - develop + - main jobs: backend-tests: @@ -39,15 +39,15 @@ jobs: - name: Load .env file to job environent uses: cardinalby/export-env-action@v2 with: - envFile: '.env' - + envFile: ".env" + - name: Install poetry run: pipx install poetry - + - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: "3.10" cache: poetry cache-dependency-path: poetry.lock - name: Set Poetry environment @@ -63,7 +63,7 @@ jobs: - name: Fetch yaml tests and runner run: | source $(poetry env info --path)/bin/activate - ./scripts/fetch_sdk_yaml_tests_and_runner.sh + ./test_collections/sdk_tests/fetch_sdk_tests_and_runner.sh env: SERVER_NAME: localhost SERVER_HOST: http://localhost @@ -76,4 +76,4 @@ jobs: POSTGRES_PASSWORD: postgres POSTGRES_DB: postgres SERVER_NAME: localhost - SERVER_HOST: http://localhost \ No newline at end of file + SERVER_HOST: http://localhost diff --git a/app/chip_tool/chip_tool.py b/app/chip_tool/chip_tool.py index 9a04b571..b6e8d4f2 100644 --- a/app/chip_tool/chip_tool.py +++ b/app/chip_tool/chip_tool.py @@ -99,7 +99,9 @@ # Websocket runner BACKEND_ROOT = Path(__file__).parents[2] -TEST_COLLECTION_SDK_CHECKOUT_PATH = BACKEND_ROOT / Path("test_collections/sdk_tests/sdk_checkout/") +TEST_COLLECTION_SDK_CHECKOUT_PATH = BACKEND_ROOT / Path( + "test_collections/sdk_tests/sdk_checkout/" +) YAML_TESTS_PATH_BASE = TEST_COLLECTION_SDK_CHECKOUT_PATH / Path("yaml_tests/") YAML_TESTS_PATH = YAML_TESTS_PATH_BASE / Path("yaml/sdk") XML_SPEC_DEFINITION_PATH = TEST_COLLECTION_SDK_CHECKOUT_PATH / Path( diff --git a/app/test_engine/models/manual_test_case.py b/app/test_engine/models/manual_test_case.py index 3e2b0bae..91a4b467 100644 --- a/app/test_engine/models/manual_test_case.py +++ b/app/test_engine/models/manual_test_case.py @@ -156,8 +156,11 @@ def handle_uploaded_file(self, file: UploadFile) -> None: try: logger.info(line.decode("utf-8").strip()) except UnicodeDecodeError: - logger.warning("WARNING: The following line contained invalid UTF-8. Some content was replaced with: �") - logger.info(line.decode("utf-8", errors='replace').strip()) + logger.warning( + "WARNING: The following line contained invalid UTF-8." + " Some content was replaced with: �" + ) + logger.info(line.decode("utf-8", errors="replace").strip()) logger.info("---- End of Manual Log ----") diff --git a/app/tests/yaml_tests/test_sdk_yaml_collection.py b/app/tests/yaml_tests/test_sdk_yaml_collection.py index d5891120..db81d4cc 100644 --- a/app/tests/yaml_tests/test_sdk_yaml_collection.py +++ b/app/tests/yaml_tests/test_sdk_yaml_collection.py @@ -34,6 +34,7 @@ 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_test_declarations.py b/app/tests/yaml_tests/test_test_declarations.py index 631ff514..7aa8ce5e 100644 --- a/app/tests/yaml_tests/test_test_declarations.py +++ b/app/tests/yaml_tests/test_test_declarations.py @@ -31,7 +31,8 @@ def test_yaml_suite_declaration() -> None: version = "SomeVersionStr" with mock.patch( - "test_collections.sdk_tests.support.yaml_tests.models.test_suite.YamlTestSuite.class_factory" + "test_collections.sdk_tests.support.yaml_tests.models." + "test_suite.YamlTestSuite.class_factory" ) as class_factory, mock.patch( "app.test_engine.models.test_declarations.TestSuiteDeclaration.__init__" ) as declaration_init: @@ -46,7 +47,8 @@ def test_yaml_case_declaration() -> None: test = YamlTest(name="TestTest", config={}, tests=[]) version = "SomeVersionStr" with mock.patch( - "test_collections.sdk_tests.support.yaml_tests.models.test_case.YamlTestCase.class_factory" + "test_collections.sdk_tests.support.yaml_tests.models." + "test_case.YamlTestCase.class_factory" ) as class_factory, mock.patch( "app.test_engine.models.test_declarations.TestCaseDeclaration.__init__" ) as declaration_init: diff --git a/app/tests/yaml_tests/test_test_suite.py b/app/tests/yaml_tests/test_test_suite.py index fd569bc6..7d99cc46 100644 --- a/app/tests/yaml_tests/test_test_suite.py +++ b/app/tests/yaml_tests/test_test_suite.py @@ -127,9 +127,11 @@ async def test_manual_suite_setup_cleanup() -> None: with mock.patch.object( target=test_engine_logger, attribute="info" ) as logger_info, mock.patch( - "test_collections.sdk_tests.support.yaml_tests.models.test_suite.YamlTestSuite.setup" + "test_collections.sdk_tests.support.yaml_tests.models." + "test_suite.YamlTestSuite.setup" ) as _, mock.patch( - "test_collections.sdk_tests.support.yaml_tests.models.test_suite.YamlTestSuite.cleanup" + "test_collections.sdk_tests.support.yaml_tests.models." + "test_suite.YamlTestSuite.cleanup" ) as _: await suite_instance.setup() logger_info.assert_called_once() @@ -154,7 +156,8 @@ async def test_chip_tool_suite_setup() -> None: suite_instance = suite_class(TestSuiteExecution()) with mock.patch( - "test_collections.sdk_tests.support.yaml_tests.models.test_suite.YamlTestSuite.setup" + "test_collections.sdk_tests.support.yaml_tests.models." + "test_suite.YamlTestSuite.setup" ) as yaml_suite_setup, mock.patch( "app.chip_tool.test_suite.ChipToolSuite.setup" ) as chip_tool_suite_setup: diff --git a/app/tests/yaml_tests/test_yaml_folder.py b/app/tests/yaml_tests/test_yaml_folder.py index 81f77273..65a5012e 100644 --- a/app/tests/yaml_tests/test_yaml_folder.py +++ b/app/tests/yaml_tests/test_yaml_folder.py @@ -31,9 +31,7 @@ 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 @@ -41,9 +39,7 @@ 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/cspell.json b/cspell.json index f2d4a424..28ac7526 100644 --- a/cspell.json +++ b/cspell.json @@ -99,11 +99,12 @@ "*.ini", "*.toml", "docker-compose*", - "*.dockerfile", + "Dockerfile", "*.pyc", ".vscode/*", "test_collections/sdk_tests/sdk_checkout", - "sdk_patch" + "sdk_patch", + ".devcontainer" ], "enableFiletypes": [ "shellscript" diff --git a/mypy.ini b/mypy.ini index 8a0c7560..f05e8b68 100644 --- a/mypy.ini +++ b/mypy.ini @@ -31,7 +31,8 @@ exclude = (?x)( ^test_collections\/sdk_tests\/sdk_checkout\/ ( sdk_runner | - yaml_tests\/yaml\/sdk + yaml_tests\/yaml\/sdk | + python_testing ) \/.*\.py$ ) diff --git a/test_collections/sdk_tests/__init__.py b/test_collections/sdk_tests/__init__.py index 6df5f6d8..54e59ed3 100644 --- a/test_collections/sdk_tests/__init__.py +++ b/test_collections/sdk_tests/__init__.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .support.yaml_tests import sdk_collection, custom_collection +from .support.yaml_tests import custom_collection, sdk_collection diff --git a/test_collections/sdk_tests/support/yaml_tests/__init__.py b/test_collections/sdk_tests/support/yaml_tests/__init__.py index c98d927c..c8da4ff9 100644 --- a/test_collections/sdk_tests/support/yaml_tests/__init__.py +++ b/test_collections/sdk_tests/support/yaml_tests/__init__.py @@ -13,12 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import Optional + from app.test_engine.models.test_declarations import TestCollectionDeclaration -from .sdk_yaml_tests import sdk_yaml_test_collection, custom_yaml_test_collection +from .sdk_yaml_tests import custom_yaml_test_collection, sdk_yaml_test_collection # Test engine will auto load TestCollectionDeclarations declared inside the package # initializer sdk_collection: TestCollectionDeclaration = sdk_yaml_test_collection() -custom_collection: TestCollectionDeclaration = custom_yaml_test_collection() \ No newline at end of file +custom_collection: Optional[TestCollectionDeclaration] = custom_yaml_test_collection() diff --git a/test_collections/sdk_tests/support/yaml_tests/models/yaml_test_folder.py b/test_collections/sdk_tests/support/yaml_tests/models/yaml_test_folder.py index a9aaa313..b8362b43 100644 --- a/test_collections/sdk_tests/support/yaml_tests/models/yaml_test_folder.py +++ b/test_collections/sdk_tests/support/yaml_tests/models/yaml_test_folder.py @@ -21,6 +21,7 @@ VERSION_FILE_FILENAME = ".version" + class YamlTestFolder: """Representing a folder with Test YAML files. 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 517977ce..b7f05dd7 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 @@ -14,6 +14,7 @@ # limitations under the License. # from pathlib import Path +from typing import Optional from loguru import logger @@ -128,14 +129,14 @@ def sdk_yaml_test_collection( def custom_yaml_test_collection( yaml_test_folder: YamlTestFolder = CUSTOM_YAML_TEST_FOLDER, -) -> YamlCollectionDeclaration: +) -> Optional[YamlCollectionDeclaration]: """Declare a new collection of test suites.""" collection = YamlCollectionDeclaration( name="Custom YAML Tests", folder=yaml_test_folder ) files = yaml_test_folder.yaml_file_paths() - suites = _parse_all_yaml(yaml_files=files, yaml_version=None) + suites = _parse_all_yaml(yaml_files=files, yaml_version="custom") for suite in suites: if not suite.test_cases: