Alex Gaynor | d27856c | 2015-01-01 20:29:13 -0800 | [diff] [blame^] | 1 | # This file is dual licensed under the terms of the Apache License, Version |
| 2 | # 2.0, and the BSD License. See the LICENSE file in the root of this repository |
| 3 | # for complete details. |
| 4 | |
| 5 | from __future__ import absolute_import, division, print_function |
| 6 | |
| 7 | import sys |
| 8 | import types |
| 9 | import warnings |
| 10 | |
| 11 | from cryptography.utils import deprecated |
| 12 | |
| 13 | |
| 14 | class TestDeprecated(object): |
| 15 | def test_deprecated(self, monkeypatch): |
| 16 | mod = types.ModuleType("TestDeprecated/test_deprecated") |
| 17 | monkeypatch.setitem(sys.modules, mod.__name__, mod) |
| 18 | mod.X = deprecated( |
| 19 | value=1, |
| 20 | module_name=mod.__name__, |
| 21 | message="deprecated message text", |
| 22 | warning_class=DeprecationWarning |
| 23 | ) |
| 24 | mod.Y = deprecated( |
| 25 | value=2, |
| 26 | module_name=mod.__name__, |
| 27 | message="more deprecated text", |
| 28 | warning_class=PendingDeprecationWarning, |
| 29 | ) |
| 30 | mod = sys.modules[mod.__name__] |
| 31 | |
| 32 | with warnings.catch_warnings(record=True) as log: |
| 33 | warnings.simplefilter("always", PendingDeprecationWarning) |
| 34 | warnings.simplefilter("always", DeprecationWarning) |
| 35 | assert mod.X == 1 |
| 36 | assert mod.Y == 2 |
| 37 | |
| 38 | [msg1, msg2] = log |
| 39 | assert msg1.category is DeprecationWarning |
| 40 | assert msg1.message.args == ("deprecated message text",) |
| 41 | |
| 42 | assert msg2.category is PendingDeprecationWarning |
| 43 | assert msg2.message.args == ("more deprecated text",) |