mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-03 12:51:00 +08:00
Add dict_to_form_widget
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from optuna_dashboard import ChoiceWidget
|
||||
from optuna_dashboard import dict_to_form_widget
|
||||
from optuna_dashboard import ObjectiveUserAttrRef
|
||||
from optuna_dashboard import SliderWidget
|
||||
from optuna_dashboard import TextInputWidget
|
||||
|
||||
|
||||
class FormWidgetsTestCase(TestCase):
|
||||
def test_widget_to_dict_from_dict(self) -> None:
|
||||
widgets = [
|
||||
ChoiceWidget(choices=["Good", "Bad"], values=[1, -1]),
|
||||
ChoiceWidget(
|
||||
choices=["Good", "Bad"],
|
||||
values=[1, -1],
|
||||
description="description",
|
||||
user_attr_key="key",
|
||||
),
|
||||
SliderWidget(min=1, max=5),
|
||||
SliderWidget(
|
||||
min=1,
|
||||
max=5,
|
||||
step=1,
|
||||
labels=[(1, "Bad"), (5, "Good")],
|
||||
description="description",
|
||||
user_attr_key="key",
|
||||
),
|
||||
TextInputWidget(),
|
||||
TextInputWidget(description="description", user_attr_key="key"),
|
||||
ObjectiveUserAttrRef(key="key"),
|
||||
]
|
||||
|
||||
for i, widget in enumerate(widgets):
|
||||
with self.subTest(f"{widget.__class__}-{i}"):
|
||||
d = widget.to_dict()
|
||||
restored = dict_to_form_widget(d)
|
||||
assert widget == restored
|
||||
Reference in New Issue
Block a user