from radiuma_api.io_port import (
    CompositeType,
    ImageType,
    TextType,
    TableType,
    CompatibilityException
)

def test_composite_type_success():
    t1 = CompositeType({
        "img": ImageType(),
        "meta": TextType(language="en")
    })

    t2 = CompositeType({
        "img": ImageType(),
        "meta": TextType(language="en")
    })

    # Must succeed
    t1.can_connect_to(t2)


def test_composite_type_key_mismatch():
    t1 = CompositeType({"img": ImageType()})
    t2 = CompositeType({"image": ImageType()})

    try:
        t1.can_connect_to(t2)
        assert False, "Expected CompositeType key mismatch"
    except CompatibilityException:
        assert True


def test_composite_type_internal_type_mismatch():
    t1 = CompositeType({"img": ImageType(modality="nifti")})
    t2 = CompositeType({"img": ImageType(modality="dicom")})

    try:
        t1.can_connect_to(t2)
        assert False, "Expected internal DType mismatch"
    except CompatibilityException:
        assert True
