Skip to content

Commit

Permalink
Add tests for bqplot exporters and make codestyle fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Sep 9, 2023
1 parent 2610699 commit e67cd36
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 5 deletions.
1 change: 0 additions & 1 deletion glue_plotly/html_exporters/bqplot/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from ipywidgets import HBox, Layout
from IPython.display import display
from ipyfilechooser import FileChooser
from pandas.io.formats.printing import justify

from glue_plotly import PLOTLY_LOGO_SVG

Expand Down
Empty file.
33 changes: 33 additions & 0 deletions glue_plotly/html_exporters/bqplot/tests/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os

from glue_jupyter import jglue


class TestBqplotExporter:

viewer_type = None
tool_id = None

def setup_method(self, method):
self.data = self.test_data()
self.app = jglue()
self.app.session.data_collection.append(self.data)
self.viewer = self.app.new_data_viewer(self.viewer_type)
self.viewer.add_data(self.data)
self.tool = self.viewer.toolbar.tools[self.tool_id]

def teardown_method(self, method):
self.viewer = None
self.app = None

def export_figure(self, tmpdir, output_filename):
output_path = tmpdir.join(output_filename).strpath
self.viewer.save_figure(output_path)
return output_path

def test_default(self, tmpdir):
output_path = self.export_figure(tmpdir, 'test_default.html')
assert os.path.exists(output_path)

def make_data(self):
raise NotImplementedError()
15 changes: 15 additions & 0 deletions glue_plotly/html_exporters/bqplot/tests/test_histogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from glue.core import Data
from glue_jupyter.bqplot.histogram import BqplotHistogramView

from .base import TestBqplotExporter


class TestHistogram(TestBqplotExporter):

viewer_type = BqplotHistogramView
tool_id = 'save:bqplot_plotlyhist'

def make_data(self):
return Data(x=[40, 41, 37, 63, 78, 35, 19, 100, 35, 86, 84, 99,
87, 56, 2, 71, 22, 36, 10, 1, 26, 70, 45, 20, 8],
label='d1')
15 changes: 15 additions & 0 deletions glue_plotly/html_exporters/bqplot/tests/test_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from glue.core import Data
from glue_jupyter.bqplot.image import BqplotImageView

from numpy import arange, ones

from .base import TestBqplotExporter


class TestImage(TestBqplotExporter):

viewer_type = BqplotImageView
tool_id = 'save:bqplot_plotlyimage'

def make_data(self):
return Data(label='d1', x=arange(24).reshape((2, 3, 4)), y=ones((2, 3, 4)))
15 changes: 15 additions & 0 deletions glue_plotly/html_exporters/bqplot/tests/test_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from glue.core import Data
from glue_jupyter.bqplot.profile import BqplotProfileView

from .base import TestBqplotExporter


class TestProfile(TestBqplotExporter):

viewer_type = BqplotProfileView
tool_id = 'save:bqplot_plotlyprofile'

def make_data(self):
return Data(x=[40, 41, 37, 63, 78, 35, 19, 100, 35, 86, 84, 99,
87, 56, 2, 71, 22, 36, 10, 1, 26, 70, 45, 20, 8],
label='d1')
13 changes: 13 additions & 0 deletions glue_plotly/html_exporters/bqplot/tests/test_scatter2d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from glue.core import Data
from glue_jupyter.bqplot.scatter import BqplotScatterView

from .base import TestBqplotExporter


class TestScatter2D(TestBqplotExporter):

viewer_type = BqplotScatterView
tool_id = 'save:bqplot_plotly2d'

def make_data(self):
return Data(x=[1, 2, 3], y=[4, 5, 6], z=[7, 8, 9], label='d1')
1 change: 0 additions & 1 deletion glue_plotly/html_exporters/qt/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ def test_default(self, tmpdir):

def make_data(self):
raise NotImplementedError()

6 changes: 3 additions & 3 deletions glue_plotly/html_exporters/qt/tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class TestProfile(TestQtExporter):
tool_id = 'save:plotlyprofile'

def make_data(self):
return Data(x=[40, 41, 37, 63, 78, 35, 19, 100, 35, 86, 84, 99,
87, 56, 2, 71, 22, 36, 10, 1, 26, 70, 45, 20, 8],
label='d1')
return Data(x=[40, 41, 37, 63, 78, 35, 19, 100, 35, 86, 84, 99,
87, 56, 2, 71, 22, 36, 10, 1, 26, 70, 45, 20, 8],
label='d1')

def setup_method(self, method):
super().setup_method(method)
Expand Down

0 comments on commit e67cd36

Please sign in to comment.