Skip to content

Commit

Permalink
Automated tests for Vehicle App Python Template (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
mml5bg authored Sep 22, 2023
1 parent 82ebc42 commit bc1f20a
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 15 deletions.
1 change: 1 addition & 0 deletions .devcontainer/tests/automated_tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
parameterized==0.9.0
36 changes: 36 additions & 0 deletions .devcontainer/tests/automated_tests/requirements_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) 2023 Robert Bosch GmbH

# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://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.

# SPDX-License-Identifier: Apache-2.0

import unittest
from pathlib import Path

import pkg_resources
from parameterized import parameterized


class TestRequirements(unittest.TestCase):
"""Test availability of required packages."""

@parameterized.expand(
["./requirements.txt", "./app/requirements.txt", "./app/tests/requirements.txt"]
)
def test_requirements(self, requirement_file_path):
"""Test that each required package is available."""
requirements = pkg_resources.parse_requirements(
Path(requirement_file_path).open()
)
for requirement in requirements:
requirement = str(requirement)
with self.subTest(requirement=requirement):
pkg_resources.require(requirement)
51 changes: 51 additions & 0 deletions .devcontainer/tests/automated_tests/runtime_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (c) 2023 Robert Bosch GmbH

# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://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.

# SPDX-License-Identifier: Apache-2.0

import os
import subprocess # nosec
import unittest

from parameterized import parameterized

devenv_runtimes_path = (
subprocess.check_output(["velocitas", "package", "-p", "devenv-runtimes"]) # nosec
.decode("utf-8")
.strip("\n")
)

os.environ["VDB_PORT"] = "30555"
os.environ["MQTT_PORT"] = "31883"


class RuntimeTest(unittest.TestCase):
@parameterized.expand(["runtime_k3d", "runtime_kanto", "runtime_local"])
def test_runtime(self, runtime):
subprocess.check_call( # nosec
[
"pytest",
"-s",
"-x",
(
f"{devenv_runtimes_path}/{runtime}/test/integration/"
f"integration_test.py::test_scripts_run_successfully"
),
]
)
subprocess.check_call( # nosec
["pytest", "-s", "-x", "./app/tests/integration/integration_test.py"]
)
if runtime != "runtime_local":
subprocess.check_call( # nosec
["velocitas", "exec", runtime.replace("_", "-"), "down"]
)
44 changes: 44 additions & 0 deletions .github/workflows/check-devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This file is maintained by velocitas CLI, do not modify manually. Change settings in .velocitas.json
# Copyright (c) 2023 Robert Bosch GmbH
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://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.
#
# SPDX-License-Identifier: Apache-2.0

name: Devcontainer check

on:
workflow_dispatch:
push:
# Run only on branches/commits and not tags
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "0 4 * * *"


jobs:
automated-tests:
runs-on: ubuntu-22.04

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Build devcontainer and run automated tests
uses: devcontainers/[email protected]
with:
runCmd: |
pip3 install -r .devcontainer/tests/automated_tests/requirements.txt
pytest -sx .devcontainer/tests
13 changes: 0 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,3 @@ jobs:
name: "test-results"
path: |
results/Documentation/renderer/*
devcontainer-check:
runs-on: ubuntu-22.04

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Build and run dev container task
uses: devcontainers/[email protected]
with:
runCmd: velocitas upgrade --dry-run
push: never
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ repos:
hooks:
- id: insert-license
files: '.*\.(py|pyi|yaml|yml|sh|helmignore|dockerignore|gitignore)$'
exclude: .devcontainer/tests
args:
- --license-filepath
- license_header.txt
Expand Down
4 changes: 2 additions & 2 deletions .velocitas.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"packages": [
{
"name": "devenv-runtimes",
"version": "v2.1.0"
"version": "v2.2.0"
},
{
"name": "devenv-github-workflows",
"version": "v4.0.0"
"version": "v4.1.1"
},
{
"name": "devenv-github-templates",
Expand Down

0 comments on commit bc1f20a

Please sign in to comment.