Commit 1bac7a70 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][parameterwidget] Improve InputType

parent a0ab5175
......@@ -74,13 +74,7 @@ def parameter_default_map(prefix_path, algorithm_name):
# Fixtures
@pytest.fixture(
params=[
item
for item in InputType
if item not in [InputType.UNKNOWN, InputType.BOOL, InputType.STRING]
]
)
@pytest.fixture(params=InputType.numerical_types())
def numerical_input_type(request):
return request.param
......@@ -115,6 +109,22 @@ def parameter_name(request):
# Tests
class TestInputType:
"""Test the InputType enum class"""
def test_numerical_info(self, numerical_input_type):
type_ = type(numerical_input_type.numpy_info)
assert type_ in [np.iinfo, np.finfo]
@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):
input_type.numpy_info
class TestBoolSetupWidget:
"""Test the BoolSetupWidget is set up and works correctly"""
......
......@@ -26,7 +26,6 @@
import numpy as np
from enum import Enum, unique
from collections import namedtuple
from PyQt5.QtCore import Qt
from PyQt5.QtCore import pyqtSignal
......@@ -77,16 +76,26 @@ class InputType(Enum):
@property
def numpy_info(self):
info = None
if np.issubdtype(self.np_type, np.floating):
if self is InputType.UNKNOWN:
raise RuntimeError(f"Invalid type")
elif np.issubdtype(self.np_type, np.floating):
info = np.finfo(self.np_type)
elif np.issubdtype(self.np_type, np.integer):
info = np.iinfo(self.np_type)
else:
Info = namedtuple("Info", ["min", "max"])
info = Info(0, 0)
raise RuntimeError(f"No information available for {self}")
return info
@staticmethod
def numerical_types():
return [
item
for item in InputType
if item not in [InputType.UNKNOWN, InputType.BOOL, InputType.STRING]
]
class StackedWidget(QStackedWidget):
"""Subclass that will use the current widget height to adjust the stack
......
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