Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yczhang-nv committed May 29, 2024
1 parent 36b7d06 commit d011acf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion morpheus/messages/message_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __new__(cls, name, bases, namespace, /, cpp_class=None, **kwargs):
@functools.wraps(result.__new__)
def _internal_new(other_cls, *args, **kwargs):

# Instantiating MultiMessage from Python or C++ will generate a deprecation warning
# Instantiating MultiMessage and its subclasses from Python or C++ will generate a deprecation warning
if issubtype(other_cls, messages.MultiMessage):
morpheus_logger.deprecated_message_warning(other_cls, ControlMessage)

Expand Down
8 changes: 6 additions & 2 deletions morpheus/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import logging.handlers
import multiprocessing
import os
import re
import warnings
from enum import Enum

Expand All @@ -27,6 +28,8 @@
import mrc
from tqdm import tqdm

import morpheus

LogLevels = Enum('LogLevels', logging._nameToLevel)


Expand Down Expand Up @@ -226,7 +229,8 @@ def deprecated_stage_warning(logger, cls, name, reason: str = None):

def deprecated_message_warning(cls, new_cls):
"""Log a warning about a deprecated message."""
message = f"The '{cls.__name__}' message has been deprecated and will be removed in a future version.\
Please use '{new_cls.__name__}' instead."
version = re.match(r"(\d+\.\d+)", morpheus.__version__).group(1)

message = (f"The '{cls.__name__}' message has been deprecated and will be removed "
f"after version {version} release. Please use '{new_cls.__name__}' instead.")
warnings.warn(message, DeprecationWarning)
9 changes: 5 additions & 4 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import multiprocessing
import os
import re
from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -150,9 +151,9 @@ class OldMessage():
class NewMessage():
pass

with patch("warnings.warn") as mock_warning:
with pytest.warns(DeprecationWarning) as warnings:
deprecated_message_warning(OldMessage, NewMessage)
warning_msg = mock_warning.call_args.args[0]

assert warning_msg == "The 'OldMessage' message has been deprecated and will be removed in a future version.\
Please use 'NewMessage' instead."
pattern = (r"The '(\w+)' message has been deprecated and will be removed "
r"after version (\d+\.\d+) release. Please use '(\w+)' instead.")
assert re.search(pattern, str(warnings[0].message)) is not None
1 change: 1 addition & 0 deletions tests/test_multi_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ def test_deprecation_message(filter_probs_df: cudf.DataFrame, caplog):

def generate_deprecation_warning(deprecated_class, new_class):

# patching warning.warn here to get the warning message string from deprecated_message_warning() for asserting
with patch("warnings.warn") as mock_warning:
morpheus_logger.deprecated_message_warning(deprecated_class, new_class)
warning_msg = mock_warning.call_args.args[0]
Expand Down

0 comments on commit d011acf

Please sign in to comment.