From d747cbefbcb43de7a03f13bf4a4079f35a607231 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca <14138589+paskino@users.noreply.github.com> Date: Mon, 30 Jun 2025 16:45:18 +0100 Subject: [PATCH 1/2] use offscreen rendering in VTK unit tests --- .github/workflows/docker_build_test_publish.yml | 2 +- Wrappers/Python/test/test_CILViewer3D.py | 9 ++++----- Wrappers/Python/test/test_CILViewerBase.py | 9 ++++----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/docker_build_test_publish.yml b/.github/workflows/docker_build_test_publish.yml index 264d11a3..88eccd3d 100644 --- a/.github/workflows/docker_build_test_publish.yml +++ b/.github/workflows/docker_build_test_publish.yml @@ -33,5 +33,5 @@ jobs: - name: Run docker container with tests shell: bash -l {0} run: | - docker run --rm --entrypoint /bin/bash -v /home/runner/work/CILViewer/CILViewer:/root/source_code cil-viewer -c "source ./mambaforge/etc/profile.d/conda.sh && conda activate cilviewer_webapp && conda install cil-data pytest pyside2 eqt>=1.0.0 -c ccpi && python -m pytest /root/source_code/Wrappers/Python -k 'not test_version and not test_cli_resample and not test_CILViewerBase and not test_CILViewer3D and not test_viewer_main_windows and not test_ui_dialogs'" + docker run --rm --entrypoint /bin/bash -v /home/runner/work/CILViewer/CILViewer:/root/source_code cil-viewer -c "source ./mambaforge/etc/profile.d/conda.sh && conda activate cilviewer_webapp && conda install cil-data pytest pyside2 eqt>=1.0.0 -c ccpi && python -m pytest /root/source_code/Wrappers/Python -k 'not test_version and not test_cli_resample and not test_viewer_main_windows and not test_ui_dialogs'" # TODO: publish to come later diff --git a/Wrappers/Python/test/test_CILViewer3D.py b/Wrappers/Python/test/test_CILViewer3D.py index 1a6aa496..9e561e73 100644 --- a/Wrappers/Python/test/test_CILViewer3D.py +++ b/Wrappers/Python/test/test_CILViewer3D.py @@ -20,11 +20,9 @@ from ccpi.viewer.CILViewer import CILViewer -# skip the tests on GitHub actions -if os.environ.get('CONDA_BUILD', '0') == '1': - skip_test = True -else: - skip_test = False +from vtkmodules.vtkRenderingCore import vtkGraphicsFactory + +skip_test = False print("skip_test is set to ", skip_test) @@ -33,6 +31,7 @@ class CILViewer3DTest(unittest.TestCase): def setUp(self): + vgf = vtkGraphicsFactory(off_screen_only_mode=True, use_mesa_classes=True) self.cil_viewer = CILViewer() def test_getGradientOpacityPercentiles_returns_correct_percentiles_when_image_values_start_at_zero(self): diff --git a/Wrappers/Python/test/test_CILViewerBase.py b/Wrappers/Python/test/test_CILViewerBase.py index 75022588..88bb5ce4 100644 --- a/Wrappers/Python/test/test_CILViewerBase.py +++ b/Wrappers/Python/test/test_CILViewerBase.py @@ -19,12 +19,9 @@ import os from ccpi.viewer.CILViewer import CILViewerBase +from vtkmodules.vtkRenderingCore import vtkGraphicsFactory -# skip the tests on GitHub actions -if os.environ.get('CONDA_BUILD', '0') == '1': - skip_test = True -else: - skip_test = False +skip_test = False print("skip_test is set to ", skip_test) @@ -34,6 +31,7 @@ class CILViewerBaseTest(unittest.TestCase): def setUp(self): '''Creates an instance of the CIL viewer base class.''' + vgf = vtkGraphicsFactory(off_screen_only_mode=True, use_mesa_classes=True) self.CILViewerBase_instance = CILViewerBase() def test_setAxisLabels(self): @@ -56,6 +54,7 @@ def test_setAxisLabels(self): class CILViewer3DTest(unittest.TestCase): def setUp(self): + vgf = vtkGraphicsFactory(off_screen_only_mode=True, use_mesa_classes=True) self.cil_viewer = CILViewerBase() def test_getSliceColorPercentiles_returns_correct_percentiles_when_slice_values_start_at_zero(self): From 0484d2c4919d56cda4d0b2b5d7eb3c052c4f6dd5 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca <14138589+paskino@users.noreply.github.com> Date: Mon, 30 Jun 2025 16:54:17 +0100 Subject: [PATCH 2/2] adapt for older versions of VTK --- Wrappers/Python/test/test_CILViewer3D.py | 5 ++++- Wrappers/Python/test/test_CILViewerBase.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Wrappers/Python/test/test_CILViewer3D.py b/Wrappers/Python/test/test_CILViewer3D.py index 9e561e73..d5dc2725 100644 --- a/Wrappers/Python/test/test_CILViewer3D.py +++ b/Wrappers/Python/test/test_CILViewer3D.py @@ -31,7 +31,10 @@ class CILViewer3DTest(unittest.TestCase): def setUp(self): - vgf = vtkGraphicsFactory(off_screen_only_mode=True, use_mesa_classes=True) + vgf = vtkGraphicsFactory() + vgf.SetOffScreenOnlyMode(True) + vgf.SetUseMesaClasses(True) + self.vgf = vgf self.cil_viewer = CILViewer() def test_getGradientOpacityPercentiles_returns_correct_percentiles_when_image_values_start_at_zero(self): diff --git a/Wrappers/Python/test/test_CILViewerBase.py b/Wrappers/Python/test/test_CILViewerBase.py index 88bb5ce4..8ee57663 100644 --- a/Wrappers/Python/test/test_CILViewerBase.py +++ b/Wrappers/Python/test/test_CILViewerBase.py @@ -31,7 +31,10 @@ class CILViewerBaseTest(unittest.TestCase): def setUp(self): '''Creates an instance of the CIL viewer base class.''' - vgf = vtkGraphicsFactory(off_screen_only_mode=True, use_mesa_classes=True) + vgf = vtkGraphicsFactory() + vgf.SetOffScreenOnlyMode(True) + vgf.SetUseMesaClasses(True) + self.vgf = vgf self.CILViewerBase_instance = CILViewerBase() def test_setAxisLabels(self):