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 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
import warnings
import pytest
from tests.mocks import MockChannel
from tests.output_aristaproto.deprecated import (
Empty,
Message,
Test,
TestServiceStub,
)
@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 warnings.catch_warnings():
warnings.simplefilter("error")
Test(value=10)
def test_message_with_deprecated_field_not_set_default(message):
with warnings.catch_warnings():
warnings.simplefilter("error")
_ = Test(value=10).message
@pytest.mark.asyncio
async def test_service_with_deprecated_method():
stub = TestServiceStub(MockChannel([Empty(), Empty()]))
with pytest.warns(DeprecationWarning) as record:
await stub.deprecated_func(Empty())
assert len(record) == 1
assert str(record[0].message) == "TestService.deprecated_func is deprecated"
with warnings.catch_warnings():
warnings.simplefilter("error")
await stub.func(Empty())
|