Commit ddd7da66 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[test][spinboxes] Refactor invalid input tests

Make it more flexible to avoid code duplication.
parent c127b7e8
......@@ -23,12 +23,24 @@
# #
###############################################################################
import pytest
from ..widgets.spinboxes import Int64SpinBox
from ..widgets.spinboxes import Uint64SpinBox
from ..widgets.spinboxes import Uint32SpinBox
from ..widgets.spinboxes import Float64SpinBox
@pytest.fixture()
def expected_values():
return [
(Uint32SpinBox, 477218588),
(Int64SpinBox, 4444444444444444444),
(Uint64SpinBox, 4444444444444444444),
(Float64SpinBox, 4.444444444444445e164),
]
class SpinBoxBaseTest:
klass = None
......@@ -57,11 +69,17 @@ class SpinBoxBaseTest:
qtbot.keyClicks(spinbox, value)
assert spinbox.value() == spinbox.numpy_type(value)
def test_invalid_input(self, qtbot):
def test_invalid_input(self, qtbot, expected_values):
spinbox = self.klass()
qtbot.addWidget(spinbox)
value = "44444444444444444444444444444444444444444444444444444444444"
expected_value = 4444444444444444444
expected_value = None
for item in expected_values:
if self.klass == item[0]:
expected_value = item[1]
break
assert expected_value is not None
with qtbot.waitSignal(spinbox.valueChanged):
qtbot.keyClicks(spinbox, value)
......@@ -150,13 +168,3 @@ class TestFloat64SpinBox(SpinBoxBaseTest):
spinbox.setValue(15)
assert spinbox.value() == spinbox.maximum()
def test_invalid_input(self, qtbot):
spinbox = self.klass()
qtbot.addWidget(spinbox)
value = "44444444444444444444444444444444444444444444444444444444444"
expected_value = 4.444444444444445e164
with qtbot.waitSignal(spinbox.valueChanged):
qtbot.keyClicks(spinbox, value)
assert spinbox.value() == spinbox.numpy_type(expected_value)
Supports Markdown
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