Skip to content

Commit cf99f19

Browse files
committed
Extends D2HashableConnection's __eq__ method to also validate label
1 parent 1a7800c commit cf99f19

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

specifipy/diagram_engines/hashable_connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ def __hash__(self):
66
return hash((self.shape_1, self.shape_2, self.direction))
77

88
def __eq__(self, other) -> bool:
9-
if (self.shape_1, self.shape_2, self.direction) == (
9+
if (self.shape_1, self.shape_2, self.direction, self.label) == (
1010
other.shape_1,
1111
other.shape_2,
1212
other.direction,
13+
other.label,
1314
):
1415
return True
1516
return False

tests/test_diagram_engines.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,18 @@ def test_connections_uniqueness(self):
1010
connection_1 = D2HashableConnection("a", "b", "some_label", Direction.TO)
1111
connection_2 = D2HashableConnection("a", "b", "some_label", Direction.TO)
1212
assert connection_1 == connection_2
13+
14+
def test_connections_hash(self):
15+
connection_1 = D2HashableConnection("a", "b", "some_label", Direction.TO)
16+
assert isinstance(connection_1.__hash__(), int)
17+
18+
def test_connections_not_equal(self):
19+
connection_1 = D2HashableConnection("a", "b", "some_label", Direction.TO)
20+
connection_2 = D2HashableConnection("a", "b", "some_label2", Direction.TO)
21+
connection_3 = D2HashableConnection("a1", "b", "some_label", Direction.TO)
22+
connection_4 = D2HashableConnection("a", "b1", "some_label", Direction.TO)
23+
connection_5 = D2HashableConnection("a", "b", "some_label", Direction.FROM)
24+
assert connection_1 != connection_2
25+
assert connection_1 != connection_3
26+
assert connection_1 != connection_4
27+
assert connection_1 != connection_5

0 commit comments

Comments
 (0)