Skip to content

Commit

Permalink
Fix test_export_html and run it on CI (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrofelder authored Nov 15, 2023
1 parent 49817bd commit 1f2067c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions brainrender/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
Expand All @@ -314,7 +314,7 @@ def export(self, savepath):
)

# Reset settings
vsettings.notebookBackend = None
vsettings.default_backend = _default_backend
self.backend = _backend

return str(path)
Expand Down
18 changes: 12 additions & 6 deletions tests/test_export_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@
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)
assert path.exists()

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")

0 comments on commit 1f2067c

Please sign in to comment.