<commit_before>import pytest

from gaphor.core.modeling import NamedElement, Presentation
from gaphor.diagram.general import Box, CommentLineItem, Ellipse, Line
from gaphor.diagram.presentation import Classified, Named
from gaphor.diagram.support import get_model_element
from gaphor.UML import Classifier, diagramitems


def _issubclass(child, parent):
    try:
        return issubclass(child, parent)
    except TypeError:
        return False


def all_items_and_elements():
    return [
        [cls, get_model_element(cls)]
        for cls in diagramitems.__dict__.values()
        if _issubclass(cls, Presentation) and get_model_element(cls)
    ]


@pytest.mark.parametrize(
    "item_class",
    [cls for cls in diagramitems.__dict__.values() if _issubclass(cls, Presentation)],
)
def test_all_diagram_items_have_a_model_element_mapping(item_class):
    if item_class in (Box, Line, Ellipse, CommentLineItem):
        assert not get_model_element(item_class)
    else:
        assert get_model_element(item_class)


NAMED_EXCLUSIONS = [
    diagramitems.ExecutionSpecificationItem,
    diagramitems.PartitionItem,
]


@pytest.mark.parametrize(
    "item_class,element_class",
    all_items_and_elements(),
)
def test_all_named_elements_have_named_items(item_class, element_class):
    if item_class in NAMED_EXCLUSIONS:
        return

    if issubclass(element_class, NamedElement):<commit_msg>Remove test for ContainmentItem since not a diagram item<commit_after>import pytest

from gaphor.core.modeling import NamedElement, Presentation
from gaphor.diagram.general import Box, CommentLineItem, Ellipse, Line
from gaphor.diagram.presentation import Classified, Named
from gaphor.diagram.support import get_model_element
from gaphor.UML import Classifier, diagramitems


def _issubclass(child, parent):
    try:
        return issubclass(child, parent)
    except TypeError:
        return False


def all_items_and_elements():
    return [
        [cls, get_model_element(cls)]
        for cls in diagramitems.__dict__.values()
        if _issubclass(cls, Presentation) and get_model_element(cls)
    ]


@pytest.mark.parametrize(
    "item_class",
    [cls for cls in diagramitems.__dict__.values() if _issubclass(cls, Presentation)],
)
def test_all_diagram_items_have_a_model_element_mapping(item_class):
    if item_class in (
        Box,
        Line,
        Ellipse,
        CommentLineItem,
        diagramitems.ContainmentItem,
    ):
        assert not get_model_element(item_class)
    else:
        assert get_model_element(item_class)


NAMED_EXCLUSIONS = [
    diagramitems.ExecutionSpecificationItem,
    diagramitems.PartitionItem,
]


@pytest.mark.parametrize(
    "item_class,element_class",
    all_items_and_elements(),
)
def test_all_named_elements_have_named_items(item_class, element_class):
    if item_class in NAMED_EXCLUSIONS:
        return

    if issubclass(element_class, NamedElement):
{'fraction_non_alphanumeric': 0.07342896174863388, 'fraction_numerical': 0.0, 'mean_word_length': 4.221033868092691, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5547768', 'n_tokens_mistral': 937, 'n_tokens_neox': 927, 'n_words': 198}