Skip to content

Commit

Permalink
Add NUTILS_REQUIRES environment variable
Browse files Browse the repository at this point in the history
This patch adds the NUTILS_REQUIRES environment variable, which instruct the
require methods and requires decorators in testing that any missing item is not
acceptable and should not result in a skipped test. The variables are set in
appropriate places of the test workflow.
  • Loading branch information
gertjanvanzwieten committed Jan 31, 2025
1 parent 2251e7b commit bb4cb43
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
MKL_NUM_THREADS: 1
PYTHONHASHSEED: 0
NUTILS_TENSORIAL: ${{ matrix.tensorial }}
NUTILS_TESTING_REQUIRES: "mod:matplotlib mod:meshio mod:PIL"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -89,7 +90,9 @@ jobs:
path: dist/
- name: Install Graphviz
if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt install -y graphviz
run: |
sudo apt install -y graphviz
echo "NUTILS_TESTING_REQUIRES=$NUTILS_TESTING_REQUIRES app:dot" >> $GITHUB_ENV
- name: Install Nutils and dependencies
id: install
env:
Expand All @@ -101,11 +104,14 @@ jobs:
python -um pip install "$_wheel[import-gmsh,export-mpl]"
- name: Install Scipy
if: ${{ matrix.matrix-backend == 'scipy' }}
run: python -um pip install --upgrade scipy
run: |
python -um pip install --upgrade scipy
echo "NUTILS_TESTING_REQUIRES=$NUTILS_TESTING_REQUIRES mod:scipy" >> $GITHUB_ENV
- name: Configure MKL
if: ${{ matrix.matrix-backend == 'mkl' }}
run: |
python -um pip install --upgrade --upgrade-strategy eager mkl
echo "NUTILS_TESTING_REQUIRES=$NUTILS_TESTING_REQUIRES lib:mkl_rt" >> $GITHUB_ENV
- name: Test
env:
COVERAGE_ID: ${{ matrix.name }}
Expand Down Expand Up @@ -203,6 +209,7 @@ jobs:
# Fixes https://github.com/actions/virtual-environments/issues/3080
STORAGE_OPTS: overlay.mount_program=/usr/bin/fuse-overlayfs
_wheel: ${{ needs.build-python-package.outputs.wheel }}
NUTILS_TESTING_REQUIRES: "mod:matplotlib mod:meshio mod:PIL lib:mkl_rt"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
12 changes: 12 additions & 0 deletions nutils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import logging
import numpy
import shutil
import os
from nutils import warnings, numeric, _util as util


Expand All @@ -31,6 +32,10 @@ def emit(self, record):
def _require(category, test, *items):
missing = [item for item in items if not test(item)]
if missing:
for item in os.getenv(f'NUTILS_TESTING_REQUIRES', '').split():
prefix, name = item.split(':')
if category.startswith(prefix) and name in missing:
raise RuntimeError(f'{category} {required!r} is unexpectedly missing')

Check warning on line 38 in nutils/testing.py

View workflow job for this annotation

GitHub Actions / Test coverage

Line not covered

Line 38 of `nutils/testing.py` is not covered by tests.
if len(missing) > 1:
category += 's'

Check warning on line 40 in nutils/testing.py

View workflow job for this annotation

GitHub Actions / Test coverage

Line not covered

Line 40 of `nutils/testing.py` is not covered by tests.
missing = ', '.join(missing)
Expand All @@ -42,6 +47,13 @@ def _test_decorator(test, *args):
test(*args)
except unittest.SkipTest as e:
wrapper = unittest.skip(e)
except Exception as outer_exc:
inner_exc = outer_exc
def wrapper(f):
@functools.wraps(f)
def wrapped(self):
raise inner_exc
return wrapped

Check warning on line 56 in nutils/testing.py

View workflow job for this annotation

GitHub Actions / Test coverage

Lines not covered

Lines 50–56 of `nutils/testing.py` are not covered by tests.
else:
def wrapper(f):
return f
Expand Down

0 comments on commit bb4cb43

Please # to comment.