import pytest

from iterable.datatypes import ProtobufIterable

# Note: Protocol Buffers requires a message class definition
# This test will be skipped if protobuf is not available


class TestProtobuf:
    def test_id(self):
        try:
            datatype_id = ProtobufIterable.id()
            assert datatype_id == "protobuf"
        except ImportError:
            pytest.skip("Protocol Buffers support requires protobuf package")

    def test_flatonly(self):
        try:
            flag = ProtobufIterable.is_flatonly()
            assert not flag
        except ImportError:
            pytest.skip("Protocol Buffers support requires protobuf package")

    def test_requires_message_class(self):
        try:
            with pytest.raises(ValueError):
                ProtobufIterable("test.pb", mode="r")
        except ImportError:
            pytest.skip("Protocol Buffers support requires protobuf package")
