gaphor/tests/test_issue_53.py
2020-05-29 13:51:55 +02:00

68 lines
1.8 KiB
Python

import pytest
from gaphor import UML
from gaphor.application import Session, distribution
from gaphor.storage.storage import load
@pytest.fixture
def session():
session = Session()
yield session
session.shutdown()
@pytest.fixture
def element_factory(session):
element_factory = session.get_service("element_factory")
modeling_language = session.get_service("modeling_language")
path = distribution().locate_file("test-models/issue_53.gaphor")
load(path, element_factory, modeling_language)
yield element_factory
element_factory.shutdown()
def test_package_removal(session, element_factory):
# Find all profile instances
profiles = element_factory.lselect(UML.Profile)
# Check there is 1 profile
assert len(profiles) == 1
# Check the profile has 1 presentation
assert len(profiles[0].presentation) == 1
# Unlink the presentation
profiles[0].presentation[0].unlink()
assert not element_factory.lselect(UML.Profile)
classes = element_factory.lselect(UML.Class)
assert len(classes) == 1
# Check if the link is really removed:
assert not classes[0].appliedStereotype
assert not element_factory.lselect(UML.InstanceSpecification)
assert len(element_factory.lselect(UML.Diagram)) == 3
def test_package_removal_by_removing_the_diagram(element_factory):
diagram = element_factory.lselect(
lambda e: e.isKindOf(UML.Diagram) and e.name == "Stereotypes diagram"
)[0]
assert diagram
diagram.unlink()
assert not element_factory.lselect(UML.Profile)
classes = element_factory.lselect(UML.Class)
assert len(classes) == 1
# Check if the link is really removed:
assert not classes[0].appliedStereotype
assert not element_factory.lselect(UML.InstanceSpecification)
assert len(element_factory.lselect(UML.Diagram)) == 2