Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Czaki committed Jan 26, 2024
1 parent a104055 commit 28b697a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
12 changes: 10 additions & 2 deletions package/PartSegCore/algorithm_describe_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,16 @@ def _get_abstract_getters(
# get all abstract methods that starts with `get_`
for method_name in cls2.__abstractmethods__:
if method_name.startswith("get_"):
if "return" not in getattr(cls2, method_name).__annotations__:
raise RuntimeError(f"Method {method_name} should have return annotation")
method = getattr(cls2, method_name)
if "return" not in method.__annotations__:
msg = f"Method {method_name} of {cls2.__qualname__} need to have return type defined"
try:
file_name = inspect.getsourcefile(method)
line = inspect.getsourcelines(method)[1]
msg += f" in {file_name}:{line}"
except TypeError:
pass
raise RuntimeError(msg)

abstract_getters[method_name[4:]] = getattr(cls2, method_name).__annotations__["return"]
elif method_name != calculation_method:
Expand Down
4 changes: 2 additions & 2 deletions package/PartSegCore/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class SaveBase(AlgorithmDescribeBase, ABC):

@classmethod
@abstractmethod
def get_short_name(cls):
def get_short_name(cls) -> str:
raise NotImplementedError

@classmethod
Expand Down Expand Up @@ -134,7 +134,7 @@ class LoadBase(AlgorithmDescribeBase, ABC):

@classmethod
@abstractmethod
def get_short_name(cls):
def get_short_name(cls) -> str:
raise NotImplementedError

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion package/PartSegCore/segmentation/algorithm_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def calculation_run(self, report_fun: Callable[[str, int], None]) -> ROIExtracti
raise NotImplementedError

@abstractmethod
def get_info_text(self):
def get_info_text(self) -> str:
raise NotImplementedError

def get_channel(self, channel_idx):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def sample_function(params: dict) -> dict:
ClassForTestFromFunc.from_function(sample_function, info="sample", alpha=1.0, additions="sample3")

def test_missing_return_annotation(self):
with pytest.raises(RuntimeError, match="Method get_sample should have return annotation"):
with pytest.raises(RuntimeError, match="Method get_sample of .*SampleClass need to have return type defined.*"):

class SampleClass(AlgorithmDescribeBase): # pylint: disable=unused-variable
@classmethod
Expand Down

0 comments on commit 28b697a

Please sign in to comment.