From 98811114d435ed29cd829c7f55a45340d5e7fb6c Mon Sep 17 00:00:00 2001 From: Patrick Baus Date: Sat, 22 Jun 2024 16:19:57 +0200 Subject: [PATCH] Test for the correct version before pushing to PyPI --- .github/workflows/publish-pypi.yml | 31 +++++++++++++++++++ tests/__init__.py | 0 .../test_encoder_decoder.py | 0 tests/test_version.py | 15 +++++++++ 4 files changed, 46 insertions(+) create mode 100644 tests/__init__.py rename test_encoder_decoder.py => tests/test_encoder_decoder.py (100%) create mode 100644 tests/test_version.py diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index b241da3..488b9ac 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -8,7 +8,38 @@ on: workflow_dispatch: jobs: + tests: + name: Run Python tests + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: [ "3.12", ] + + steps: + - name: Checkout source repository + uses: actions/checkout@v4 + + - name: Set up python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + cache: 'pip' # caching pip dependencies + python-version: ${{ matrix.python-version }} + + - name: Install dependencies for testing + run: | + python3 -m pip install --upgrade pip + python3 -m pip install .[test] + + - name: Test with pytest + env: + GIT_TAG: ${{ github.ref_type == 'tag' && github.ref_name || '' }} + run: | + pytest --exitfirst --verbose --failed-first + upload: + needs: + - tests runs-on: ubuntu-latest strategy: diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_encoder_decoder.py b/tests/test_encoder_decoder.py similarity index 100% rename from test_encoder_decoder.py rename to tests/test_encoder_decoder.py diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 0000000..183035c --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,15 @@ +"""Test to catch invalid versions when releasing a new git tag""" + +import os + +from hp3478a_async._version import __version__ + + +def test_version(): + """ + Test the Git tag when using CI against the package version + """ + if os.getenv("GIT_TAG"): + assert os.getenv("GIT_TAG") == __version__ + else: + assert True