Make Item protocol runtime checkable

This commit is contained in:
Arjan Molenaar 2020-11-15 15:08:44 +01:00
parent ab75c770fe
commit 8a2655b643
2 changed files with 15 additions and 2 deletions

View File

@ -1,6 +1,6 @@
"""Basic items."""
from math import atan2
from typing import Protocol, Sequence
from typing import Protocol, Sequence, runtime_checkable
from gaphas.canvas import Context
from gaphas.connector import Handle, LinePort, Port
@ -16,6 +16,7 @@ from gaphas.state import (
)
@runtime_checkable
class Item(Protocol):
@property
def matrix(self) -> Matrix:

View File

@ -4,7 +4,7 @@ The test check functionality of `Item.constraint` method, not
constraints themselves.
"""
from gaphas.item import Element, Line
from gaphas.item import Element, Item, Line
class Custom:
@ -30,3 +30,15 @@ def test_can_pass_arbitrary_arguments_to_a_line(connections):
assert t.custom == "custom"
assert t._connections is connections
def test_element_implements_item_protocol(connections):
element = Element(connections)
assert isinstance(element, Item)
def test_line_implements_item_protocol(connections):
line = Line(connections)
assert isinstance(line, Item)