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