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

Added descriptive error text to assert statements #1816

Merged
merged 4 commits into from
Nov 23, 2024
Merged
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
24 changes: 17 additions & 7 deletions interfaces/cython/cantera/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@
else:
self.mass = 1.0

assert constant in ('TP','TV','HP','SP','SV','UV')
if constant not in ('TP','TV','HP','SP','SV','UV'):
raise ValueError(

Check warning on line 234 in interfaces/cython/cantera/composite.py

View check run for this annotation

Codecov / codecov/patch

interfaces/cython/cantera/composite.py#L234

Added line #L234 was not covered by tests
f"Constant {constant} is invalid. "
"Must be one of 'TP','TV','HP','SP','SV', or 'UV'")
self.constant = constant

@property
Expand Down Expand Up @@ -314,9 +317,13 @@

def __iadd__(self, other):
if self._id != other._id:
raise ValueError('Cannot add Quantities with different phase '
'definitions.')
assert self.constant == other.constant
raise ValueError(
'Cannot add Quantities with different phase '
f'definitions. {self._id} != {other._id}')
if self.constant != other.constant:
raise ValueError(

Check warning on line 324 in interfaces/cython/cantera/composite.py

View check run for this annotation

Codecov / codecov/patch

interfaces/cython/cantera/composite.py#L324

Added line #L324 was not covered by tests
"Cannot add Quantities with different "
f"constant values. {self.constant} != {other.constant}")

m = self.mass + other.mass
Y = (self.Y * self.mass + other.Y * other.mass)
Expand All @@ -331,7 +338,8 @@
else: # self.constant == 'HP'
dp_rel = 2 * abs(self.P - other.P) / (self.P + other.P)
if dp_rel > 1.0e-7:
raise ValueError('Cannot add Quantities at constant pressure when'
raise ValueError(
'Cannot add Quantities at constant pressure when '
f'pressure is not equal ({self.P} != {other.P})')

H = self.enthalpy + other.enthalpy
Expand Down Expand Up @@ -1329,7 +1337,8 @@
return a, b

def setter(self, AB):
assert len(AB) == 2, "Expected 2 elements, got {}".format(len(AB))
if len(AB) != 2:
raise ValueError("Expected 2 elements, got {}".format(len(AB)))

Check warning on line 1341 in interfaces/cython/cantera/composite.py

View check run for this annotation

Codecov / codecov/patch

interfaces/cython/cantera/composite.py#L1341

Added line #L1341 was not covered by tests
A, B, _ = np.broadcast_arrays(AB[0], AB[1], self._output_dummy)
for loc, index in enumerate(self._indices):
self._set_loc(loc)
Expand All @@ -1355,7 +1364,8 @@
return a, b, c

def setter(self, ABC):
assert len(ABC) == 3, "Expected 3 elements, got {}".format(len(ABC))
if len(ABC) != 3:
raise ValueError("Expected 3 elements, got {}".format(len(ABC)))

Check warning on line 1368 in interfaces/cython/cantera/composite.py

View check run for this annotation

Codecov / codecov/patch

interfaces/cython/cantera/composite.py#L1368

Added line #L1368 was not covered by tests
A, B, _ = np.broadcast_arrays(ABC[0], ABC[1], self._output_dummy)
XY = ABC[2] # composition
if len(np.shape(XY)) < 2:
Expand Down
Loading