Skip to content

Commit

Permalink
Add the action scade-tests-pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
ansjhenry committed Feb 20, 2024
1 parent c5e290a commit a40f9df
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 29 deletions.
26 changes: 3 additions & 23 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,32 +142,12 @@ jobs:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get SCADE installation directory
uses: ./get-scade-dir
id: get-scade-dir
with:
scade-version: ${{ matrix.scade-version }}

- name: Get Python version
uses: ./get-scade-python
id: get-scade-python
with:
scade-dir: ${{ steps.get-scade-dir.outputs.scade-directory }}

- name: Create a Python virtual environment
uses: ./create-scade-venv
id: create-scade-venv
with:
python-dir: ${{ steps.get-scade-python.outputs.python-dir }}
target-dir: '.venvs'
target-name: ${{ steps.get-scade-python.outputs.python-name }}
uses: actions/checkout@v4

- name: Execute tests
uses: ./tests-pytest
uses: ./scade-tests-pytest
with:
python-dir: ${{ steps.create-scade-venv.outputs.scripts-dir }}
scade-version: ${{ matrix.scade-version }}
library-dir: "tests/python"
pytest-postargs: "tests/python/tests -vv"
checkout: false
Expand Down
10 changes: 10 additions & 0 deletions doc/source/tests-actions/examples/scade-tests-pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests:
name: "Run tests basic example"
runs-on: [self-hosted, 'SCADE']
steps:
- name: "Run the tests for a given version of Ansys SCADE"
uses: ansys/scade-actions/scade-tests-pytest@{{ version }}
with:
scade-version: '23.2'
pytest-extra-args: "--cov=ansys --cov-report=term --cov-branch --cov-report=html:.cov/html"
checkout: false
35 changes: 32 additions & 3 deletions doc/source/tests-actions/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ Create SCADE Python virtual environment action

Test library action
--------------------
This action runs the test suite for a Python library. This action accepts
markers, options, and post arguments to be passed to pytest before executing
the test session.
This action runs the test suite for a Python library and a given Python
interpreter. This action accepts markers, options, and post arguments to be
passed to pytest before executing the test session.

.. jinja:: tests-pytest

Expand All @@ -56,3 +56,32 @@ Examples
:language: yaml

{% endfor %}


SCADE Test library action
-------------------------
This action runs the test suite for a Python library and a given version of
Ansys SCADE. This action accepts markers, options, and post arguments to be
passed to pytest before executing the test session.

.. jinja:: scade-tests-pytest

{{ description }}

{{ inputs_table }}

{{ outputs_table }}

Examples
++++++++

.. jinja:: scade-tests-pytest

{% for filename, title in examples %}
.. dropdown:: {{ title }}
:animate: fade-in

.. literalinclude:: examples/{{ filename }}
:language: yaml

{% endfor %}
98 changes: 98 additions & 0 deletions scade-tests-pytest/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# action derived from ansys/actions/tests-pytest
name: >
Tests pytest action
description: >
Run a test suite using `pytest <https://docs.pytest.org/en/stable/>`_.
inputs:

scade-version:
description: >
SCADE version used for installing and running ``pytest``.
For example, use ``'24.1'`` for Ansys SCADE 2024 R1.
required: true

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

pytest-markers:
description: >
Set of `pytest markers
<https://docs.pytest.org/en/stable/example/markers.html>`_ in the form of
a string. These markers are used to discretize tests when running the test
session.
default: ''
required: false

pytest-extra-args:
description: >
Set of additional ``pytest`` arguments in the form of a string.
default: ''
required: false

pytest-postargs:
description: >
Directory of the test suite and the level of verbosity.
default: 'tests -vv'
required: false

checkout:
description: >
Whether to clone the repository in the CI/CD machine.
default: 'true'
required: false


runs:
using: "composite"
steps:

- name: "Retrieve SCADE installation directory"
uses: ./get-scade-dir
id: get-scade-dir
with:
scade-version: ${{ inputs.scade-version }}

- name: "Retrieve SCADE Python interpreter"
uses: ./get-scade-python
id: get-scade-python
with:
scade-dir: ${{ steps.get-scade-dir.outputs.scade-directory }}

- name: "Create Python virtual environment"
uses: ./create-scade-venv
id: create-scade-venv
with:
python-dir: ${{ steps.get-scade-python.outputs.python-dir }}
target-dir: '.venvs'
target-name: ${{ steps.get-scade-python.outputs.python-name }}

# redundant with ./tests-pytest
# - name: Check Python and install dependencies
# shell: cmd
# run: |
# echo "Activate the environment ${{ steps.create-scade-venv.outputs.scripts-dir }}"
# echo PYTHON_DIR=${{ steps.create-scade-venv.outputs.scripts-dir }}>> %GITHUB_ENV%
#
# - name: Check Python
# shell: cmd
# run: |
# call %PYTHON_DIR%\activate.bat
# python --version
# %PYTHON_DIR%\python.exe -m pip install -U pip
# %PYTHON_DIR%\python.exe -m pip install ${{ inputs.library-dir }}[tests]

- name: "Run the tests"
uses: ./tests-pytest
with:
python-dir: ${{ steps.create-scade-venv.outputs.scripts-dir }}
library-dir: ${{ inputs.library-dir }}
pytest-markers: ${{ inputs.pytest-markers }}
pytest-extra-args: ${{ inputs.pytest-extra-args }}
pytest-postargs: ${{ inputs.pytest-postargs }}
checkout: ${{ checkout }}
5 changes: 2 additions & 3 deletions tests-pytest/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ inputs:

checkout:
description: >
Whether to clone the repository in the CI/CD machine. Default value is
``true``.
Whether to clone the repository in the CI/CD machine.
default: 'true'
required: false

Expand All @@ -54,7 +53,7 @@ runs:
steps:

- name: "Install Git and clone project"
uses: actions/checkout@v3
uses: actions/checkout@v4
if: ${{ inputs.checkout == 'true' }}

- name: Pass Inputs to Shell
Expand Down

0 comments on commit a40f9df

Please sign in to comment.