|
1 | 1 | import os |
2 | 2 | import unittest |
| 3 | +import warnings |
3 | 4 |
|
4 | 5 | from nose.tools import eq_, ok_ |
5 | 6 |
|
| 7 | +from ddtrace.utils.deprecation import deprecation, deprecated, format_message |
6 | 8 | from ddtrace.utils.formats import asbool, get_env |
7 | 9 |
|
8 | 10 |
|
@@ -49,4 +51,36 @@ def test_get_env_key_priority(self): |
49 | 51 |
|
50 | 52 | def test_deprecation_formatter(self): |
51 | 53 | # 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