Skip to content

Commit

Permalink
Add tests for type annotated interact.
Browse files Browse the repository at this point in the history
  • Loading branch information
corranwebster committed Apr 18, 2024
1 parent 5664ef7 commit 06473b0
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions python/ipywidgets/ipywidgets/widgets/tests/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from unittest.mock import patch

import os
from enum import Enum
from collections import OrderedDict
import pytest

Expand All @@ -24,6 +25,17 @@
def f(**kwargs):
pass


class Color(Enum):
red = 0
green = 1
blue = 2


def g(a: str, b: bool, c: int, d: float, e: Color) -> None:
pass


displayed = []
@pytest.fixture()
def clear_display():
Expand Down Expand Up @@ -624,3 +636,27 @@ def test_state_schema():
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../', 'state.schema.json')) as f:
schema = json.load(f)
jsonschema.validate(state, schema)

def test_type_hints():
c = interactive(g)

assert len(c.children) == 6

check_widget_children(
c,
a={'cls': widgets.Text},
b={'cls': widgets.Checkbox},
c={'cls': widgets.IntText},
d={'cls': widgets.FloatText},
e={
'cls': widgets.Dropdown,
'options': {
'red': Color.red,
'green': Color.green,
'blue': Color.blue,
},
'_options_labels': ("red", "green", "blue"),
'_options_values': (Color.red, Color.green, Color.blue),
},
)

0 comments on commit 06473b0

Please sign in to comment.