Skip to content

Commit

Permalink
[Units] Add tests that all properties are implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanwweber authored and speth committed Apr 25, 2023
1 parent 97de761 commit c64773d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/python/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from typing import Optional, Tuple, Dict

import cantera.with_units as ctu
import cantera as ct
import numpy as np
from pint.testing import assert_allclose


Expand Down Expand Up @@ -514,3 +516,36 @@ def test_X_Y_setters_without_units_works(generic_phase, prop):
composition = f"{generic_phase.species_names[0]}:1"
setattr(generic_phase, prop, composition)
assert_allclose(getattr(generic_phase, prop)[0], ctu.Q_([1], "dimensionless"))


def test_thermophase_properties_exist(ideal_gas):
# Since the Solution class in the with_units subpackage only implements
# the ThermoPhase interface for now, instantiate a regular ThermoPhase
# to compare the attributes and make sure all of them exist on the with_units
# object
tp = ct.ThermoPhase("h2o2.yaml")

for attr in dir(tp):
if attr.startswith("_"): # or attr in skip:
continue

try:
getattr(tp, attr)
except (ct.CanteraError, ct.ThermoModelMethodError):
continue

assert hasattr(ideal_gas, attr)


def test_purefluid_properties_exist(pure_fluid):
pf = ct.PureFluid("liquidvapor.yaml", "water")
for attr in dir(pf):
if attr.startswith("_"):
continue

try:
getattr(pf, attr)
except (ct.CanteraError, ct.ThermoModelMethodError):
continue

assert hasattr(pure_fluid, attr)

0 comments on commit c64773d

Please sign in to comment.