diff --git a/glue_plotly/viewers/common/tests/__init__.py b/glue_plotly/viewers/common/tests/__init__.py index e69de29..3033646 100644 --- a/glue_plotly/viewers/common/tests/__init__.py +++ b/glue_plotly/viewers/common/tests/__init__.py @@ -0,0 +1 @@ +from .base_viewer_tests import BasePlotlyViewTests # noqa diff --git a/glue_plotly/viewers/common/tests/base_viewer_tests.py b/glue_plotly/viewers/common/tests/base_viewer_tests.py new file mode 100644 index 0000000..3fd125c --- /dev/null +++ b/glue_plotly/viewers/common/tests/base_viewer_tests.py @@ -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 diff --git a/glue_plotly/viewers/histogram/tests/test_viewer.py b/glue_plotly/viewers/histogram/tests/test_viewer.py index c192689..0e6c6b9 100644 --- a/glue_plotly/viewers/histogram/tests/test_viewer.py +++ b/glue_plotly/viewers/histogram/tests/test_viewer.py @@ -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]) diff --git a/glue_plotly/viewers/scatter/tests/test_viewer.py b/glue_plotly/viewers/scatter/tests/test_viewer.py index efe0b3d..0554022 100644 --- a/glue_plotly/viewers/scatter/tests/test_viewer.py +++ b/glue_plotly/viewers/scatter/tests/test_viewer.py @@ -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) @@ -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