From 2d5aadc79fb920e675a7b61c88ac13fb99af22a0 Mon Sep 17 00:00:00 2001 From: Seimen Date: Sat, 4 Jan 2025 09:35:17 +0100 Subject: [PATCH 1/3] type in docstring StreamArgs --- thermo/stream.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thermo/stream.py b/thermo/stream.py index f08e94df..dfd58ca2 100644 --- a/thermo/stream.py +++ b/thermo/stream.py @@ -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. From d98137c044d09a88a40f3b07052679c0800ae22b Mon Sep 17 00:00:00 2001 From: Seimen Date: Mon, 6 Jan 2025 12:55:15 +0100 Subject: [PATCH 2/3] added failing test for stream.copy() method on a user child class in test_stream.py --- tests/test_stream.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/test_stream.py b/tests/test_stream.py index 4f5b1df3..5c4f2c41 100644 --- a/tests/test_stream.py +++ b/tests/test_stream.py @@ -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(): From 363a9a3e464790d4e7ebedc4716930d00749d2c6 Mon Sep 17 00:00:00 2001 From: Seimen Date: Mon, 6 Jan 2025 12:57:05 +0100 Subject: [PATCH 3/3] bugfix .copy on stream objects break lisp. Instead, we're using the class ctor by invoke self.__class__ This fix is necessary to copy the slotted class. --- thermo/stream.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thermo/stream.py b/thermo/stream.py index dfd58ca2..73be071b 100644 --- a/thermo/stream.py +++ b/thermo/stream.py @@ -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 @@ -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