From 808730e3273dd561d077ca9f9949aa44b2bc9a5d Mon Sep 17 00:00:00 2001 From: Jon Carifio Date: Sat, 9 Sep 2023 13:22:58 -0400 Subject: [PATCH] Refactoring of exporter tests and updates to package data. --- glue_plotly/__init__.py | 5 +- glue_plotly/html_exporters/bqplot/base.py | 4 +- glue_plotly/html_exporters/bqplot/image.py | 2 +- .../bqplot/tests/{base.py => test_base.py} | 9 +--- .../bqplot/tests/test_histogram.py | 10 +++- .../html_exporters/bqplot/tests/test_image.py | 12 +++-- .../bqplot/tests/test_profile.py | 10 +++- .../bqplot/tests/test_scatter2d.py | 10 +++- glue_plotly/html_exporters/qt/dendrogram.py | 4 +- glue_plotly/html_exporters/qt/histogram.py | 4 +- glue_plotly/html_exporters/qt/image.py | 4 +- glue_plotly/html_exporters/qt/profile.py | 4 +- glue_plotly/html_exporters/qt/scatter2d.py | 4 +- glue_plotly/html_exporters/qt/scatter3d.py | 4 +- glue_plotly/html_exporters/qt/table.py | 4 +- .../qt/tests/{base.py => test_base.py} | 21 ++++---- .../qt/tests/test_dendrogram.py | 8 ++- .../html_exporters/qt/tests/test_histogram.py | 15 +++--- .../html_exporters/qt/tests/test_image.py | 10 +++- .../html_exporters/qt/tests/test_profile.py | 8 ++- .../html_exporters/qt/tests/test_scatter2d.py | 44 +++------------ .../html_exporters/qt/tests/test_scatter3d.py | 53 +++---------------- .../html_exporters/qt/tests/test_table.py | 41 +++----------- setup.cfg | 3 +- 24 files changed, 117 insertions(+), 176 deletions(-) rename glue_plotly/html_exporters/bqplot/tests/{base.py => test_base.py} (72%) rename glue_plotly/html_exporters/qt/tests/{base.py => test_base.py} (72%) diff --git a/glue_plotly/__init__.py b/glue_plotly/__init__.py index cc35ef3..5c907a8 100644 --- a/glue_plotly/__init__.py +++ b/glue_plotly/__init__.py @@ -8,8 +8,7 @@ pass -PLOTLY_LOGO_PNG = os.path.abspath(os.path.join(os.path.dirname(__file__), 'logo')) -PLOTLY_LOGO_SVG = os.path.abspath(os.path.join(os.path.dirname(__file__), 'logo.svg')) +PLOTLY_LOGO = os.path.abspath(os.path.join(os.path.dirname(__file__), 'logo')) PLOTLY_ERROR_MESSAGE = "An error occurred during the export to Plotly:" @@ -85,6 +84,6 @@ def setup_jupyter(): from glue_jupyter.bqplot.scatter import BqplotScatterView BqplotHistogramView.tools += ['save:bqplot_plotlyhist'] - BqplotImageView.tools += ['save:bqplot_plotlyimage'] + BqplotImageView.tools += ['save:bqplot_plotlyimage2d'] BqplotProfileView.tools += ['save:bqplot_plotlyprofile'] BqplotScatterView.tools += ['save:bqplot_plotly2d'] diff --git a/glue_plotly/html_exporters/bqplot/base.py b/glue_plotly/html_exporters/bqplot/base.py index fe05e96..59bce88 100644 --- a/glue_plotly/html_exporters/bqplot/base.py +++ b/glue_plotly/html_exporters/bqplot/base.py @@ -8,11 +8,11 @@ from IPython.display import display from ipyfilechooser import FileChooser -from glue_plotly import PLOTLY_LOGO_SVG +from glue_plotly import PLOTLY_LOGO class PlotlyBaseBqplotExport(Tool): - icon = PLOTLY_LOGO_SVG + icon = PLOTLY_LOGO action_text = 'Save Plotly HTML page' tool_tip = 'Save Plotly HTML page' diff --git a/glue_plotly/html_exporters/bqplot/image.py b/glue_plotly/html_exporters/bqplot/image.py index 02e43cb..df5bfcc 100644 --- a/glue_plotly/html_exporters/bqplot/image.py +++ b/glue_plotly/html_exporters/bqplot/image.py @@ -12,7 +12,7 @@ @viewer_tool class PlotlyImageBqplotExport(PlotlyBaseBqplotExport): - tool_id = 'save:bqplot_plotlyimage' + tool_id = 'save:bqplot_plotlyimage2d' def save_figure(self, filepath): diff --git a/glue_plotly/html_exporters/bqplot/tests/base.py b/glue_plotly/html_exporters/bqplot/tests/test_base.py similarity index 72% rename from glue_plotly/html_exporters/bqplot/tests/base.py rename to glue_plotly/html_exporters/bqplot/tests/test_base.py index 387c42a..201fb8d 100644 --- a/glue_plotly/html_exporters/bqplot/tests/base.py +++ b/glue_plotly/html_exporters/bqplot/tests/test_base.py @@ -22,12 +22,5 @@ def teardown_method(self, method): def export_figure(self, tmpdir, output_filename): output_path = tmpdir.join(output_filename).strpath - self.viewer.save_figure(output_path) + self.tool.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 index 8adafdb..8afbba1 100644 --- a/glue_plotly/html_exporters/bqplot/tests/test_histogram.py +++ b/glue_plotly/html_exporters/bqplot/tests/test_histogram.py @@ -1,7 +1,9 @@ +import os + from glue.core import Data from glue_jupyter.bqplot.histogram import BqplotHistogramView -from .base import TestBqplotExporter +from .test_base import TestBqplotExporter class TestHistogram(TestBqplotExporter): @@ -9,7 +11,11 @@ class TestHistogram(TestBqplotExporter): viewer_type = BqplotHistogramView tool_id = 'save:bqplot_plotlyhist' - def make_data(self): + def test_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') + + def test_default(self, tmpdir): + output_path = self.export_figure(tmpdir, 'test_default.html') + assert os.path.exists(output_path) diff --git a/glue_plotly/html_exporters/bqplot/tests/test_image.py b/glue_plotly/html_exporters/bqplot/tests/test_image.py index 96fe5df..947c56e 100644 --- a/glue_plotly/html_exporters/bqplot/tests/test_image.py +++ b/glue_plotly/html_exporters/bqplot/tests/test_image.py @@ -1,15 +1,21 @@ +import os + from glue.core import Data from glue_jupyter.bqplot.image import BqplotImageView from numpy import arange, ones -from .base import TestBqplotExporter +from .test_base import TestBqplotExporter class TestImage(TestBqplotExporter): viewer_type = BqplotImageView - tool_id = 'save:bqplot_plotlyimage' + tool_id = 'save:bqplot_plotlyimage2d' - def make_data(self): + def test_data(self): return Data(label='d1', x=arange(24).reshape((2, 3, 4)), y=ones((2, 3, 4))) + + def test_default(self, tmpdir): + output_path = self.export_figure(tmpdir, 'test_default.html') + assert os.path.exists(output_path) diff --git a/glue_plotly/html_exporters/bqplot/tests/test_profile.py b/glue_plotly/html_exporters/bqplot/tests/test_profile.py index 4a55c5e..1139ea6 100644 --- a/glue_plotly/html_exporters/bqplot/tests/test_profile.py +++ b/glue_plotly/html_exporters/bqplot/tests/test_profile.py @@ -1,7 +1,9 @@ +import os + from glue.core import Data from glue_jupyter.bqplot.profile import BqplotProfileView -from .base import TestBqplotExporter +from .test_base import TestBqplotExporter class TestProfile(TestBqplotExporter): @@ -9,7 +11,11 @@ class TestProfile(TestBqplotExporter): viewer_type = BqplotProfileView tool_id = 'save:bqplot_plotlyprofile' - def make_data(self): + def test_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') + + def test_default(self, tmpdir): + output_path = self.export_figure(tmpdir, 'test_default.html') + assert os.path.exists(output_path) diff --git a/glue_plotly/html_exporters/bqplot/tests/test_scatter2d.py b/glue_plotly/html_exporters/bqplot/tests/test_scatter2d.py index 9a12d5a..2833402 100644 --- a/glue_plotly/html_exporters/bqplot/tests/test_scatter2d.py +++ b/glue_plotly/html_exporters/bqplot/tests/test_scatter2d.py @@ -1,7 +1,9 @@ +import os + from glue.core import Data from glue_jupyter.bqplot.scatter import BqplotScatterView -from .base import TestBqplotExporter +from .test_base import TestBqplotExporter class TestScatter2D(TestBqplotExporter): @@ -9,5 +11,9 @@ class TestScatter2D(TestBqplotExporter): viewer_type = BqplotScatterView tool_id = 'save:bqplot_plotly2d' - def make_data(self): + def test_data(self): return Data(x=[1, 2, 3], y=[4, 5, 6], z=[7, 8, 9], label='d1') + + def test_default(self, tmpdir): + output_path = self.export_figure(tmpdir, 'test_default.html') + assert os.path.exists(output_path) diff --git a/glue_plotly/html_exporters/qt/dendrogram.py b/glue_plotly/html_exporters/qt/dendrogram.py index 139e5ad..71df121 100644 --- a/glue_plotly/html_exporters/qt/dendrogram.py +++ b/glue_plotly/html_exporters/qt/dendrogram.py @@ -4,7 +4,7 @@ from glue_qt.viewers.common.tool import Tool from glue_qt.utils import messagebox_on_error -from glue_plotly import PLOTLY_ERROR_MESSAGE, PLOTLY_LOGO_PNG +from glue_plotly import PLOTLY_ERROR_MESSAGE, PLOTLY_LOGO from glue_plotly.common import data_count, layers_to_export from glue_plotly.common.dendrogram import layout_config_from_mpl, trace_for_layer @@ -14,7 +14,7 @@ @viewer_tool class PlotlyDendrogramStaticExport(Tool): - icon = PLOTLY_LOGO_PNG + icon = PLOTLY_LOGO tool_id = 'save:plotlydendro' action_text = 'Save Plotly HTML page' tool_tip = 'Save Plotly HTML page' diff --git a/glue_plotly/html_exporters/qt/histogram.py b/glue_plotly/html_exporters/qt/histogram.py index b79174b..ff5c74a 100644 --- a/glue_plotly/html_exporters/qt/histogram.py +++ b/glue_plotly/html_exporters/qt/histogram.py @@ -5,7 +5,7 @@ from glue_qt.utils import messagebox_on_error from glue_qt.viewers.common.tool import Tool -from glue_plotly import PLOTLY_ERROR_MESSAGE, PLOTLY_LOGO_PNG +from glue_plotly import PLOTLY_ERROR_MESSAGE, PLOTLY_LOGO from glue_plotly.common import data_count, layers_to_export from glue_plotly.common.histogram import layout_config_from_mpl, traces_for_layer @@ -17,7 +17,7 @@ @viewer_tool class PlotlyHistogram1DExport(Tool): - icon = PLOTLY_LOGO_PNG + icon = PLOTLY_LOGO tool_id = 'save:plotlyhist' action_text = 'Save Plotly HTML page' tool_tip = 'Save Plotly HTML page' diff --git a/glue_plotly/html_exporters/qt/image.py b/glue_plotly/html_exporters/qt/image.py index d329446..b047da3 100644 --- a/glue_plotly/html_exporters/qt/image.py +++ b/glue_plotly/html_exporters/qt/image.py @@ -13,7 +13,7 @@ from ... import save_hover, export_dialog -from glue_plotly import PLOTLY_ERROR_MESSAGE, PLOTLY_LOGO_PNG +from glue_plotly import PLOTLY_ERROR_MESSAGE, PLOTLY_LOGO from glue_plotly.common import data_count, layers_to_export from glue_plotly.common.image import axes_data_from_mpl, layers_by_type, layout_config, traces @@ -26,7 +26,7 @@ @viewer_tool class PlotlyImage2DExport(Tool): - icon = PLOTLY_LOGO_PNG + icon = PLOTLY_LOGO tool_id = 'save:plotlyimage2d' action_text = 'Save Plotly HTML page' tool_tip = 'Save Plotly HTML page' diff --git a/glue_plotly/html_exporters/qt/profile.py b/glue_plotly/html_exporters/qt/profile.py index 6f96476..1c619e8 100644 --- a/glue_plotly/html_exporters/qt/profile.py +++ b/glue_plotly/html_exporters/qt/profile.py @@ -4,7 +4,7 @@ from glue.config import viewer_tool from glue_qt.viewers.common.tool import Tool -from glue_plotly import PLOTLY_LOGO_PNG +from glue_plotly import PLOTLY_LOGO from glue_plotly.common import data_count, layers_to_export from glue_plotly.common.profile import layout_config_from_mpl, traces_for_layer @@ -16,7 +16,7 @@ @viewer_tool class PlotlyProfile1DExport(Tool): - icon = PLOTLY_LOGO_PNG + icon = PLOTLY_LOGO tool_id = 'save:plotlyprofile' action_text = 'Save Plotly HTML page' tool_tip = 'Save Plotly HTML page' diff --git a/glue_plotly/html_exporters/qt/scatter2d.py b/glue_plotly/html_exporters/qt/scatter2d.py index 6ead9bc..93a2c12 100644 --- a/glue_plotly/html_exporters/qt/scatter2d.py +++ b/glue_plotly/html_exporters/qt/scatter2d.py @@ -13,7 +13,7 @@ from ... import save_hover -from glue_plotly import PLOTLY_ERROR_MESSAGE, PLOTLY_LOGO_PNG +from glue_plotly import PLOTLY_ERROR_MESSAGE, PLOTLY_LOGO from glue_plotly.common import data_count, layers_to_export from glue_plotly.common.scatter2d import polar_layout_config_from_mpl, rectilinear_layout_config, \ traces_for_layer @@ -29,7 +29,7 @@ @viewer_tool class PlotlyScatter2DStaticExport(Tool): - icon = PLOTLY_LOGO_PNG + icon = PLOTLY_LOGO tool_id = 'save:plotly2d' action_text = 'Save Plotly HTML page' tool_tip = 'Save Plotly HTML page' diff --git a/glue_plotly/html_exporters/qt/scatter3d.py b/glue_plotly/html_exporters/qt/scatter3d.py index 2b23934..8faffa2 100644 --- a/glue_plotly/html_exporters/qt/scatter3d.py +++ b/glue_plotly/html_exporters/qt/scatter3d.py @@ -12,7 +12,7 @@ from glue_qt.utils.threading import Worker from glue_qt.viewers.common.tool import Tool -from glue_plotly import PLOTLY_ERROR_MESSAGE, PLOTLY_LOGO_PNG +from glue_plotly import PLOTLY_ERROR_MESSAGE, PLOTLY_LOGO from glue_plotly.common import data_count, layers_to_export from glue_plotly.common.scatter3d import layout_config, traces_for_layer from ... import save_hover, export_dialog @@ -26,7 +26,7 @@ @viewer_tool class PlotlyScatter3DStaticExport(Tool): - icon = PLOTLY_LOGO_PNG + icon = PLOTLY_LOGO tool_id = 'save:plotly3d' action_text = 'Save Plotly HTML page' tool_tip = 'Save Plotly HTML page' diff --git a/glue_plotly/html_exporters/qt/table.py b/glue_plotly/html_exporters/qt/table.py index 933eb47..096b530 100644 --- a/glue_plotly/html_exporters/qt/table.py +++ b/glue_plotly/html_exporters/qt/table.py @@ -4,7 +4,7 @@ from glue.core import BaseData from glue_qt.viewers.common.tool import Tool -from glue_plotly import PLOTLY_LOGO_PNG +from glue_plotly import PLOTLY_LOGO from qtpy import compat from qtpy.QtCore import Qt @@ -24,7 +24,7 @@ @viewer_tool class PlotlyTableExport(Tool): - icon = PLOTLY_LOGO_PNG + icon = PLOTLY_LOGO tool_id = 'save:plotlytable' action_text = 'Save Plotly HTML page' tool_tip = 'Save Plotly HTML page' diff --git a/glue_plotly/html_exporters/qt/tests/base.py b/glue_plotly/html_exporters/qt/tests/test_base.py similarity index 72% rename from glue_plotly/html_exporters/qt/tests/base.py rename to glue_plotly/html_exporters/qt/tests/test_base.py index 60d2d55..8d41f37 100644 --- a/glue_plotly/html_exporters/qt/tests/base.py +++ b/glue_plotly/html_exporters/qt/tests/test_base.py @@ -1,15 +1,16 @@ -import os - from mock import patch from glue_qt.app import GlueApplication +from glue_plotly.save_hover import SaveHoverDialog +from glue_plotly.sort_components import SortComponentsDialog +from qtpy.QtWidgets import QMessageBox class TestQtExporter: viewer_type = None tool_id = None - + def setup_method(self, method): self.data = self.make_data() self.app = GlueApplication() @@ -29,7 +30,7 @@ def teardown_method(self, method): self.app.close() self.app = None - def auto_accept_hoverdialog(self): + def auto_accept_selectdialog(self): def exec_replacement(dialog): dialog.select_all() dialog.accept() @@ -44,12 +45,8 @@ def export_figure(self, tmpdir, output_filename): output_path = tmpdir.join(output_filename).strpath with patch('qtpy.compat.getsavefilename') as fd: fd.return_value = output_path, 'html' - self.tool.activate() + with patch.object(SaveHoverDialog, 'exec_', self.auto_accept_selectdialog()), \ + patch.object(SortComponentsDialog, 'exec_', self.auto_accept_selectdialog()), \ + patch.object(QMessageBox, 'exec_', self.auto_accept_messagebox()): + self.tool.activate() 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/qt/tests/test_dendrogram.py b/glue_plotly/html_exporters/qt/tests/test_dendrogram.py index 61a5a2b..4452f4f 100644 --- a/glue_plotly/html_exporters/qt/tests/test_dendrogram.py +++ b/glue_plotly/html_exporters/qt/tests/test_dendrogram.py @@ -1,7 +1,9 @@ +import os + from glue.core import Data from glue_qt.plugins.dendro_viewer.data_viewer import DendrogramViewer -from .base import TestQtExporter +from .test_base import TestQtExporter class TestDendrogram(TestQtExporter): @@ -11,3 +13,7 @@ class TestDendrogram(TestQtExporter): def make_data(self): return Data(label='dendrogram', parent=[-1, 0, 1, 1], height=[1.3, 2.2, 3.2, 4.4]) + + def test_default(self, tmpdir): + output_path = self.export_figure(tmpdir, 'test_default.html') + assert os.path.exists(output_path) diff --git a/glue_plotly/html_exporters/qt/tests/test_histogram.py b/glue_plotly/html_exporters/qt/tests/test_histogram.py index 8c84d71..2b5d8cb 100644 --- a/glue_plotly/html_exporters/qt/tests/test_histogram.py +++ b/glue_plotly/html_exporters/qt/tests/test_histogram.py @@ -1,7 +1,9 @@ +import os + from glue.core import Data from glue_qt.viewers.histogram import HistogramViewer -from .base import TestQtExporter +from .test_base import TestQtExporter class TestHistogram(TestQtExporter): @@ -9,12 +11,13 @@ class TestHistogram(TestQtExporter): viewer_type = HistogramViewer tool_id = 'save:plotlyhist' - def setup_method(self, method): - super().setup_method(method) - self.viewer.state.x_att = self.data.id['x'] - self.viewer.state.hist_n_bin = 6 - 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') + + def test_default(self, tmpdir): + self.viewer.state.x_att = self.data.id['x'] + self.viewer.state.hist_n_bin = 6 + output_path = self.export_figure(tmpdir, 'test_default.html') + assert os.path.exists(output_path) diff --git a/glue_plotly/html_exporters/qt/tests/test_image.py b/glue_plotly/html_exporters/qt/tests/test_image.py index b602574..cc4315a 100644 --- a/glue_plotly/html_exporters/qt/tests/test_image.py +++ b/glue_plotly/html_exporters/qt/tests/test_image.py @@ -1,15 +1,21 @@ +import os + from glue.core import Data from glue_qt.viewers.image.data_viewer import ImageViewer from numpy import arange, ones -from .base import TestQtExporter +from .test_base import TestQtExporter class TestImage(TestQtExporter): viewer_type = ImageViewer - tool_id = 'save:plotlyimage' + tool_id = 'save:plotlyimage2d' def make_data(self): return Data(label='d1', x=arange(24).reshape((2, 3, 4)), y=ones((2, 3, 4))) + + def test_default(self, tmpdir): + output_path = self.export_figure(tmpdir, 'test.html') + assert os.path.exists(output_path) diff --git a/glue_plotly/html_exporters/qt/tests/test_profile.py b/glue_plotly/html_exporters/qt/tests/test_profile.py index 593f738..cfc5c7c 100644 --- a/glue_plotly/html_exporters/qt/tests/test_profile.py +++ b/glue_plotly/html_exporters/qt/tests/test_profile.py @@ -1,7 +1,9 @@ +import os + from glue.core import Data from glue_qt.viewers.profile import ProfileViewer -from .base import TestQtExporter +from .test_base import TestQtExporter class TestProfile(TestQtExporter): @@ -17,3 +19,7 @@ def make_data(self): def setup_method(self, method): super().setup_method(method) self.viewer.state.x_att = self.data.id['Pixel Axis 0 [x]'] + + def test_default(self, tmpdir): + output_path = self.export_figure(tmpdir, 'test.html') + assert os.path.exists(output_path) diff --git a/glue_plotly/html_exporters/qt/tests/test_scatter2d.py b/glue_plotly/html_exporters/qt/tests/test_scatter2d.py index 30da9f1..be8d2a8 100644 --- a/glue_plotly/html_exporters/qt/tests/test_scatter2d.py +++ b/glue_plotly/html_exporters/qt/tests/test_scatter2d.py @@ -1,50 +1,18 @@ -from __future__ import absolute_import, division, print_function - import os -from mock import patch - from glue.core import Data -from glue_qt.app import GlueApplication from glue_qt.viewers.scatter import ScatterViewer -from glue_plotly.save_hover import SaveHoverDialog - - -def auto_accept(): - def exec_replacement(self): - self.select_all() - self.accept() - return exec_replacement +from .test_base import TestQtExporter -class TestScatter2D: - def setup_method(self, method): - self.data = Data(x=[1, 2, 3], y=[4, 5, 6], z=[7, 8, 9], label='d1') - self.app = GlueApplication() - self.app.session.data_collection.append(self.data) - self.viewer = self.app.new_data_viewer(ScatterViewer) - self.viewer.add_data(self.data) - for subtool in self.viewer.toolbar.tools['save'].subtools: - if subtool.tool_id == 'save:plotly2d': - self.tool = subtool - break - else: - raise Exception("Could not find save:plotly2d tool in viewer") +class TestScatter2D(TestQtExporter): - def teardown_method(self, method): - self.viewer.close(warn=False) - self.viewer = None - self.app.close() - self.app = None + viewer_type = ScatterViewer + tool_id = 'save:plotly2d' - def export_figure(self, tmpdir, output_filename): - output_path = tmpdir.join(output_filename).strpath - with patch('qtpy.compat.getsavefilename') as fd: - fd.return_value = output_path, 'html' - with patch.object(SaveHoverDialog, 'exec_', auto_accept()): - self.tool.activate() - return output_path + def make_data(self): + return Data(x=[1, 2, 3], y=[4, 5, 6], z=[7, 8, 9], label='d1') def test_default(self, tmpdir): self.viewer.state.plot_mode = 'rectilinear' diff --git a/glue_plotly/html_exporters/qt/tests/test_scatter3d.py b/glue_plotly/html_exporters/qt/tests/test_scatter3d.py index bbf45a1..1f41945 100644 --- a/glue_plotly/html_exporters/qt/tests/test_scatter3d.py +++ b/glue_plotly/html_exporters/qt/tests/test_scatter3d.py @@ -1,61 +1,24 @@ -from __future__ import absolute_import, division, print_function - import os import pytest -from mock import patch from glue.core import Data -from glue_qt.app import GlueApplication -from glue_plotly.save_hover import SaveHoverDialog -from qtpy.QtWidgets import QMessageBox pytest.importorskip('glue_vispy_viewers') from glue_vispy_viewers.scatter.scatter_viewer import VispyScatterViewer # noqa - -def auto_accept_hoverdialog(): - def exec_replacement(self): - self.select_all() - self.accept() - - return exec_replacement - - -def auto_accept_messagebox(): - def exec_replacement(self): - self.accept() - - return exec_replacement +from .test_base import TestQtExporter -class TestScatter3D: +class TestScatter3D(TestQtExporter): - def setup_method(self, method): - self.data = Data(x=[1, 2, 3], y=[4, 5, 6], z=[7, 8, 9], label='d1') - self.app = GlueApplication() - self.app.session.data_collection.append(self.data) - self.viewer = self.app.new_data_viewer(VispyScatterViewer) - self.viewer.add_data(self.data) - for subtool in self.viewer.toolbar.tools['save'].subtools: - if subtool.tool_id == 'save:plotly3d': - self.tool = subtool - break - else: - raise Exception("Could not find save:plotly3d tool in viewer") + viewer_type = VispyScatterViewer + tool_id = 'save:plotly3d' - def teardown_method(self, method): - self.viewer.close(warn=False) - self.viewer = None - self.app.close() - self.app = None + def make_data(self): + return Data(x=[1, 2, 3], y=[4, 5, 6], z=[7, 8, 9], label='d1') def test_default(self, tmpdir): - output_file = tmpdir.join('test.html').strpath - with patch('qtpy.compat.getsavefilename') as fd: - fd.return_value = output_file, 'html' - with patch.object(SaveHoverDialog, 'exec_', auto_accept_hoverdialog()), \ - patch.object(QMessageBox, 'exec_', auto_accept_messagebox()): - self.tool.activate() - assert os.path.exists(output_file) + output_path = self.export_figure(tmpdir, 'test.html') + assert os.path.exists(output_path) diff --git a/glue_plotly/html_exporters/qt/tests/test_table.py b/glue_plotly/html_exporters/qt/tests/test_table.py index 61faff5..90a1183 100644 --- a/glue_plotly/html_exporters/qt/tests/test_table.py +++ b/glue_plotly/html_exporters/qt/tests/test_table.py @@ -1,50 +1,25 @@ import os -from mock import patch - from glue.core import Data from glue_qt.app import GlueApplication from glue_qt.viewers.table import TableViewer -from glue_plotly.sort_components import SortComponentsDialog -from qtpy.QtWidgets import QMessageBox - - -def auto_accept_sortdialog(): - def exec_replacement(self): - self.select_all() - self.accept() - return exec_replacement +from .test_base import TestQtExporter -def auto_accept_messagebox(): - def exec_replacement(self): - self.accept() +class TestTable(TestQtExporter): - return exec_replacement - - -class TestTable: + viewer_type = TableViewer + tool_id = 'save:plotlytable' def setup_method(self, method): self.data = Data(x=[1, 2, 3], y=[4, 5, 6], z=[7, 8, 9], label='d1') self.app = GlueApplication() self.app.session.data_collection.append(self.data) - self.viewer = self.app.new_data_viewer(TableViewer) + self.viewer = self.app.new_data_viewer(self.viewer_type) self.viewer.add_data(self.data) - self.tool = self.viewer.toolbar.tools['save:plotlytable'] - - def teardown_method(self, method): - self.viewer.close(warn=False) - self.viewer = None - self.app.close() - self.app = None + self.tool = self.viewer.toolbar.tools[self.tool_id] def test_default(self, tmpdir): - output_file = tmpdir.join('test.html').strpath - with patch('qtpy.compat.getsavefilename') as fd: - fd.return_value = output_file, 'html' - with patch.object(SortComponentsDialog, 'exec_', auto_accept_sortdialog()), \ - patch.object(QMessageBox, 'exec_', auto_accept_messagebox()): - self.tool.activate() - assert os.path.exists(output_file) + output_path = self.export_figure(tmpdir, 'test.html') + assert os.path.exists(output_path) diff --git a/setup.cfg b/setup.cfg index 747ee49..fad8bb4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,9 +31,10 @@ qt = jupyter = glue-jupyter ipyvuetify + ipyfilechooser [options.package_data] -* = *.png, *.ui +* = *.png, *.svg, *.ui [options.entry_points] glue.plugins =