Skip to content

Commit f623990

Browse files
authored
Refactor tests into scripts (#832)
* Complete testing script. * Test scripts in CI and update `contributing.md` to use script.
1 parent ada7871 commit f623990

16 files changed

+110
-34
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ jobs:
3030
env:
3131
PYTHON_VERSION: ${{ matrix.python }}
3232
NUMBA_BOUNDSCHECK: ${{ matrix.numba_boundscheck }}
33-
PYTHONFAULTHANDLER: '${{ github.workspace }}/faulthandler.log'
3433
steps:
3534
- name: Checkout Repo
3635
uses: actions/checkout@v4
@@ -49,15 +48,7 @@ jobs:
4948
run: |
5049
pip install -e '.[tests]'
5150
- name: Run tests
52-
run: |
53-
if [ $(python -c 'import numpy as np; print(np.lib.NumpyVersion(np.__version__) >= "2.0.0a1")') = 'True' ]; then
54-
pytest --pyargs sparse --doctest-modules --cov-report=xml:coverage_Numba.xml -n auto -vvv
55-
else
56-
pytest --pyargs sparse --cov-report=xml:coverage_Numba.xml -n auto -vvv
57-
fi
58-
python -c 'import finch'
59-
SPARSE_BACKEND=Finch pytest --pyargs sparse/tests --cov-report=xml:coverage_Finch.xml -n auto -vvv
60-
SPARSE_BACKEND=MLIR pytest --pyargs sparse/mlir_backend --cov-report=xml:coverage_MLIR.xml -n auto -vvv
51+
run: ci/test_backends.sh
6152
- uses: codecov/codecov-action@v5
6253
if: always()
6354
with:
@@ -79,8 +70,7 @@ jobs:
7970
pip install -U setuptools wheel
8071
pip install '.[finch]' scipy
8172
- name: Run examples
82-
run: |
83-
source ci/test_examples.sh
73+
run: ci/test_examples.sh
8474

8575
notebooks:
8676
runs-on: ubuntu-latest
@@ -96,46 +86,36 @@ jobs:
9686
run: |
9787
pip install -e '.[notebooks]'
9888
- name: Run notebooks
99-
run: |
100-
source ci/test_notebooks.sh
89+
run: ci/test_notebooks.sh
10190

10291
array_api_tests:
10392
strategy:
10493
matrix:
10594
backend: ['Numba', 'Finch']
10695
fail-fast: false
96+
env:
97+
ARRAY_API_TESTS_DIR: ${{ github.workspace }}/array-api-tests
10798
runs-on: ubuntu-latest
10899
steps:
109100
- name: Checkout Repo
110101
uses: actions/checkout@v4
111102
- name: Checkout array-api-tests
112-
uses: actions/checkout@v4
113-
with:
114-
repository: data-apis/array-api-tests
115-
ref: '33f2d2ea2f3dd2b3ceeeb4519d55e08096184149' # Latest commit as of 2024-05-29
116-
submodules: 'true'
117-
path: 'array-api-tests'
103+
run: ci/clone_array_api_tests.sh
118104
- name: Set up Python
119105
uses: actions/setup-python@v5
120106
with:
121107
python-version: '3.11'
122108
cache: 'pip'
123109
- name: Install build and test dependencies from PyPI
124110
run: |
125-
pip install pytest-xdist -r array-api-tests/requirements.txt
111+
pip install pytest-xdist -r "$ARRAY_API_TESTS_DIR/requirements.txt"
126112
- name: Build and install Sparse
127113
run: |
128114
pip install '.[finch]'
129115
- name: Run the test suite
130116
env:
131-
ARRAY_API_TESTS_MODULE: sparse
132117
SPARSE_BACKEND: ${{ matrix.backend }}
133-
run: |
134-
cd ${GITHUB_WORKSPACE}/array-api-tests
135-
if [ "${SPARSE_BACKEND}" = "Finch" ]; then
136-
python -c 'import finch'
137-
fi
138-
pytest array_api_tests -v -c pytest.ini -n auto --max-examples=2 --derandomize --disable-deadline -o xfail_strict=True --xfails-file ${GITHUB_WORKSPACE}/ci/${{ matrix.backend }}-array-api-xfails.txt --skips-file ${GITHUB_WORKSPACE}/ci/${{ matrix.backend }}-array-api-skips.txt
118+
run: ci/test_array_api.sh
139119

140120
on:
141121
# Trigger the workflow on push or pull request,

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ results/
8484
# Notebooks converted to scripts.
8585
docs/examples_ipynb/
8686

87-
# Pixi envs
87+
# Envs
8888
.pixi/
8989
pixi.lock
90+
.venv/

ci/array-api-tests-rev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
33f2d2ea2f3dd2b3ceeeb4519d55e08096184149

ci/clone_array_api_tests.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
ARRAY_API_TESTS_DIR="${ARRAY_API_TESTS_DIR:-"../array-api-tests"}"
5+
if [ ! -d "$ARRAY_API_TESTS_DIR" ]; then
6+
git clone --recursive https://github.com/data-apis/array-api-tests.git "$ARRAY_API_TESTS_DIR"
7+
fi
8+
9+
git --git-dir="$ARRAY_API_TESTS_DIR/.git" --work-tree "$ARRAY_API_TESTS_DIR" clean -xddf
10+
git --git-dir="$ARRAY_API_TESTS_DIR/.git" --work-tree "$ARRAY_API_TESTS_DIR" fetch
11+
git --git-dir="$ARRAY_API_TESTS_DIR/.git" --work-tree "$ARRAY_API_TESTS_DIR" reset --hard $(cat "ci/array-api-tests-rev.txt")

ci/setup_env.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
if [ ! -d ".venv" ]; then
5+
python -m venv .venv
6+
source .venv/bin/activate
7+
pip install -e .[all]
8+
source ci/clone_array_api_tests.sh
9+
pip install -r ../array-api-tests/requirements.txt
10+
pip uninstall -y matrepr
11+
fi

ci/test_Finch.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
python -c 'import finch'
5+
PYTHONFAULTHANDLER="${HOME}/faulthandler.log" SPARSE_BACKEND=Finch pytest --pyargs sparse/tests --cov-report=xml:coverage_Finch.xml -n auto -vvv

ci/test_MLIR.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
SPARSE_BACKEND=MLIR pytest --pyargs sparse/mlir_backend --cov-report=xml:coverage_MLIR.xml -n auto -vvv

ci/test_Numba.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
if [ $(python -c 'import numpy as np; print(np.lib.NumpyVersion(np.__version__) >= "2.0.0a1")') = 'True' ]; then
5+
pytest --pyargs sparse --doctest-modules --cov-report=xml:coverage_Numba.xml -n auto -vvv
6+
else
7+
pytest --pyargs sparse --cov-report=xml:coverage_Numba.xml -n auto -vvv
8+
fi

ci/test_all.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
ACTIVATE_VENV="${ACTIVATE_VENV:-0}"
5+
6+
if [ $ACTIVATE_VENV = "1" ]; then
7+
source .venv/bin/activate
8+
fi
9+
10+
source ci/test_backends.sh
11+
source ci/test_examples.sh
12+
source ci/test_notebooks.sh
13+
SPARSE_BACKEND="Numba" source ci/test_array_api.sh
14+
SPARSE_BACKEND="Finch" PYTHONFAULTHANDLER="${HOME}/faulthandler.log" source ci/test_array_api.sh

ci/test_array_api.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
source ci/clone_array_api_tests.sh
5+
6+
if [ "${SPARSE_BACKEND}" = "Finch" ]; then
7+
python -c 'import finch'
8+
fi
9+
ARRAY_API_TESTS_MODULE="sparse" pytest "$ARRAY_API_TESTS_DIR/array_api_tests/" -v -c "$ARRAY_API_TESTS_DIR/pytest.ini" --ci --max-examples=2 --derandomize --disable-deadline -o xfail_strict=True -n auto --xfails-file ../sparse/ci/${SPARSE_BACKEND}-array-api-xfails.txt --skips-file ../sparse/ci/${SPARSE_BACKEND}-array-api-skips.txt

0 commit comments

Comments
 (0)