Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.editor
Commits
7783d019
Commit
7783d019
authored
Jun 13, 2019
by
Samuel GAIST
Browse files
[widgets][spinboxes] Improve handling of invalid types
parent
03c871f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
beat/editor/test/test_spinboxes.py
View file @
7783d019
...
...
@@ -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
)
...
...
beat/editor/widgets/spinboxes.py
View file @
7783d019
...
...
@@ -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
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment