Skip to content

Commit af474fb

Browse files
author
Emanuele Palazzetti
committed
[core] add ddtrace.utils.deprecation tests
1 parent 0632287 commit af474fb

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

tests/test_utils.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22
import unittest
3+
import warnings
34

45
from nose.tools import eq_, ok_
56

7+
from ddtrace.utils.deprecation import deprecation, deprecated, format_message
68
from ddtrace.utils.formats import asbool, get_env
79

810

@@ -49,4 +51,36 @@ def test_get_env_key_priority(self):
4951

5052
def test_deprecation_formatter(self):
5153
# ensure the formatter returns the proper message
52-
pass
54+
msg = format_message(
55+
'deprecated_function',
56+
'use something else instead',
57+
'1.0.0',
58+
)
59+
expected = "'deprecated_function' is deprecated and will be remove in future versions (1.0.0). use something else instead"
60+
eq_(msg, expected)
61+
62+
def test_deprecation(self):
63+
# ensure `deprecation` properly raise a DeprecationWarning
64+
with warnings.catch_warnings(record=True) as w:
65+
warnings.simplefilter('always')
66+
deprecation(
67+
name='fn',
68+
message='message',
69+
version='1.0.0'
70+
)
71+
ok_(len(w) == 1)
72+
ok_(issubclass(w[-1].category, DeprecationWarning))
73+
ok_('message' in str(w[-1].message))
74+
75+
def test_deprecated_decorator(self):
76+
# ensure `deprecated` decorator properly raise a DeprecationWarning
77+
@deprecated('decorator', version='1.0.0')
78+
def fxn():
79+
pass
80+
81+
with warnings.catch_warnings(record=True) as w:
82+
warnings.simplefilter('always')
83+
fxn()
84+
ok_(len(w) == 1)
85+
ok_(issubclass(w[-1].category, DeprecationWarning))
86+
ok_('decorator' in str(w[-1].message))

0 commit comments

Comments
 (0)