Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamArgs.copy() breaks lisp #166

Merged
merged 3 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,34 @@ def test_sub_streams():
assert m.CASs == ['7732-18-5']



@pytest.fixture(
params=[
(StreamArgs,{}),
(EnergyStream,dict(Q=0))
],
ids="StreamArgs EnergyStream".split()
)
def any_type_of_stream(request):
return request.param

def test_stream_copy(any_type_of_stream):
stream_type, param = any_type_of_stream
expected_args = stream_type(**param)
# when copied
stream_copy = expected_args.copy()
# then
assert isinstance(stream_copy, stream_type)

def test_child_class_copy(any_type_of_stream):
# lets say user wants to enhance StreamArgs class by:
stream_type, param = any_type_of_stream
class EnhancedStreamArgs(stream_type):
pass
expected_args = EnhancedStreamArgs(**param)
# when copied
stream_copy = expected_args.copy()
# then
assert isinstance(stream_copy, EnhancedStreamArgs)


def test_StreamArgs_flow_overspecified():
Expand Down
8 changes: 4 additions & 4 deletions thermo/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ class StreamArgs:
Handling flow flow vs. composition is fuzzier because of the common use cases
where a flow rate may be known, but not composition; or the composition but not
the flow, however later when the product
flows are known it is desireable to set it. To allow this,
flows are known it is desirable to set it. To allow this,
the variables `ns`, `ms`, `Qls`, and `Qgs` are allowed to overwrite an existing
flow and/or composition specification even if if `multiple_composition_basis` is False.

Eveen if the property wasn't set to this object, but if enough degrees of freedom
Even if the property wasn't set to this object, but if enough degrees of freedom
are known, the actual value can usually be queried by adding `_calc` to the attribute,
e.g. `H_calc` is available if `T`, `P`, and `zs` are known. This will perform the
flash if it hasn't already been done.
Expand Down Expand Up @@ -382,7 +382,7 @@ def copy(self):
kwargs['Vfgs'] = [i for i in kwargs['Vfgs']]
if kwargs['Vfls'] is not None:
kwargs['Vfls'] = [i for i in kwargs['Vfls']]
return StreamArgs(Vf_TP=self.Vf_TP, Q_TP=self.Q_TP, flasher=self.flasher,
return self.__class__(Vf_TP=self.Vf_TP, Q_TP=self.Q_TP, flasher=self.flasher,
multiple_composition_basis=self.multiple_composition_basis, **kwargs)

__copy__ = copy
Expand Down Expand Up @@ -2996,7 +2996,7 @@ def copy(self):
copy : EnergyStream
Copied Energy Stream, [-]
'''
return EnergyStream(Q=self.Q)
return self.__class__(Q=self.Q)

__copy__ = copy

Expand Down
Loading