aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_warnings.py
blob: 9946baa73ed0ca6d002ab3c66461b4bc20f10963 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)
o">== "1": return [] else: return ["ssl", "crypto"] ffi = build_ffi_for_binding( module_name="_openssl", module_prefix="_cffi_src.openssl.", modules=[ # This goes first so we can define some cryptography-wide symbols. "cryptography", "aes", "asn1", "bignum", "bio", "cmac", "cms", "conf", "crypto", "dh", "dsa", "ec", "ecdh", "ecdsa", "engine", "err", "evp", "hmac", "nid", "objects", "ocsp", "opensslv", "osrandom_engine", "pem", "pkcs12", "rand", "rsa", "ssl", "x509", "x509name", "x509v3", "x509_vfy", "pkcs7", "callbacks", ], libraries=_get_openssl_libraries(sys.platform), extra_link_args=extra_link_args(compiler_type()), )