Skip to content

Commit e4d3c66

Browse files
committed
add deprecator test
1 parent b90f56a commit e4d3c66

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

tests/test_deprecator.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
3+
from diffpy.utils._deprecator import deprecated, deprecation_message
4+
5+
old_base = "diffpy.utils"
6+
old_name = "oldFunction"
7+
new_name = "new_function"
8+
removal_version = "4.0.0"
9+
10+
dep_msg = deprecation_message(old_base, old_name, new_name, removal_version)
11+
12+
13+
@deprecated(dep_msg)
14+
def oldFunction(print_msg):
15+
"""This function is deprecated and will be removed in version 4.0.0.
16+
17+
Please use newFunction instead
18+
"""
19+
return new_function(print_msg)
20+
21+
22+
def new_function(print_msg):
23+
print(print_msg)
24+
return
25+
26+
27+
def test_deprecated(capsys):
28+
# Case: user deprecates a function with the deprecated decorator
29+
# Expected: DeprecationWarning is raised when the function is called
30+
# and the function executes correctly
31+
expected_print_msg = "Testing deprecated function"
32+
with pytest.deprecated_call(match=dep_msg):
33+
oldFunction(expected_print_msg)
34+
35+
captured = capsys.readouterr()
36+
actual_print_msg = captured.out.strip()
37+
assert actual_print_msg == expected_print_msg

0 commit comments

Comments
 (0)