From e67cd362a69958b9e5a77ffc64186db97c608db9 Mon Sep 17 00:00:00 2001 From: Jon Carifio Date: Sat, 9 Sep 2023 02:25:29 -0400 Subject: [PATCH] Add tests for bqplot exporters and make codestyle fixes. --- glue_plotly/html_exporters/bqplot/base.py | 1 - .../html_exporters/bqplot/tests/__init__.py | 0 .../html_exporters/bqplot/tests/base.py | 33 +++++++++++++++++++ .../bqplot/tests/test_histogram.py | 15 +++++++++ .../html_exporters/bqplot/tests/test_image.py | 15 +++++++++ .../bqplot/tests/test_profile.py | 15 +++++++++ .../bqplot/tests/test_scatter2d.py | 13 ++++++++ glue_plotly/html_exporters/qt/tests/base.py | 1 - .../html_exporters/qt/tests/test_profile.py | 6 ++-- 9 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 glue_plotly/html_exporters/bqplot/tests/__init__.py create mode 100644 glue_plotly/html_exporters/bqplot/tests/base.py create mode 100644 glue_plotly/html_exporters/bqplot/tests/test_histogram.py create mode 100644 glue_plotly/html_exporters/bqplot/tests/test_image.py create mode 100644 glue_plotly/html_exporters/bqplot/tests/test_profile.py create mode 100644 glue_plotly/html_exporters/bqplot/tests/test_scatter2d.py diff --git a/glue_plotly/html_exporters/bqplot/base.py b/glue_plotly/html_exporters/bqplot/base.py index aca96c7..fe05e96 100644 --- a/glue_plotly/html_exporters/bqplot/base.py +++ b/glue_plotly/html_exporters/bqplot/base.py @@ -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 diff --git a/glue_plotly/html_exporters/bqplot/tests/__init__.py b/glue_plotly/html_exporters/bqplot/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/glue_plotly/html_exporters/bqplot/tests/base.py b/glue_plotly/html_exporters/bqplot/tests/base.py new file mode 100644 index 0000000..387c42a --- /dev/null +++ b/glue_plotly/html_exporters/bqplot/tests/base.py @@ -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() diff --git a/glue_plotly/html_exporters/bqplot/tests/test_histogram.py b/glue_plotly/html_exporters/bqplot/tests/test_histogram.py new file mode 100644 index 0000000..8adafdb --- /dev/null +++ b/glue_plotly/html_exporters/bqplot/tests/test_histogram.py @@ -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') diff --git a/glue_plotly/html_exporters/bqplot/tests/test_image.py b/glue_plotly/html_exporters/bqplot/tests/test_image.py new file mode 100644 index 0000000..96fe5df --- /dev/null +++ b/glue_plotly/html_exporters/bqplot/tests/test_image.py @@ -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))) diff --git a/glue_plotly/html_exporters/bqplot/tests/test_profile.py b/glue_plotly/html_exporters/bqplot/tests/test_profile.py new file mode 100644 index 0000000..4a55c5e --- /dev/null +++ b/glue_plotly/html_exporters/bqplot/tests/test_profile.py @@ -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') diff --git a/glue_plotly/html_exporters/bqplot/tests/test_scatter2d.py b/glue_plotly/html_exporters/bqplot/tests/test_scatter2d.py new file mode 100644 index 0000000..9a12d5a --- /dev/null +++ b/glue_plotly/html_exporters/bqplot/tests/test_scatter2d.py @@ -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') diff --git a/glue_plotly/html_exporters/qt/tests/base.py b/glue_plotly/html_exporters/qt/tests/base.py index a1e7475..60d2d55 100644 --- a/glue_plotly/html_exporters/qt/tests/base.py +++ b/glue_plotly/html_exporters/qt/tests/base.py @@ -53,4 +53,3 @@ def test_default(self, tmpdir): def make_data(self): raise NotImplementedError() - diff --git a/glue_plotly/html_exporters/qt/tests/test_profile.py b/glue_plotly/html_exporters/qt/tests/test_profile.py index 8db5dc2..593f738 100644 --- a/glue_plotly/html_exporters/qt/tests/test_profile.py +++ b/glue_plotly/html_exporters/qt/tests/test_profile.py @@ -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)