From 23f67537db0a8b3959a8d83b01e89b79922fccd6 Mon Sep 17 00:00:00 2001 From: Qin Yu Date: Sun, 17 Mar 2024 18:01:08 +0100 Subject: [PATCH] Add Separator tests --- tests/test_widgets.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_widgets.py b/tests/test_widgets.py index 4e6a96527..c6d67e292 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -1059,6 +1059,37 @@ def f(x: Set[Lit]): ... assert sel.choices == get_args(Lit) +def test_separator_default(): + from magicgui.types import Separator + + sep = Separator() + assert sep.thickness == 1 + + +def test_separator(): + from magicgui.types import Separator + + sep = [Separator(i + 1) for i in range(4)] + a = [1, 2, sep[0], 4, sep[1], 6, 7, sep[2], 9, sep[3], 11, 12, sep[0], 14, sep[0]] + b = [1, 2, sep[0], 4, sep[1], 6, 7, sep[2], 9, sep[3], 6, 7, sep[0], 9, sep[0]] + a2 = (1, 2, None, 4, None, None, 6, 7, None, None, None, 9, None, None, None, None, 11, 12, None, 14, None) + b2 = (1, 2, None, 4, None, None, 6, 7, None, None, None, 9, None, None, None, None, None, None) + + @magicgui( + call_button="Test Separator", + a={"widget_type": "ComboBox", "choices": a}, + b={"widget_type": "ComboBox", "choices": b}, + result_widget=True, + ) + def widget_with_separator(a=a[0], b=b[0]): + return + + assert widget_with_separator.a.native.count() == 21 + assert widget_with_separator.b.native.count() == 18 + assert widget_with_separator.a.choices == a2 + assert widget_with_separator.b.choices == b2 + + def test_float_slider_readout(): sld = widgets.FloatSlider(value=4, min=0.5, max=10.5) assert sld.value == 4