test_param_widget.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import functools
  2. from pathlib import Path
  3. from ..param_widgets import (
  4. BoolParamWidget,
  5. StrParamWidget,
  6. PosIntParamWidget,
  7. ChoiceParamWidget,
  8. PathParamWidget,
  9. load_parameter_widget,
  10. )
  11. from ..param_multival_widget import MultiValueInputWidget
  12. def test_GooeyParamWidgetMixin():
  13. # can we set and get a supported value to/from any widget
  14. # through the GooeyParamWidgetMixin API
  15. for pw_factory, val, default in (
  16. (BoolParamWidget, True, False),
  17. (PosIntParamWidget, 4, 1),
  18. (StrParamWidget, 'dummy', 'mydefault'),
  19. (functools.partial(ChoiceParamWidget, ['a', 'b', 'c']), 'b', 'c'),
  20. (PathParamWidget, str(Path.cwd()), 'mypath'),
  21. # cannot include MultiValueInputWidget, leads to Python segfault
  22. # on garbage collection?!
  23. #(functools.partial(
  24. # MultiValueInputWidget, PathParamWidget),
  25. # [str(Path.cwd()), 'temp'],
  26. # 'mypath'),
  27. ):
  28. # this is how all parameter widgets are instantiated
  29. pw = load_parameter_widget(
  30. None,
  31. pw_factory,
  32. name='peewee',
  33. docs='EXPLAIN!',
  34. default=default,
  35. )
  36. pw.set_gooey_param_value(val)
  37. # we get the set value back, not the default
  38. assert pw.get_gooey_param_spec() == {'peewee': val}