Skip to content

Commit

Permalink
feat: Add the action scade-tests-pytest (#9)
Browse files Browse the repository at this point in the history
* Add the action scade-tests-pytest
  • Loading branch information
ansjhenry authored Feb 20, 2024
1 parent c5e290a commit 057db2f
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 31 deletions.
30 changes: 5 additions & 25 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,33 +141,13 @@ jobs:
scade-version: ['23.2']
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 }}

# - name: Checkout
# 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 %}
83 changes: 83 additions & 0 deletions scade-tests-pytest/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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 }}

- 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: ${{ inputs.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 057db2f

Please sign in to comment.