sdk-python/cloudevents/tests/test_converters.py

43 lines
1.5 KiB
Python

# Copyright 2018-Present The CloudEvents Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import pytest
from cloudevents.sdk import exceptions
from cloudevents.sdk.converters import base, binary
def test_binary_converter_raise_unsupported():
with pytest.raises(exceptions.UnsupportedEvent):
cnvtr = binary.BinaryHTTPCloudEventConverter()
cnvtr.read(None, {}, None, None) # type: ignore[arg-type] # intentionally wrong type # noqa: E501
def test_base_converters_raise_exceptions():
with pytest.raises(Exception):
cnvtr = base.Converter()
cnvtr.event_supported(None)
with pytest.raises(Exception):
cnvtr = base.Converter()
cnvtr.can_read(None)
with pytest.raises(Exception):
cnvtr = base.Converter()
cnvtr.write(None, None) # type: ignore[arg-type] # intentionally wrong type
with pytest.raises(Exception):
cnvtr = base.Converter()
cnvtr.read(None, None, None, None) # type: ignore[arg-type] # intentionally wrong type # noqa: E501