diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/hazmat/bindings/test_openssl.py | 3 | ||||
-rw-r--r-- | tests/test_warnings.py | 47 |
2 files changed, 49 insertions, 1 deletions
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py index 8f89232b..8cc81cdc 100644 --- a/tests/hazmat/bindings/test_openssl.py +++ b/tests/hazmat/bindings/test_openssl.py @@ -134,8 +134,9 @@ class TestOpenSSL(object): assert resp == expected_options assert b.lib.SSL_get_mode(ssl) == expected_options - def test_libraries(self): + def test_libraries(self, monkeypatch): assert _get_libraries("darwin") == ["ssl", "crypto"] + monkeypatch.setenv('PYCA_WINDOWS_LINK_TYPE', 'static') assert "ssleay32mt" in _get_libraries("win32") def test_windows_static_dynamic_libraries(self): diff --git a/tests/test_warnings.py b/tests/test_warnings.py new file mode 100644 index 00000000..9946baa7 --- /dev/null +++ b/tests/test_warnings.py @@ -0,0 +1,47 @@ +# 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__] + mod.Z = 3 + + with warnings.catch_warnings(record=True) as log: + warnings.simplefilter("always", PendingDeprecationWarning) + warnings.simplefilter("always", DeprecationWarning) + assert mod.X == 1 + assert mod.Y == 2 + assert mod.Z == 3 + + [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",) + + assert "Y" in dir(mod) |