Skip to content

Commit

Permalink
Merge pull request #3591 from maartenbreddels/fix_test_traitlet_depre…
Browse files Browse the repository at this point in the history
…cated_8_port

Backport PR #3590: using _comm_default shadows possible bugs
  • Loading branch information
jasongrout committed Sep 16, 2022
2 parents 6330485 + e15688c commit 02d4bb9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions python/ipywidgets/ipywidgets/widgets/tests/test_set_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ def deserializer(json_data, widget):
return DataInstance( memoryview(json_data['data']).tobytes() if json_data else None )

class DataWidget(SimpleWidget):
d = Instance(DataInstance).tag(sync=True, to_json=mview_serializer, from_json=deserializer)
d = Instance(DataInstance, args=()).tag(sync=True, to_json=mview_serializer, from_json=deserializer)

# A widget that has a buffer that might be changed on reception:
def truncate_deserializer(json_data, widget):
return DataInstance( json_data['data'][:20].tobytes() if json_data else None )

class TruncateDataWidget(SimpleWidget):
d = Instance(DataInstance).tag(sync=True, to_json=bytes_serializer, from_json=truncate_deserializer)
d = Instance(DataInstance, args=()).tag(sync=True, to_json=bytes_serializer, from_json=truncate_deserializer)


#
Expand Down
7 changes: 5 additions & 2 deletions python/ipywidgets/ipywidgets/widgets/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from ipykernel.comm import Comm
from ipywidgets import Widget
import ipywidgets.widgets.widget

class DummyComm(Comm):
comm_id = 'a-b-c-d'
Expand All @@ -25,14 +26,16 @@ def close(self, *args, **kwargs):
undefined = object()

def setup_test_comm():
_widget_attrs['_comm_default'] = getattr(Widget, '_comm_default', undefined)
Widget._comm_default = lambda self: DummyComm()
Widget.comm.klass = DummyComm
ipywidgets.widgets.widget.Comm = DummyComm
_widget_attrs['_repr_mimebundle_'] = Widget._repr_mimebundle_
def raise_not_implemented(*args, **kwargs):
raise NotImplementedError()
Widget._repr_mimebundle_ = raise_not_implemented

def teardown_test_comm():
Widget.comm.klass = Comm
ipywidgets.widgets.widget.Comm = Comm
for attr, value in _widget_attrs.items():
if value is undefined:
delattr(Widget, attr)
Expand Down

0 comments on commit 02d4bb9

Please sign in to comment.