From 18675cccab927b569dd098c316504ec157597ea8 Mon Sep 17 00:00:00 2001 From: Nicola Coretti Date: Mon, 5 Feb 2024 15:09:03 +0100 Subject: [PATCH] Add basic CI test setup --- .github/workflows/checks.yml | 49 +++++++++++++++++++++++++++++++++ .github/workflows/ci-master.yml | 17 +----------- .github/workflows/ci-pr.yml | 16 +---------- noxfile.py | 47 +++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/checks.yml create mode 100644 noxfile.py diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..e488fbf --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,49 @@ +name: CI Checks + +on: + workflow_call: + + +jobs: + + unit-tests: + name: Unit Tests + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + python-version: [ "3.11" ] + + steps: + - name: SCM Checkout + uses: actions/checkout@v4 + + - name: Setup Python & Poetry Environment + uses: exasol/python-toolbox/.github/actions/python-environment@0.7.0 + with: + python-version: ${{ matrix.python-version }} + + - name: Run Tests + run: | + poetry run nox -s unit-tests + + integration-tests: + name: Integration Tests + runs-on: ubuntu-20.04 + strategy: + fail-fast: true + matrix: + python-version: [ "3.11" ] + + steps: + - name: SCM Checkout + uses: actions/checkout@v4 + + - name: Setup Python & Poetry Environment + uses: exasol/python-toolbox/.github/actions/python-environment@0.7.0 + with: + python-version: ${{ matrix.python-version }} + + - name: Run Tests + run: | + poetry run nox -s integration-tests diff --git a/.github/workflows/ci-master.yml b/.github/workflows/ci-master.yml index 24e7385..7843204 100644 --- a/.github/workflows/ci-master.yml +++ b/.github/workflows/ci-master.yml @@ -12,20 +12,5 @@ on: - cron: "0 0 1/7 * *" jobs: - verify: - runs-on: ubuntu-latest - - steps: - - - name: SCM Checkout - uses: actions/checkout@v4 - - - name: Setup Python & Poetry Environment - uses: exasol/python-toolbox/.github/actions/python-environment@main - with: - python-version: "3.11" - - - name: Run all checks - run: | - echo "Stub: This needs to call the checks in the future" + uses: ./.github/workflows/checks.yml diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml index a12f98d..cbd7c6f 100644 --- a/.github/workflows/ci-pr.yml +++ b/.github/workflows/ci-pr.yml @@ -10,18 +10,4 @@ on: jobs: verify: - runs-on: ubuntu-latest - - steps: - - - name: SCM Checkout - uses: actions/checkout@v4 - - - name: Setup Python & Poetry Environment - uses: exasol/python-toolbox/.github/actions/python-environment@0.7.0 - with: - python-version: "3.11" - - - name: Run all checks - run: | - echo "Stub: This needs to call the checks in the future" + uses: ./.github/workflows/checks.yml diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000..146441c --- /dev/null +++ b/noxfile.py @@ -0,0 +1,47 @@ +from __future__ import annotations +from pathlib import Path +from typing import Iterable +import nox +from nox import Session + +__all__ = [ + "unit_tests", + "integration_tests", +] + +_ROOT : Path = Path(__file__).parent + + +def _test_command(path: Path) -> Iterable[str]: + base_command = ["poetry", "run"] + pytest_command = ["pytest", "-v", f"{path}"] + return base_command + pytest_command + + +def _unit_tests(session: Session) -> None: + command = _test_command(_ROOT / "test" / "unit") + session.run(*command) + + +def _integration_tests(session: Session) -> None: + command = _test_command(_ROOT / "test" / "integration") + session.run(*command) + + +@nox.session(name="unit-tests", python=False) +def unit_tests(session: Session) -> None: + """Runs all unit tests""" + _unit_tests(session) + + +@nox.session(name="integration-tests", python=False) +def integration_tests(session: Session) -> None: + """Runs the all integration tests""" + _integration_tests(session) + + +@nox.session(name="all-tests", python=False) +def all_tests(session: Session) -> None: + """Runs all tests (Unit and Integration)""" + command = _test_command(_ROOT / "test") + session.run(*command)