diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2015-01-01 20:29:13 -0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2015-01-01 20:29:13 -0800 |
commit | d27856c33df1cba86a3c1f61123106787bc35c0d (patch) | |
tree | 212888a2ad9d52a55857d1ad9f847ef12c282315 | |
parent | 408fc4ee2833fcd5db315564f7f6961ec426365b (diff) | |
download | cryptography-d27856c33df1cba86a3c1f61123106787bc35c0d.tar.gz cryptography-d27856c33df1cba86a3c1f61123106787bc35c0d.tar.bz2 cryptography-d27856c33df1cba86a3c1f61123106787bc35c0d.zip |
Added some tests
-rw-r--r-- | tests/test_warnings.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_warnings.py b/tests/test_warnings.py new file mode 100644 index 00000000..dd1b6a54 --- /dev/null +++ b/tests/test_warnings.py @@ -0,0 +1,43 @@ +# This file is dual licensed under the terms of the Apache License, Version +# 2.0, and the BSD License. See the LICENSE file in the root of this repository +# for complete details. + +from __future__ import absolute_import, division, print_function + +import sys +import types +import warnings + +from cryptography.utils import deprecated + + +class TestDeprecated(object): + def test_deprecated(self, monkeypatch): + mod = types.ModuleType("TestDeprecated/test_deprecated") + monkeypatch.setitem(sys.modules, mod.__name__, mod) + mod.X = deprecated( + value=1, + module_name=mod.__name__, + message="deprecated message text", + warning_class=DeprecationWarning + ) + mod.Y = deprecated( + value=2, + module_name=mod.__name__, + message="more deprecated text", + warning_class=PendingDeprecationWarning, + ) + mod = sys.modules[mod.__name__] + + with warnings.catch_warnings(record=True) as log: + warnings.simplefilter("always", PendingDeprecationWarning) + warnings.simplefilter("always", DeprecationWarning) + assert mod.X == 1 + assert mod.Y == 2 + + [msg1, msg2] = log + assert msg1.category is DeprecationWarning + assert msg1.message.args == ("deprecated message text",) + + assert msg2.category is PendingDeprecationWarning + assert msg2.message.args == ("more deprecated text",) |