Commit 6413ec41 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][parameterwidget] Renamed ChoicesDialog to NumericalChoiceDialog

Also added test for the dialog itself
parent 148a28d1
......@@ -28,6 +28,7 @@ import numpy as np
from PyQt5 import QtCore
from PyQt5.QtWidgets import QDialogButtonBox
from PyQt5.QtWidgets import QInputDialog
from ..backend.asset import Asset
......@@ -37,7 +38,7 @@ from ..widgets.parameterwidget import StringSetupWidget
from ..widgets.parameterwidget import NumericalSetupWidget
from ..widgets.parameterwidget import ParameterWidget
from ..widgets.parameterwidget import InputType
from ..widgets.parameterwidget import ChoicesDialog
from ..widgets.parameterwidget import NumericalChoiceDialog
from .conftest import prefix
from .conftest import sync_prefix
......@@ -125,6 +126,26 @@ class TestInputType:
input_type.numpy_info
class TestNumericalChoiceDialog:
"""Test the NumericalChoiceDialog class"""
def test_dialog(self, qtbot, numerical_input_type):
dialog = NumericalChoiceDialog(numerical_input_type)
qtbot.addWidget(dialog)
qtbot.mouseClick(
dialog.buttons.button(QDialogButtonBox.Ok), QtCore.Qt.LeftButton
)
assert dialog.value() == 0
@pytest.mark.parametrize(
"input_type",
[item for item in InputType if item not in InputType.numerical_types()],
)
def test_non_numerical_info(self, input_type):
with pytest.raises(RuntimeError):
NumericalChoiceDialog(input_type)
class TestBoolSetupWidget:
"""Test the BoolSetupWidget is set up and works correctly"""
......@@ -468,7 +489,7 @@ class TestNumericalSetupWidget:
for i in range(0, 3):
with qtbot.waitSignal(numerical_setup_widget.dataChanged):
monkeypatch.setattr(
ChoicesDialog,
NumericalChoiceDialog,
"getChoiceValue",
classmethod(lambda *args: (str(setup_choices["choice"][i]), True)),
)
......@@ -522,7 +543,7 @@ class TestNumericalSetupWidget:
# add some choices
for i in range(0, 3):
monkeypatch.setattr(
ChoicesDialog,
NumericalChoiceDialog,
"getChoiceValue",
classmethod(
lambda *args: (str(wrong_setup_choices["choice"][i]), True)
......@@ -570,19 +591,19 @@ class TestNumericalSetupWidget:
# add some choices
with qtbot.waitSignal(numerical_setup_widget.dataChanged):
monkeypatch.setattr(
ChoicesDialog,
NumericalChoiceDialog,
"getChoiceValue",
classmethod(lambda *args: (value1, True)),
)
numerical_setup_widget.add_button.click()
monkeypatch.setattr(
ChoicesDialog,
NumericalChoiceDialog,
"getChoiceValue",
classmethod(lambda *args: (value2, True)),
)
numerical_setup_widget.add_button.click()
monkeypatch.setattr(
ChoicesDialog,
NumericalChoiceDialog,
"getChoiceValue",
classmethod(lambda *args: (value3, True)),
)
......
......@@ -128,7 +128,7 @@ class StackedWidget(QStackedWidget):
return size
class ChoicesDialog(QDialog):
class NumericalChoiceDialog(QDialog):
"""Dialog to retrieve a value to to add to a choice list"""
def __init__(self, selected_type, parent=None):
......@@ -138,7 +138,7 @@ class ChoicesDialog(QDialog):
:param parent QWidget: parent widget
"""
super(ChoicesDialog, self).__init__(parent)
super(NumericalChoiceDialog, self).__init__(parent)
self.setWindowTitle(self.tr("Input"))
self.label = QLabel(self.tr("New Choice:"))
......@@ -158,6 +158,11 @@ class ChoicesDialog(QDialog):
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
def value(self):
"""Returns the value selected"""
return self.spinbox.value()
@staticmethod
def getChoiceValue(selected_type, parent=None):
"""Static method to create the dialog and return qdialog accepted/spinbox value
......@@ -166,12 +171,12 @@ class ChoicesDialog(QDialog):
:param parent QWidget: parent widget
"""
dialog = ChoicesDialog(selected_type, parent)
dialog = NumericalChoiceDialog(selected_type, parent)
result = dialog.exec_()
value = None
if result == QDialog.Accepted:
value = dialog.spinbox.value()
value = dialog.value()
return (value, result)
......@@ -706,7 +711,7 @@ class NumericalSetupWidget(QWidget):
input_value = None
ok = False
input_value, ok = ChoicesDialog.getChoiceValue(self.current_type)
input_value, ok = NumericalChoiceDialog.getChoiceValue(self.current_type)
if ok:
if (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment