test_param_widget.py 1.5 KB

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