forked from coala/coala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DeprecationUtilities.py: Add a utility function
Add a check_deprecation utility function to log a warning message in case deprecated parameters are used.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import logging | ||
|
||
|
||
def check_deprecation(param_list): | ||
""" | ||
Shows a deprecation warning message if the parameters | ||
passed are not ``None``. | ||
:param param_list: | ||
A dictionary of parameters with their names mapped | ||
to their values being checked for deprecation. | ||
>>> from testfixtures import LogCapture | ||
>>> from collections import OrderedDict | ||
>>> param_list = OrderedDict([('foo', None), | ||
... ('bar', 'Random'), | ||
... ('baz', 1773)]) | ||
>>> with LogCapture() as capture: | ||
... check_deprecation(param_list) | ||
... print(capture) | ||
root WARNING | ||
bar parameter is deprecated | ||
root WARNING | ||
baz parameter is deprecated | ||
""" | ||
for param_name, param_value in param_list.items(): | ||
if param_value is not None: | ||
logging.warning('{} parameter is deprecated'.format(param_name)) |