diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e321e6d..3043833 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,6 +92,39 @@ jobs: run: | pytest -v tests + test-without-wgpu: + name: ${{ matrix.name }} without wgpu + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - name: Test py313 + os: ubuntu-latest + pyversion: '3.13' + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.pyversion }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.pyversion }} + - name: Install package and dev dependencies + run: | + python -m pip install --upgrade pip + pip install .[tests] + pip uninstall -y wgpu + rm -r rendercanvas + - name: Unit tests + run: | + python -c " + try: + import wgpu + raise RuntimeError('wgpu could be imported, but this is the no-wgpu test build') + except ImportError: + print('wgpu is (intentionally) not available') + " + pytest -v tests + test-examples-build: name: Test examples ${{ matrix.pyversion }} runs-on: ${{ matrix.os }} diff --git a/tests/test_context.py b/tests/test_context.py index 6a4b632..80bd2b8 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -1,12 +1,15 @@ import numpy as np -from rendercanvas.utils.bitmappresentadapter import BitmapPresentAdapter -from rendercanvas.utils.bitmaprenderingcontext import BitmapRenderingContext -from rendercanvas.offscreen import OffscreenRenderCanvas as ManualOffscreenRenderCanvas - from testutils import can_use_wgpu_lib, run_tests import pytest +from rendercanvas.offscreen import OffscreenRenderCanvas as ManualOffscreenRenderCanvas +from rendercanvas.utils.bitmaprenderingcontext import BitmapRenderingContext + +if can_use_wgpu_lib: + from rendercanvas.utils.bitmappresentadapter import BitmapPresentAdapter + + def get_test_bitmap(width, height): colors = [ (255, 0, 0, 255), diff --git a/tests/test_meta.py b/tests/test_meta.py index 78784b7..2ac9063 100644 --- a/tests/test_meta.py +++ b/tests/test_meta.py @@ -77,6 +77,7 @@ def test_namespace(): def test_deps_plain_import(): modules = get_loaded_modules("rendercanvas", 1) assert modules == {"rendercanvas", "sniffio"} + # Note, no wgpu @pytest.mark.skipif(sys.version_info < (3, 10), reason="Need py310+") diff --git a/tests/testutils.py b/tests/testutils.py index 79027b2..219d57b 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -5,8 +5,6 @@ import subprocess from io import StringIO -import wgpu - class LogCaptureHandler(logging.StreamHandler): _ANSI_ESCAPE_SEQ = re.compile(r"\x1b\[[\d;]+m") @@ -62,6 +60,10 @@ def run_tests(scope): def get_default_adapter_summary(): """Get description of adapter, or None when no adapter is available.""" + try: + import wgpu + except ImportError: + return None # wgpu not installed try: adapter = wgpu.gpu.request_adapter_sync() except RuntimeError: