summaryrefslogtreecommitdiffstats
path: root/tests/test_deprecated.py
blob: fd4de829be8791f74feeca2ec8c935dac7365077 (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
import warnings

import pytest

from tests.output_aristaproto.deprecated import (
    Message,
    Test,
)


@pytest.fixture
def message():
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", category=DeprecationWarning)
        return Message(value="hello")


def test_deprecated_message():
    with pytest.warns(DeprecationWarning) as record:
        Message(value="hello")

    assert len(record) == 1
    assert str(record[0].message) == f"{Message.__name__} is deprecated"


def test_message_with_deprecated_field(message):
    with pytest.warns(DeprecationWarning) as record:
        Test(message=message, value=10)

    assert len(record) == 1
    assert str(record[0].message) == f"{Test.__name__}.message is deprecated"


def test_message_with_deprecated_field_not_set(message):
    with pytest.warns(None) as record:
        Test(value=10)

    assert not record


def test_message_with_deprecated_field_not_set_default(message):
    with pytest.warns(None) as record:
        _ = Test(value=10).message

    assert not record