diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..2629cbd --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,51 @@ +name: test +on: + push: + branches: + - "master" + - "feature/*" + - "hotfix/*" + - "release/*" + - "renovate/*" + pull_request: + workflow_dispatch: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install dependencies + run: make setup + - name: Run Linters + run: make lint + test: + strategy: + matrix: + platform: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: | + 3.8 + 3.9 + 3.10 + 3.11 + 3.12 + cache: 'pip' + - name: Install dependencies + run: | + make setup + pip install tox-gh + - name: Run tests + run: tox -m ci + env: + PYTEST_ADDOPTS: "--no-header -vv -rN" diff --git a/Makefile b/Makefile index 390c954..e5eacdf 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,8 @@ -# Copyright 2017 Canonical Ltd. +# Copyright 2017,2024 Canonical Ltd. # Licensed under the LGPLv3, see LICENCE file for details. include sysdeps.mk PYTHON = python -# Since the python-tox package in Ubuntu uses Python 3, use pip to install tox -# instead. This also works on OSX where tox is not present in Homebrew. -PIP_SYSDEPS = tox - -PIP = sudo pip install $(1) SYSDEPS_INSTALLED = .sysdeps-installed DEVENV = venv @@ -21,17 +16,18 @@ $(DEVENVPIP): $(SYSDEPS_INSTALLED): sysdeps.mk ifeq ($(shell command -v apt-get > /dev/null; echo $$?),0) sudo apt-get install --yes $(APT_SYSDEPS) +else ifeq ($(shell command -v brew > /dev/null; echo $$?),0) + brew install $(BREW_SYSDEPS) else @echo 'System dependencies can only be installed automatically on' - @echo 'systems with "apt-get". On OSX you can manually use Homebrew' - @echo 'if there are missing dependencies corresponding to the following' - @echo 'Debian packages:' + @echo 'systems with "apt-get" or "brew". Dependencies correspond to' + @echo 'the following Debian packages:' @echo '$(APT_SYSDEPS).' endif - sudo pip3 install $(PIP_SYSDEPS) + @command -v tox > /dev/null || (echo "Could not find tox on the PATH"; exit 1) + @command -v isort > /dev/null || (echo "Could not find isort on the PATH"; exit 1) touch $(SYSDEPS_INSTALLED) - .PHONY: check check: setup lint @tox diff --git a/sysdeps.mk b/sysdeps.mk index d3bffee..34327ae 100644 --- a/sysdeps.mk +++ b/sysdeps.mk @@ -1 +1,2 @@ -APT_SYSDEPS = python3-pip python3-setuptools libsodium-dev libffi-dev libssl-dev +APT_SYSDEPS = python3-pip python3-setuptools libsodium-dev libffi-dev libssl-dev tox isort +BREW_SYSDEPS = python3 libsodium libffi openssl tox isort diff --git a/test-requirements.txt b/test-requirements.txt index 27a0b39..0984b89 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,16 +1,17 @@ -# Copyright 2017 Canonical Ltd. +# Copyright 2017,2024 Canonical Ltd. # Licensed under the LGPLv3, see LICENCE file for details. coverage==7.3.2 extras==1.0.0 fixtures==3.0.0 flake8==2.4.0 -httmock==1.2.5 +httmock==1.4.0 linecache2==1.0.0 -mock==1.0.1 +mock==5.1.0 nose2==0.13.0 pbr==3.1.1 python-mimeparse==1.6.0 +setuptools==75.1.0 testtools==2.3.0; python_version<"3" testtools==2.5.0; python_version>="3" traceback2==1.4.0 diff --git a/tox.ini b/tox.ini index b9b393d..f9860bf 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,11 @@ -# Copyright 2017 Canonical Ltd. +# Copyright 2017,2024 Canonical Ltd. # Licensed under the LGPLv3, see LICENCE file for details. [tox] -envlist = lint, py27, py35, docs +envlist = lint, py3.8, docs # envlist = py27 +# If the system has tox < 4.8, installs a newer tox in a venv. +minversion = 4.8 [testenv] setenv = @@ -15,6 +17,9 @@ commands = deps = -r{toxinidir}/test-requirements.txt +[testenv:py3.{8,9,10,11,12,13}] +labels = ci + [testenv:devenv] envdir = devenv usedevelop = True