Skip to content

Commit

Permalink
Refactoring of exporter tests and updates to package data.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Sep 9, 2023
1 parent e67cd36 commit 808730e
Show file tree
Hide file tree
Showing 24 changed files with 117 additions and 176 deletions.
5 changes: 2 additions & 3 deletions glue_plotly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:"


Expand Down Expand Up @@ -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']
4 changes: 2 additions & 2 deletions glue_plotly/html_exporters/bqplot/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion glue_plotly/html_exporters/bqplot/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@viewer_tool
class PlotlyImageBqplotExport(PlotlyBaseBqplotExport):
tool_id = 'save:bqplot_plotlyimage'
tool_id = 'save:bqplot_plotlyimage2d'

def save_figure(self, filepath):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 8 additions & 2 deletions glue_plotly/html_exporters/bqplot/tests/test_histogram.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
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):

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)
12 changes: 9 additions & 3 deletions glue_plotly/html_exporters/bqplot/tests/test_image.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 8 additions & 2 deletions glue_plotly/html_exporters/bqplot/tests/test_profile.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
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):

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)
10 changes: 8 additions & 2 deletions glue_plotly/html_exporters/bqplot/tests/test_scatter2d.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
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):

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)
4 changes: 2 additions & 2 deletions glue_plotly/html_exporters/qt/dendrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions glue_plotly/html_exporters/qt/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions glue_plotly/html_exporters/qt/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions glue_plotly/html_exporters/qt/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions glue_plotly/html_exporters/qt/scatter2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions glue_plotly/html_exporters/qt/scatter3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions glue_plotly/html_exporters/qt/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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()
Expand All @@ -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()
8 changes: 7 additions & 1 deletion glue_plotly/html_exporters/qt/tests/test_dendrogram.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)
15 changes: 9 additions & 6 deletions glue_plotly/html_exporters/qt/tests/test_histogram.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
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):

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)
10 changes: 8 additions & 2 deletions glue_plotly/html_exporters/qt/tests/test_image.py
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit 808730e

Please sign in to comment.