Skip to content

Commit

Permalink
Improve code and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pvk-developer committed Sep 17, 2024
1 parent e15a077 commit dfe8c85
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
11 changes: 1 addition & 10 deletions rdt/transformers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,4 @@ def __getitem__(self, sdtype):
If the sdtype is `text` raises a `DeprecationWarning` stating that it will be
phased out.
"""
if sdtype in DEPRECATED_SDTYPES_MAPPING and not self._warned.get(sdtype):
new_sdtype = DEPRECATED_SDTYPES_MAPPING.get(sdtype)
warnings.warn(
f"The sdtype '{sdtype}' is deprecated and will be phased out. "
f"Please use '{new_sdtype}' instead.",
DeprecationWarning,
)
self._warned[sdtype] = True

return super().get(sdtype)
return self.get(sdtype)
23 changes: 23 additions & 0 deletions tests/unit/transformers/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,26 @@ def test_warn_dict():
assert result_access == 'text_transformer'
assert result_access_no_warn == 'text_transformer'
assert result_get_no_warn == 'text_transformer'


def test_warn_dict_get():
"""Test that ``WarnDict`` will raise a warning when called with `text`."""
# Setup
instance = WarnDict()
instance['text'] = 'text_transformer'

# Run
warning_msg = "The sdtype 'text' is deprecated and will be phased out. Please use 'id' instead."
with pytest.warns(DeprecationWarning, match=warning_msg):
result_access = instance.get('text')

# Run second time and no warning gets shown
with warnings.catch_warnings(record=True) as record:
result_access_no_warn = instance['text']
result_get_no_warn = instance.get('text')

# Assert
assert len(record) == 0
assert result_access == 'text_transformer'
assert result_access_no_warn == 'text_transformer'
assert result_get_no_warn == 'text_transformer'

0 comments on commit dfe8c85

Please sign in to comment.