Skip to content

Commit

Permalink
debug: test requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
Revathyvenugopal162 committed Feb 21, 2024
1 parent 0c0a364 commit 43bdb38
Show file tree
Hide file tree
Showing 18 changed files with 754 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Ansys SCADE actions
:target: https://actions.docs.ansys.com/
:alt: Ansys

.. |CI-CD| image:: https://github.com/ansys/actions/actions/workflows/ci_cd.yml/badge.svg
:target: https://github.com/ansys/actions/actions/workflows/ci_cd.yml
.. |CI-CD| image:: https://github.com/ansys/scade-actions/actions/workflows/ci_cd.yml/badge.svg
:target: https://github.com/ansys/scade-actions/actions/workflows/ci_cd.yml
:alt: CI-CD

.. |MIT| image:: https://img.shields.io/badge/License-MIT-blue.svg
Expand All @@ -30,4 +30,5 @@ Purpose

The Ansys SCADE actions prepare a SCADE environment for executing tests.

They are driven by a Ansys SCADE version, such as ``23.1`` or ``24.1``, instead of a Python version, such as ``3.7`` or ``3.10``.
They are driven by a Ansys SCADE version, such as ``23.1`` or ``24.1``,
instead of a Python version, such as ``3.7`` or ``3.10``.
File renamed without changes.
14 changes: 14 additions & 0 deletions tests/python-pyproject/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"

[project]
name="test_package"
version="0.1.dev0"
description ="Test purpose"

[project.optional-dependencies]
test = [
"pytest==7.1.2",
"pytest-cov==3.0.0"
]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions tests/python-setup/.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
File renamed without changes.
21 changes: 21 additions & 0 deletions tests/python-setup/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-setup/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-setup/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

0 comments on commit 43bdb38

Please sign in to comment.