Skip to content

Commit

Permalink
dgstreams: implemented protection against double connection
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-nn committed Nov 11, 2024
1 parent b6836b8 commit 5ec112c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions degirum_tools/streams_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ def connect_to(self, other_gizmo, inp: Union[int, Stream] = 0):
Returns self
"""
other_gizmo._output_refs.append(
self.get_input(inp) if isinstance(inp, int) else inp
)
inp_stream = self.get_input(inp) if isinstance(inp, int) else inp
if not inp_stream in other_gizmo._output_refs:
other_gizmo._output_refs.append(inp_stream)
self._connected_gizmos.add(other_gizmo)
other_gizmo._connected_gizmos.add(self)
return self
Expand Down
8 changes: 8 additions & 0 deletions test/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ def test_streams_connection(short_video):
source = streams.VideoSourceGizmo(short_video)
sink = VideoSink()
c = streams.Composition(source >> sink)
assert source._connected_gizmos == {sink}
assert sink._connected_gizmos == {source}
assert set(c._gizmos) == {source, sink}

# double connection: should be the same as single connection
source = streams.VideoSourceGizmo(short_video)
sink = VideoSink()
c = streams.Composition(source >> sink, source >> sink)
assert len(source._output_refs) == 1 and source._output_refs[0] is sink.get_input(0)
assert source._connected_gizmos == {sink}
assert sink._connected_gizmos == {source}
assert set(c._gizmos) == {source, sink}
Expand Down

0 comments on commit 5ec112c

Please sign in to comment.