Skip to content

Commit

Permalink
Fix Python 3.7 test
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Feb 16, 2023
1 parent 6b4cc83 commit 73b0187
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions python/ipywidgets/ipywidgets/widgets/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
from ipywidgets import Widget
import ipywidgets.widgets.widget

import comm
# The new comm package is not available in our Python 3.7 CI (older ipykernel version)
try:
import comm
NEW_COMM_PACKAGE = True
except ImportError:
NEW_COMM_PACKAGE = False

from ipykernel.comm import Comm


Expand Down Expand Up @@ -40,12 +46,17 @@ def dummy_get_comm_manager(**kwargs):
_widget_attrs = {}
undefined = object()

orig_create_comm = comm.create_comm
orig_get_comm_manager = comm.get_comm_manager
orig_create_comm = None
orig_get_comm_manager = None

if NEW_COMM_PACKAGE:
orig_create_comm = comm.create_comm
orig_get_comm_manager = comm.get_comm_manager

def setup_test_comm():
comm.create_comm = dummy_create_comm
comm.get_comm_manager = dummy_get_comm_manager
if NEW_COMM_PACKAGE:
comm.create_comm = dummy_create_comm
comm.get_comm_manager = dummy_get_comm_manager
Widget.comm.klass = DummyComm
ipywidgets.widgets.widget.Comm = DummyComm
_widget_attrs['_repr_mimebundle_'] = Widget._repr_mimebundle_
Expand All @@ -54,8 +65,9 @@ def raise_not_implemented(*args, **kwargs):
Widget._repr_mimebundle_ = raise_not_implemented

def teardown_test_comm():
comm.create_comm = orig_create_comm
comm.get_comm_manager = orig_get_comm_manager
if NEW_COMM_PACKAGE:
comm.create_comm = orig_create_comm
comm.get_comm_manager = orig_get_comm_manager
Widget.comm.klass = Comm
ipywidgets.widgets.widget.Comm = Comm
for attr, value in _widget_attrs.items():
Expand Down

0 comments on commit 73b0187

Please sign in to comment.