Skip to content

Commit

Permalink
CU-8695d4www: Allow usage of specified deprecated method(s) during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mart-r committed Aug 13, 2024
1 parent 0ee1a8a commit a89e680
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions medcat/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ def _format_version(ver: Tuple[int, int, int]) -> str:
return ".".join(str(v) for v in ver)


def deprecated(message: str, depr_version: Tuple[int, int, int], removal_version: Tuple[int, int, int]) -> Callable:
def deprecated(message: str, depr_version: Tuple[int, int, int],
removal_version: Tuple[int, int, int],
allow_usage: bool = False) -> Callable:
"""Deprecate a method.
Args:
message (str): The deprecation message.
depr_version (Tuple[int, int, int]): The first version of MedCAT where this was deprecated.
removal_version (Tuple[int, int, int]): The first version of MedCAT where this will be removed.
allow_usage (bool): Whether to allow usage during test time.
Returns:
Callable: _description_
Callable: The wrapped method.
"""
def decorator(func: Callable) -> Callable:
@functools.wraps(func)
Expand Down
5 changes: 4 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def __init__(self, func: Callable, msg: str,
def deprecation_exception_raiser(message: str, depr_version: Tuple[int, int, int],
removal_version: Tuple[int, int, int]):
def decorator(func: Callable) -> Callable:
def wrapper(*_, **__):
def wrapper(*args, **kwargs):
if ('allow_usage' in kwargs and kwargs['allow_usage'] or
len(args) >= 4 and args[3]):
return func(*args, **kwargs)
raise DeprecatedMethodCallException(func, message, depr_version, removal_version)
return wrapper
return decorator
Expand Down

0 comments on commit a89e680

Please sign in to comment.