Skip to content

Commit

Permalink
Add base viewer test class, including test for unique class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Jul 17, 2024
1 parent 7247444 commit 732d682
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions glue_plotly/viewers/common/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .base_viewer_tests import BasePlotlyViewTests # noqa
22 changes: 22 additions & 0 deletions glue_plotly/viewers/common/tests/base_viewer_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from uuid import UUID


class BasePlotlyViewTests:

def setup_method(self, method):
pass

def teardown_method(self, method):
pass

def test_unique_class(self):
unique_class = self.viewer.unique_class
prefix = "glue-plotly-"
prefix_len = len(prefix)
assert unique_class.startswith(prefix)
assert len(unique_class) == prefix_len + 32

# Test UUID validity by seeing if we can construct a UUID instance
assert UUID(unique_class[prefix_len:])

assert unique_class in self.viewer.figure._dom_classes
3 changes: 2 additions & 1 deletion glue_plotly/viewers/histogram/tests/test_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from plotly.graph_objects import Bar

from glue_plotly.common import DEFAULT_FONT
from glue_plotly.viewers.common.tests import BasePlotlyViewTests
from glue_plotly.viewers.histogram import PlotlyHistogramView


class TestHistogramViewer:
class TestHistogramViewer(BasePlotlyViewTests):

def setup_method(self, method):
self.data = Data(label="histogram", x=[1, 1, 1, 2, 2, 3, 3, 3, 4, 6, 6])
Expand Down
5 changes: 4 additions & 1 deletion glue_plotly/viewers/scatter/tests/test_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from plotly.graph_objects import Scatter

from glue_plotly.common import DEFAULT_FONT
from glue_plotly.viewers.common.tests import BasePlotlyViewTests
from glue_plotly.viewers.scatter import PlotlyScatterView


class TestScatterView:
class TestScatterView(BasePlotlyViewTests):

def setup_method(self, method):
super().setup_method(method)
self.data = Data(label="histogram", x=[1, 3, 5, 7, 9], y=[2, 4, 6, 8, 10])
self.app = JupyterApplication()
self.app.session.data_collection.append(self.data)
Expand All @@ -33,6 +35,7 @@ def setup_method(self, method):
def teardown_method(self, method):
self.viewer = None
self.app = None
super().teardown_method(method)

def test_basic(self):
assert len(self.viewer.layers) == 1
Expand Down

0 comments on commit 732d682

Please sign in to comment.