From 8c2cf14c5518128b6ede8f9014df753e9e74ec46 Mon Sep 17 00:00:00 2001 From: Federico Stagni Date: Thu, 16 Nov 2023 16:28:19 +0100 Subject: [PATCH] test: fixing py tests --- .github/workflows/prepare_environment.sh | 11 ----- .github/workflows/python2-3-app.yml | 56 +++++++++++++++--------- environment.yml | 6 +-- pyproject.toml | 15 +++++-- src/db12/benchmark.py | 2 +- tests/test_DB12.py | 3 +- 6 files changed, 51 insertions(+), 42 deletions(-) delete mode 100755 .github/workflows/prepare_environment.sh diff --git a/.github/workflows/prepare_environment.sh b/.github/workflows/prepare_environment.sh deleted file mode 100755 index 892a886..0000000 --- a/.github/workflows/prepare_environment.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -PYTHON_VERSION=$1 - -conda create --quiet -c conda-forge -c free -n test-env \ - python="$PYTHON_VERSION" \ - "pytest>=4.6" pylint pytest-cov pytest-mock pycodestyle \ - mock setuptools setuptools_scm wheel -source "${CONDA}/bin/activate" test-env -pip install ".[testing]" diff --git a/.github/workflows/python2-3-app.yml b/.github/workflows/python2-3-app.yml index 764e6ed..c938a8e 100644 --- a/.github/workflows/python2-3-app.yml +++ b/.github/workflows/python2-3-app.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest if: github.event_name != 'push' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions/setup-python@v2 with: python-version: '3.9' @@ -16,31 +16,45 @@ jobs: - name: Run pre-commit run: pre-commit run --all-files --show-diff-on-failure - build: - runs-on: ubuntu-latest + pytest: + runs-on: ubuntu-20.04 + if: github.event_name != 'push' || github.repository == 'DIRACGrid/db12' + strategy: - fail-fast: False matrix: - python_version: - - 2.7 - - 3.6 - - 3.9 + python: + - 2.7.18 + - 3.6.15 + - 3.9.17 + - 3.11.4 + container: python:${{ matrix.python }}-slim steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - name: Installing dependencies + run: | + python -m pip install pytest mock + pip install -e . + - name: Run pytest + run: pytest - - uses: actions/checkout@v2 - - name: Prepare environment - run: .github/workflows/prepare_environment.sh ${{ matrix.python_version }} + pylint: + runs-on: ubuntu-20.04 + if: github.event_name != 'push' || github.repository == 'DIRACGrid/db12' + timeout-minutes: 10 - - name: Run pylint - run: | - . "${CONDA}/bin/activate" test-env - pylint -E src/db12/ tests/ + strategy: + matrix: + python: + - 2.7.18 + - 3.6.15 + - 3.9.17 - - name: Run pytest + container: python:${{ matrix.python }}-slim + steps: + - uses: actions/checkout@v4 + - name: Installing dependencies run: | - . "${CONDA}/bin/activate" test-env - pytest tests + python -m pip install pylint pytest mock + - name: Run pylint + run: pylint -E src/db12 tests diff --git a/environment.yml b/environment.yml index 8e61232..06cf492 100644 --- a/environment.yml +++ b/environment.yml @@ -3,8 +3,6 @@ name: db12 dependencies: - python =3.9 - future - - mock - pre-commit - - pylint - - pytest - - pytest-mock + - pip: + - -e . diff --git a/pyproject.toml b/pyproject.toml index 374b58c..494f262 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,13 @@ [build-system] -requires = [ - "setuptools>=42", - "wheel" -] +requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"] build-backend = "setuptools.build_meta" + +# Enable setuptools_scm to compute the version number from the most recent tag +# https://github.com/pypa/setuptools_scm/#pyprojecttoml-usage +[tool.setuptools_scm] +# Avoid letting setuptools_scm use old style tags (i.e. vXrYpZ) +git_describe_command = "git describe --dirty --tags --long --match *[0-9].[0-9]* --exclude v[0-9]r* --exclude v[0-9][0-9]r*" + +[tool.isort] +profile = "black" + diff --git a/src/db12/benchmark.py b/src/db12/benchmark.py index 30d44d5..82a11ff 100644 --- a/src/db12/benchmark.py +++ b/src/db12/benchmark.py @@ -64,7 +64,7 @@ def single_dirac_benchmark(iterations_num=1, measured_copies=None, correction=Tr it_1 += 1 - cput = sum(end[:4]) - sum(start[:4]) + cput = sum(end[:4]) - sum(start[:4]) # pylint: disable=used-before-assignment wall = end[4] - start[4] if not cput: diff --git a/tests/test_DB12.py b/tests/test_DB12.py index 2203fee..45199d2 100644 --- a/tests/test_DB12.py +++ b/tests/test_DB12.py @@ -1,8 +1,9 @@ """Unit test for DB12""" +from __future__ import print_function from __future__ import absolute_import from __future__ import division + import pytest -import mock from db12 import single_dirac_benchmark from db12 import multiple_dirac_benchmark