Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_export_html and run it on CI #275

Merged
merged 5 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")