"""Test implementation (interface realization) item connectors."""

from gaphor import UML
from gaphor.tests import TestCase
from gaphor.UML.classes.implementation import ImplementationItem
from gaphor.UML.classes.interface import InterfaceItem
from gaphor.UML.classes.klass import ClassItem


class ImplementationTestCase(TestCase):
    def test_non_interface_glue(self):
        """Test non-interface gluing with implementation."""

        impl = self.create(ImplementationItem)
        clazz = self.create(ClassItem, UML.Class)

        glued = self.allow(impl, impl.head, clazz)
        # connecting head to non-interface item is disallowed
        self.assertFalse(glued)

    def test_interface_glue(self):
        """Test interface gluing with implementation."""
        iface = self.create(InterfaceItem, UML.Interface)
        impl = self.create(ImplementationItem)

        glued = self.allow(impl, impl.head, iface)
        assert glued

    def test_classifier_glue(self):
        """Test classifier gluing with implementation."""
        impl = self.create(ImplementationItem)
        clazz = self.create(ClassItem, UML.Class)

        glued = self.allow(impl, impl.tail, clazz)
        assert glued

    def test_connection(self):
        """Test connection of class and interface with implementation."""
        iface = self.create(InterfaceItem, UML.Interface)
        impl = self.create(ImplementationItem)
        clazz = self.create(ClassItem, UML.Class)

        self.connect(impl, impl.head, iface)
        self.connect(impl, impl.tail, clazz)

        # check the datamodel
        self.assertTrue(isinstance(impl.subject, UML.Implementation))
        ct = self.get_connected(impl.head)
        assert ct is iface
        assert impl.subject is not None
        assert impl.subject.contract is iface.subject
        assert impl.subject.implementatingClassifier is clazz.subject

    def test_reconnection(self):
        """Test reconnection of class and interface with implementation."""
        iface = self.create(InterfaceItem, UML.Interface)
        c1 = self.create(ClassItem, UML.Class)
        c2 = self.create(ClassItem, UML.Class)
        impl = self.create(ImplementationItem)

        # connect: iface -> c1
        self.connect(impl, impl.head, iface)
        self.connect(impl, impl.tail, c1)

        s = impl.subject

        # reconnect: iface -> c2
        self.connect(impl, impl.tail, c2)

        assert s is impl.subject
        assert iface.subject is impl.subject.contract
        assert c2.subject is impl.subject.implementatingClassifier
        assert c1.subject is not impl.subject.implementatingClassifier

@@ -88,42 +88,8 @@
 UML%0A
-from gaphor.tests import TestCase%0A
 from
@@ -259,16 +259,20 @@
 %0A%0Aclass 
+Test
 Implemen
@@ -281,26 +281,8 @@
 tion
-TestCase(TestCase)
 :%0A  
@@ -307,32 +307,38 @@
 erface_glue(self
+, case
 ):%0A        %22%22%22Te
@@ -393,36 +393,36 @@
 %0A        impl = 
+ca
 se
-lf
 .create(Implemen
@@ -441,36 +441,36 @@
         clazz = 
+ca
 se
-lf
 .create(ClassIte
@@ -492,36 +492,36 @@
         glued = 
+ca
 se
-lf
 .allow(impl, imp
@@ -609,31 +609,24 @@
     
-self.
 assert
-False(
+ not 
 glued
-)
 %0A%0A  
@@ -647,32 +647,38 @@
 erface_glue(self
+, case
 ):%0A        %22%22%22Te
@@ -729,36 +729,36 @@
         iface = 
+ca
 se
-lf
 .create(Interfac
@@ -786,36 +786,36 @@
 %0A        impl = 
+ca
 se
-lf
 .create(Implemen
@@ -835,36 +835,36 @@
         glued = 
+ca
 se
-lf
 .allow(impl, imp
@@ -929,24 +929,30 @@
 er_glue(self
+, case
 ):%0A        %22
@@ -1007,36 +1007,36 @@
 %0A        impl = 
+ca
 se
-lf
 .create(Implemen
@@ -1055,36 +1055,36 @@
         clazz = 
+ca
 se
-lf
 .create(ClassIte
@@ -1114,20 +1114,20 @@
 glued = 
+ca
 se
-lf
 .allow(i
@@ -1191,32 +1191,38 @@
 _connection(self
+, case
 ):%0A        %22%22%22Te
@@ -1290,36 +1290,36 @@
         iface = 
+ca
 se
-lf
 .create(Interfac
@@ -1347,36 +1347,36 @@
 %0A        impl = 
+ca
 se
-lf
 .create(Implemen
@@ -1403,20 +1403,20 @@
 clazz = 
+ca
 se
-lf
 .create(
@@ -1438,36 +1438,36 @@
 Class)%0A%0A        
+ca
 se
-lf
 .connect(impl, i
@@ -1483,36 +1483,36 @@
  iface)%0A        
+ca
 se
-lf
 .connect(impl, i
@@ -1571,24 +1571,15 @@
     
-self.
 assert
-True(
+ 
 isin
@@ -1618,17 +1618,16 @@
 ntation)
-)
 %0A       
@@ -1632,20 +1632,20 @@
    ct = 
+ca
 se
-lf
 .get_con
@@ -1884,16 +1884,22 @@
 ion(self
+, case
 ):%0A     
@@ -1985,20 +1985,20 @@
 iface = 
+ca
 se
-lf
 .create(
@@ -2040,20 +2040,20 @@
    c1 = 
+ca
 se
-lf
 .create(
@@ -2087,20 +2087,20 @@
    c2 = 
+ca
 se
-lf
 .create(
@@ -2136,20 +2136,20 @@
  impl = 
+ca
 se
-lf
 .create(
@@ -2200,36 +2200,36 @@
 e -%3E c1%0A        
+ca
 se
-lf
 .connect(impl, i
@@ -2245,36 +2245,36 @@
  iface)%0A        
+ca
 se
-lf
 .connect(impl, i
@@ -2355,20 +2355,20 @@
         
+ca
 se
-lf
 .connect

Convert gaphor/UML/classes/tests/test_implementationconnection.py to pytest