Skip to content

Commit

Permalink
Standardize lbmol unit (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeambrus authored May 5, 2023
1 parent 14cd560 commit 9f804f9
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 59 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.17.0 (2023-05-02)
-------------------

* Standardize the usage of ``lbmol``
* Add more valid units for ``mole per mass`` category

1.16.0 (2023-04-26)
-------------------

Expand Down
30 changes: 30 additions & 0 deletions src/barril/units/_tests/test_legacy_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,33 @@ class SomeNonExpectedObject:

category = unit_database_posc.GetDefaultCategory(SomeNonExpectedObject())
assert category is None


def testAddCategoryWithLegacyUnit(unit_database_posc) -> None:
"""Try creating a category with legacy unit"""
unit_database_posc.AddCategory(
category="molar-mass",
quantity_type="mass per mol",
valid_units=["g/mol", "kg/mol", "lb/lbmole"],
default_value=100,
min_value=0,
is_min_exclusive=True,
caption="Molar Mass",
)
valid_units = unit_database_posc.GetValidUnits("molar-mass")
assert sorted(valid_units) == sorted(["g/mol", "kg/mol", "lb/lbmol"])


def testAddCategoryWithLegacyDefaultUnit(unit_database_posc) -> None:
"""Try creating a category with legacy default unit"""
unit_database_posc.AddCategory(
category="molar-mass",
quantity_type="mass per mol",
default_unit="lb/lbmole",
default_value=100,
min_value=0,
is_min_exclusive=True,
caption="Molar Mass",
)
valid_units = unit_database_posc.GetValidUnits("molar-mass")
assert sorted(valid_units) == sorted(["g/mol", "kg/mol", "lb/lbmol"])
10 changes: 6 additions & 4 deletions src/barril/units/_tests/test_posc_additional_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def testDensityGeneration(db) -> None:


def testMolarDensity(db) -> None:
db.CheckQuantityTypeUnit("amount of a substance", "gmole/m3")
db.CheckQuantityTypeUnit("concentration of B", "gmole/m3")
db.CheckQuantityTypeUnit("amount of a substance", "gmol/m3")
db.CheckQuantityTypeUnit("concentration of B", "gmol/m3")


def testPartsPerMillionByVolumeConcentration(db) -> None:
Expand Down Expand Up @@ -172,7 +172,7 @@ def testMassPerMol(db) -> None:

assert gpermol_to_kgpermol == 1
assert kgpermol_to_gpermol == 1000
assert db.Convert("mass per mol", "g/mol", "lb/lbmole", 1) == 1
assert db.Convert("mass per mol", "g/mol", "lb/lbmol", 1) == 1


@pytest.mark.parametrize("category", ["mole per mass", "molality"])
Expand All @@ -182,7 +182,9 @@ def testMolPerMass(db, category) -> None:

assert molperg_to_molperkg == 1000
assert molperkg_to_molperg == 0.001
assert db.Convert(category, "mol/g", "lbmole/lb", 1) == 1
assert db.Convert(category, "mol/g", "lbmol/lb", 1) == 1
valid_units = db.GetValidUnits(category)
assert valid_units == ["mol/kg", "mol/g", "lbmol/lb"]


def testInjectivityFactor(db) -> None:
Expand Down
Loading

0 comments on commit 9f804f9

Please sign in to comment.