From 49817bd3bc6575e77174d53f7d542e9f34444e3b Mon Sep 17 00:00:00 2001 From: Alessandro Felder Date: Wed, 15 Nov 2023 10:20:16 +0000 Subject: [PATCH 1/4] use pyvista action for headless display in tox (#273) this might fix VTK failures in windows --- .github/workflows/test_and_deploy.yml | 3 +++ tox.ini | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/test_and_deploy.yml b/.github/workflows/test_and_deploy.yml index 2268ebf9..e76ed9b4 100644 --- a/.github/workflows/test_and_deploy.yml +++ b/.github/workflows/test_and_deploy.yml @@ -36,6 +36,9 @@ jobs: if: runner.os == 'macOS' run: brew install hdf5 + # Helps set up VTK with a headless display + - uses: pyvista/setup-headless-display-action@v2 + # Run tests - uses: neuroinformatics-unit/actions/test@v2 with: diff --git a/tox.ini b/tox.ini index 6a32366a..6fc1dafa 100644 --- a/tox.ini +++ b/tox.ini @@ -14,4 +14,9 @@ extras = commands = pytest -v --color=yes --cov=brainrender --cov-report=xml passenv = + CI + GITHUB_ACTIONS DISPLAY + XAUTHORITY + NUMPY_EXPERIMENTAL_ARRAY_FUNCTION + PYVISTA_OFF_SCREEN From 1f2067c6db88d84b5e37eb4801919ee0c656285d Mon Sep 17 00:00:00 2001 From: Alessandro Felder Date: Wed, 15 Nov 2023 16:12:56 +0000 Subject: [PATCH 2/4] Fix `test_export_html` and run it on CI (#275) --- brainrender/render.py | 6 +++--- tests/test_export_html.py | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/brainrender/render.py b/brainrender/render.py index b2dcc0d1..a7d91408 100644 --- a/brainrender/render.py +++ b/brainrender/render.py @@ -289,6 +289,7 @@ def export(self, savepath): """ logger.debug(f"Exporting scene to {savepath}") _backend = self.backend + _default_backend = vsettings.default_backend if not self.is_rendered: self.render(interactive=False) @@ -302,9 +303,8 @@ def export(self, savepath): # Create new plotter and save to file plt = Plotter() - plt.add(self.clean_renderables, render=False) + plt.add(self.clean_renderables).render() plt = plt.show(interactive=False) - plt.camera[-2] = -1 with open(path, "w") as fp: fp.write(plt.get_snapshot()) @@ -314,7 +314,7 @@ def export(self, savepath): ) # Reset settings - vsettings.notebookBackend = None + vsettings.default_backend = _default_backend self.backend = _backend return str(path) diff --git a/tests/test_export_html.py b/tests/test_export_html.py index 4ac5cc4e..70ca54b5 100644 --- a/tests/test_export_html.py +++ b/tests/test_export_html.py @@ -5,15 +5,18 @@ from brainrender import Scene -@pytest.mark.local -def test_export_for_web(): +@pytest.fixture +def scene(): + """Provide a scene with a brain region""" s = Scene(title="BR") - th = s.add_brain_region("TH") - s.add_label(th, "TH") + return s - path = s.export("test.html") + +def test_export_for_web(scene): + """Check that exporting to html creates the expected file""" + path = scene.export("test.html") assert path == "test.html" path = Path(path) @@ -21,5 +24,8 @@ def test_export_for_web(): path.unlink() + +def test_export_for_web_raises(scene): + """Check that exporting with invalid file extention raises ValueError""" with pytest.raises(ValueError): - path = s.export("test.py") + scene.export("test.py") From f0a0306de243d5801e653c75d52a2ac608f22933 Mon Sep 17 00:00:00 2001 From: alessandrofelder Date: Wed, 15 Nov 2023 17:08:41 +0000 Subject: [PATCH 3/4] run video tests on CI too --- .github/workflows/test_and_deploy.yml | 4 ++++ tests/test_video.py | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test_and_deploy.yml b/.github/workflows/test_and_deploy.yml index e76ed9b4..4956edd6 100644 --- a/.github/workflows/test_and_deploy.yml +++ b/.github/workflows/test_and_deploy.yml @@ -39,6 +39,10 @@ jobs: # Helps set up VTK with a headless display - uses: pyvista/setup-headless-display-action@v2 + # Sets up ffmpeg to we can run video tests on CI + - uses: FedericoCarboni/setup-ffmpeg@v2 + id: setup-ffmpeg + # Run tests - uses: neuroinformatics-unit/actions/test@v2 with: diff --git a/tests/test_video.py b/tests/test_video.py index a25934af..61a984fb 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -1,12 +1,9 @@ from pathlib import Path -import pytest - from brainrender.scene import Scene from brainrender.video import Animation, VideoMaker -@pytest.mark.local def test_video(): s = Scene(title="BR") @@ -21,7 +18,6 @@ def test_video(): path.unlink() -@pytest.mark.local def test_video_custom(): def custom(scene, *args, **kwargs): return @@ -40,7 +36,6 @@ def custom(scene, *args, **kwargs): path.unlink() -@pytest.mark.local def test_animation(): # Create a brainrender scene scene = Scene(title="brain regions", inset=False) From ebde5695e835429e57b896634e271ab8c1577277 Mon Sep 17 00:00:00 2001 From: alessandrofelder Date: Wed, 15 Nov 2023 17:14:46 +0000 Subject: [PATCH 4/4] Revert "run video tests on CI too" This reverts commit f0a0306de243d5801e653c75d52a2ac608f22933. Commit should have landed in `fix-video-test` branch! --- .github/workflows/test_and_deploy.yml | 4 ---- tests/test_video.py | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_and_deploy.yml b/.github/workflows/test_and_deploy.yml index 4956edd6..e76ed9b4 100644 --- a/.github/workflows/test_and_deploy.yml +++ b/.github/workflows/test_and_deploy.yml @@ -39,10 +39,6 @@ jobs: # Helps set up VTK with a headless display - uses: pyvista/setup-headless-display-action@v2 - # Sets up ffmpeg to we can run video tests on CI - - uses: FedericoCarboni/setup-ffmpeg@v2 - id: setup-ffmpeg - # Run tests - uses: neuroinformatics-unit/actions/test@v2 with: diff --git a/tests/test_video.py b/tests/test_video.py index 61a984fb..a25934af 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -1,9 +1,12 @@ from pathlib import Path +import pytest + from brainrender.scene import Scene from brainrender.video import Animation, VideoMaker +@pytest.mark.local def test_video(): s = Scene(title="BR") @@ -18,6 +21,7 @@ def test_video(): path.unlink() +@pytest.mark.local def test_video_custom(): def custom(scene, *args, **kwargs): return @@ -36,6 +40,7 @@ def custom(scene, *args, **kwargs): path.unlink() +@pytest.mark.local def test_animation(): # Create a brainrender scene scene = Scene(title="brain regions", inset=False)