Skip to content

Commit

Permalink
add network test
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Apr 20, 2024
1 parent 8a9e3df commit 9faa0ac
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
"""
"""

def test_disconnect():
import thermosteam as tmo
class Mix(tmo.AbstractUnit):
_N_ins = 2
_N_outs = 1
_ins_size_is_fixed = False

class Split(tmo.AbstractUnit):
_N_ins = 1
_N_outs = 2
_outs_size_is_fixed = False

tmo.settings.set_thermo([])
M = Mix(ins=())
S = Split(ins=())

# Test outs size fixed
M.outs[0].disconnect_source()
assert len(M.outs) == 1 and isinstance(M.outs[0], tmo.AbstractMissingStream)

# Test ins size not fixed
M.ins[0].disconnect_sink()
assert len(M.ins) == 1 and isinstance(M.ins[0], tmo.AbstractStream)

# Test ins size fixed
S.ins[0].disconnect_sink()
assert len(S.ins) == 1 and isinstance(S.ins[0], tmo.AbstractMissingStream)

# Test outs size not fixed
S.outs[0].disconnect_source()
assert len(S.outs) == 1 and isinstance(S.outs[0], tmo.AbstractStream)


if __name__ == '__main__':
test_disconnect()
3 changes: 3 additions & 0 deletions thermosteam/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ class AbstractMissingStream:
__slots__ = ('_source', '_sink')
line = 'Stream'
ID = 'missing stream'
disconnect_source = AbstractStream.disconnect_source
disconnect_sink = AbstractStream.disconnect_sink
disconnect = AbstractStream.disconnect

def __init__(self, source=None, sink=None):
self._source = source
Expand Down

0 comments on commit 9faa0ac

Please sign in to comment.