Commit 7783d019 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][spinboxes] Improve handling of invalid types

parent 03c871f7
......@@ -45,9 +45,24 @@ def expected_values():
]
class TestInvalidTypes:
"""Test using invalid types for creation"""
@pytest.mark.parametrize("invalid_type", [None, np.bool, np.str])
def test_invalid_type(self, qtbot, invalid_type):
with pytest.raises(RuntimeError):
NumpySpinBox(invalid_type)
class SpinBoxBaseTest:
numpy_type = None
@pytest.mark.parametrize("invalid_type", [None, np.bool, np.str])
def test_set_invalid_type(self, qtbot, invalid_type):
spinbox = NumpySpinBox(self.numpy_type)
with pytest.raises(RuntimeError):
spinbox.setNumpyType(invalid_type)
def test_range(self, qtbot):
spinbox = NumpySpinBox(self.numpy_type)
qtbot.addWidget(spinbox)
......
......@@ -251,6 +251,9 @@ class NumpySpinBox(QAbstractSpinBox):
:param value numpy_type: value to set
"""
if numpy_type is None or not np.issubdtype(numpy_type, np.number):
raise RuntimeError(f"Invalid type {numpy_type}")
if self._numpy_type != numpy_type:
self._numpy_type = numpy_type
if np.issubdtype(self._numpy_type, np.floating):
......
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