Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Setup tests #4

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
runs-on: [self-hosted, 'SCADE']
strategy:
matrix:
# scade-version: ['19.2', '19.4', '21.1', '21.2']
# scade-version: ['23.1', '23.2']
scade-version: ['23.1']
fail-fast: false
steps:
Expand All @@ -164,12 +164,13 @@ jobs:
target-dir: '.venvs'
target-name: ${{ steps.get-scade-python.outputs.python-name }}

# no test application for now
# - name: Execute tests
# uses: ./scade-tests-pytest
# with:
# python-dir: ${{ steps.create-scade-venv.outputs.scripts-dir }}
# checkout: false
- name: Execute tests
uses: ./scade-tests-pytest
with:
python-dir: ${{ steps.create-scade-venv.outputs.scripts-dir }}
library-dir: "tests/python"
pytest-postargs: "tests/python/tests -vv"
checkout: false

doc-deploy-dev:
name: "Deploy developers documentation"
Expand Down
14 changes: 10 additions & 4 deletions scade-tests-pytest/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ inputs:
required: true

# Optional inputs
library-dir:
description: >
Directory of the library to test.
default: '.'
required: false

pytest-markers:
description: >
Set of `pytest markers
Expand Down Expand Up @@ -75,15 +81,15 @@ runs:
- name: "Install Python library"
shell: cmd
run: |
%PYTHON_EXE% -m pip install .
%PYTHON_EXE% -m pip install ${{ inputs.library-dir }}

- name: "Check if requirements.txt file exists"
- name: "Check if requirements_tests.txt file exists"
shell: cmd
run: |
:: Add the requirements
if exist requirements/requirements_tests.txt (
if exist ${{ inputs.library-dir }}/requirements/requirements_tests.txt (
echo Install test dependencies from the requirements file
%PYTHON_EXE% -m pip install -r requirements/requirements_tests.txt
%PYTHON_EXE% -m pip install -r ${{ inputs.library-dir }}/requirements/requirements_tests.txt
)

# - name: "Install test dependencies from pyproject.toml"
Expand Down
32 changes: 32 additions & 0 deletions tests/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
TestResults
*.pyproj
*.sln
*.vsw
2 changes: 2 additions & 0 deletions tests/python/requirements/requirements_tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest==7.1.2
pytest-cov==3.0.0
12 changes: 12 additions & 0 deletions tests/python/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from setuptools import find_packages, setup

setup(
name="test_package",
version="0.1.dev0",
url="https://github.com/test-package-for-scade-actions.git",
author="ESEG",
author_email="[email protected]",
description="Test purpose",
packages=find_packages(where="./src"),
package_dir={"": "src"},
)
21 changes: 21 additions & 0 deletions tests/python/src/test_package/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
45 changes: 45 additions & 0 deletions tests/python/src/test_package/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""
Simple script to verify the correct execution of the actions.
"""

from pathlib import Path

from scade import output
from scade.model.project.stdproject import get_roots as get_projects
from scade.model.suite import get_roots as get_sessions


def get_project_names(projects):
return [Path(_.pathname).name for _ in projects]


def get_operator_paths(model):
return [_.get_full_path() for _ in model.all_operators]


if __name__ == "__main__":
output(str(get_project_names(get_projects())) + "\n")
# assume one and only one SCADE project
output(str(get_operator_paths(get_sessions()[0].model)) + "\n")
90 changes: 90 additions & 0 deletions tests/python/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Unit tests fixtures."""

import os
import re
import sys
from inspect import getsourcefile
from pathlib import Path

# import pytest

# set sys.path from the python interpreter location (<install>/SCADE/contrib/Python3xx)
# note: these tests are executed in the context of a virtual environment
# on top of a SCADE's Python distribution

for line in (Path(sys.executable).parent.parent / "pyvenv.cfg").open("r"):
m = re.match(r"^home\s*=\s*(.*)$", line)
if m:
contrib = Path(m.groups()[0]).parent
break

assert contrib
base = contrib.parent / "SCADE"
bin = base / "bin"
assert bin.exists()
sys.path.append(str(bin))
lib = base / "APIs" / "Python" / "lib"
assert lib.exists()
sys.path.append(str(lib))


# can be imported since sys.path is updated
# isort: split
# activate the SCADE Python APIs by importing scade_env
import scade_env # noqa: E402, F401

# must be imported after scade_env
# isort: split
import scade # noqa: E402
import scade.model.suite as suite # noqa: E402


def get_resources_dir() -> Path:
"""Return the directory ./resources relative to this file's directory."""
script_path = Path(os.path.abspath(getsourcefile(lambda: 0)))
return script_path.parent


def load_session(pathname: Path):
"""
Load a Scade model in a separate environment.

Note: The model can have unresolved references since the libraries
are not loaded.
"""
session = suite.Session()
session.load2(str(pathname))
assert session.model
return session


def load_project(pathname: Path):
"""
Load a Scade project in a separate environment.

Note: Undocumented API.
"""
project_ = scade.load_project(str(pathname))
return project_
Loading
Loading