From 4def07326e3369c36570888a103c83bd0df922f0 Mon Sep 17 00:00:00 2001 From: Adam Lugowski Date: Thu, 21 Sep 2023 23:44:24 -0700 Subject: [PATCH] Make test suite run without scipy --- .github/workflows/tests.yml | 27 +++++++++++---------------- pyproject.toml | 1 + tests/test_graphblas.py | 6 ++---- tests/test_heatmap.py | 8 +++++++- tests/test_scipy.py | 7 ++++++- tests/test_sparkline.py | 7 ++++++- tests/test_sparse.py | 8 ++++++-- 7 files changed, 39 insertions(+), 25 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a096bef..8852f09 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,50 +22,45 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install base dependencies - run: pip install numpy matplotlib pytest + run: pip install numpy matplotlib pytest pytest-subtests html5lib - name: Test minimums - run: pytest tests/test_basic.py - - - name: Install test dependencies - if: ${{ !contains(matrix.python-version, 'pypy') }} # no scipy wheels for pypy - run: pip install pytest numpy matplotlib pytest-subtests html5lib scipy - - - name: Test only scipy - if: ${{ !contains(matrix.python-version, 'pypy') }} # no scipy wheels for pypy run: pytest + - name: Install SciPy + # --only-binary disables compiling the package from source if a binary wheel is not available, such as PyPy + run: pip install --only-binary ":all:" scipy || true + - name: Install python-graphblas - if: ${{ !contains(matrix.python-version, 'pypy') && matrix.python-version != '3.7' }} # no wheels for pypy and old python + if: ${{ !contains(matrix.python-version, 'pypy') && matrix.python-version != '3.7' }} # no wheels for PyPy or old Python run: | pip install suitesparse-graphblas==7.4.4.1a1 pip install python-graphblas - name: Install pydata sparse - if: ${{ !contains(matrix.python-version, 'pypy') && matrix.python-version != '3.7' }} # no wheels for pypy and old python + if: ${{ !contains(matrix.python-version, 'pypy') && matrix.python-version != '3.7' }} # no wheels for PyPy or old Python run: | pip install sparse - name: Test without Jupyter - if: ${{ !contains(matrix.python-version, 'pypy') }} # no scipy wheels for pypy run: pytest - name: Install Jupyter - if: ${{ !contains(matrix.python-version, 'pypy') }} # no scipy wheels for pypy + if: ${{ !contains(matrix.python-version, 'pypy') }} run: pip install jupyter - name: Test with Jupyter - if: ${{ !contains(matrix.python-version, 'pypy') }} # no scipy wheels for pypy + if: ${{ !contains(matrix.python-version, 'pypy') }} run: pytest - name: Test with Coverage - if: ${{ contains(matrix.os, 'ubuntu') && !contains(matrix.python-version, 'pypy') }} + if: ${{ contains(matrix.os, 'ubuntu') }} run: | pip install pytest-cov pytest --cov=matspy --cov-report term --cov-report=xml - name: Upload Coverage to Codecov - if: ${{ contains(matrix.os, 'ubuntu') && !contains(matrix.python-version, 'pypy') }} + if: ${{ contains(matrix.os, 'ubuntu') }} uses: codecov/codecov-action@v3 with: gcov: true diff --git a/pyproject.toml b/pyproject.toml index d7ac65a..aa2436f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,3 +40,4 @@ repository = "https://github.com/alugowski/matspy" [project.optional-dependencies] test = ["pytest", "scipy", "matplotlib", "html5lib", "matrepr"] +testextra = ["python-graphblas", "sparse"] diff --git a/tests/test_graphblas.py b/tests/test_graphblas.py index fc1cf92..b7042a5 100644 --- a/tests/test_graphblas.py +++ b/tests/test_graphblas.py @@ -12,13 +12,11 @@ # Context initialization must happen before any other imports gb.init("suitesparse", blocking=True) - - have_gb = True except ImportError: - have_gb = False + gb = None -@unittest.skipIf(not have_gb, "python-graphblas not installed") +@unittest.skipIf(gb is None, "python-graphblas not installed") class GraphBLASTests(unittest.TestCase): def setUp(self): self.mats = [ diff --git a/tests/test_heatmap.py b/tests/test_heatmap.py index fb9ce6a..c3ab46e 100644 --- a/tests/test_heatmap.py +++ b/tests/test_heatmap.py @@ -5,12 +5,18 @@ import unittest import numpy.random -import scipy.sparse +try: + import scipy + import scipy.sparse +except ImportError: + scipy = None + from matspy import to_spy_heatmap numpy.random.seed(123) +@unittest.skipIf(scipy is None, "scipy not installed") class SpyHeatmapTests(unittest.TestCase): def test_buckets_1(self): density = 0.3 diff --git a/tests/test_scipy.py b/tests/test_scipy.py index a78e9b8..2ae1aed 100644 --- a/tests/test_scipy.py +++ b/tests/test_scipy.py @@ -5,13 +5,18 @@ import unittest import numpy.random -import scipy.sparse +try: + import scipy + import scipy.sparse +except ImportError: + scipy = None from matspy import spy_to_mpl, to_sparkline numpy.random.seed(123) +@unittest.skipIf(scipy is None, "scipy not installed") class SciPyTests(unittest.TestCase): def setUp(self): self.mats = [ diff --git a/tests/test_sparkline.py b/tests/test_sparkline.py index 9e50af0..dc79bdf 100644 --- a/tests/test_sparkline.py +++ b/tests/test_sparkline.py @@ -5,13 +5,18 @@ import unittest import numpy.random -import scipy.sparse +try: + import scipy + import scipy.sparse +except ImportError: + scipy = None from matspy import to_sparkline numpy.random.seed(123) +@unittest.skipIf(scipy is None, "scipy not installed") class SparklineTests(unittest.TestCase): def test_small_buckets(self): for dims in [(1001, 1001), (11, 11)]: diff --git a/tests/test_sparse.py b/tests/test_sparse.py index 14a6277..b718d41 100644 --- a/tests/test_sparse.py +++ b/tests/test_sparse.py @@ -10,14 +10,18 @@ sparse = None import numpy as np -import scipy.sparse +try: + import scipy + import scipy.sparse +except ImportError: + scipy = None from matspy import spy_to_mpl, to_sparkline, to_spy_heatmap np.random.seed(123) -@unittest.skipIf(sparse is None, "pydata/sparse not installed") +@unittest.skipIf(sparse is None or scipy is None, "pydata/sparse not installed") class PyDataSparseTests(unittest.TestCase): def setUp(self): self.mats = [