|
8 | 8 | import types |
9 | 9 | import warnings |
10 | 10 |
|
| 11 | +import pytest |
| 12 | + |
11 | 13 | from cryptography.utils import deprecated |
12 | 14 |
|
13 | 15 |
|
@@ -45,3 +47,42 @@ def test_deprecated(self, monkeypatch): |
45 | 47 | assert msg2.message.args == ("more deprecated text",) |
46 | 48 |
|
47 | 49 | assert "Y" in dir(mod) |
| 50 | + |
| 51 | + def test_deleting_deprecated_members(self, monkeypatch): |
| 52 | + mod = types.ModuleType("TestDeprecated/test_deprecated") |
| 53 | + monkeypatch.setitem(sys.modules, mod.__name__, mod) |
| 54 | + mod.X = deprecated( |
| 55 | + value=1, |
| 56 | + module_name=mod.__name__, |
| 57 | + message="deprecated message text", |
| 58 | + warning_class=DeprecationWarning |
| 59 | + ) |
| 60 | + mod.Y = deprecated( |
| 61 | + value=2, |
| 62 | + module_name=mod.__name__, |
| 63 | + message="more deprecated text", |
| 64 | + warning_class=PendingDeprecationWarning, |
| 65 | + ) |
| 66 | + mod = sys.modules[mod.__name__] |
| 67 | + mod.Z = 3 |
| 68 | + |
| 69 | + with warnings.catch_warnings(record=True) as log: |
| 70 | + warnings.simplefilter("always", PendingDeprecationWarning) |
| 71 | + warnings.simplefilter("always", DeprecationWarning) |
| 72 | + del mod.X |
| 73 | + del mod.Y |
| 74 | + del mod.Z |
| 75 | + |
| 76 | + [msg1, msg2] = log |
| 77 | + assert msg1.category is DeprecationWarning |
| 78 | + assert msg1.message.args == ("deprecated message text",) |
| 79 | + |
| 80 | + assert msg2.category is PendingDeprecationWarning |
| 81 | + assert msg2.message.args == ("more deprecated text",) |
| 82 | + |
| 83 | + assert "X" not in dir(mod) |
| 84 | + assert "Y" not in dir(mod) |
| 85 | + assert "Z" not in dir(mod) |
| 86 | + |
| 87 | + with pytest.raises(AttributeError): |
| 88 | + del mod.X |
0 commit comments