Skip to content

Commit

Permalink
Add test of 3D viewer state JSON serializability.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Oct 31, 2024
1 parent a195690 commit ee93916
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Empty file.
35 changes: 35 additions & 0 deletions glue_jupyter/common/tests/test_state3d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import traitlets

from glue_jupyter.state_traitlets_helpers import GlueState
from glue_jupyter.common.state3d import ViewerState3D


class Widget(traitlets.HasTraits):

state = GlueState()

latest_json = None

# The following two methods mimic the behavior of ipywidgets

@traitlets.observe('state')
def on_state_change(self, change):
to_json = self.trait_metadata('state', 'to_json')
self.latest_json = to_json(self.state, self)

def set_state_from_json(self, json):
from_json = self.trait_metadata('state', 'from_json')
from_json(json, self)

Check warning on line 22 in glue_jupyter/common/tests/test_state3d.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/common/tests/test_state3d.py#L21-L22

Added lines #L21 - L22 were not covered by tests


def test_json_serializable():
widget = Widget()
assert widget.latest_json is None
widget.state = ViewerState3D()
assert widget.latest_json == {
"x_att": None, "x_min": 0, "x_max": 1,
"y_att": None, "y_min": 0, "y_max": 1,
"z_att": None, "z_min": 0, "z_max": 1,
"visible_axes": True, "native_aspect": False,
"layers": [], "title": None,
}

0 comments on commit ee93916

Please sign in to comment.