From 3163c38f89e6a685c98e211fc66c83d6570113a1 Mon Sep 17 00:00:00 2001 From: raphaeltimbo Date: Mon, 20 Jul 2026 21:13:49 -0300 Subject: [PATCH] Add CoolProp 8 compatibility, drop coolprop<8 dev constraint CoolProp 8 raises ValueError (was RuntimeError in v7) for unknown fluids in get_REFPROPname, so catch both in fluids.get_name. The reworked cubic EOS saturation routines in v8 also introduce ~1e-10 roundoff in the PR/SRK pressure roundtrip, so test_eos and test_eos_config now compare p with assert_allclose instead of exact equality. With ccp compatible with both major versions, remove the constraint-dependencies = ["coolprop<8"] dev/CI pin from [tool.uv]. --- ccp/config/fluids.py | 9 +++++---- ccp/tests/test_state.py | 8 ++++---- pyproject.toml | 4 ---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/ccp/config/fluids.py b/ccp/config/fluids.py index f0ec754..70d57c7 100644 --- a/ccp/config/fluids.py +++ b/ccp/config/fluids.py @@ -81,10 +81,11 @@ def get_name(name): try: fluid_name = CP.get_REFPROPname(name) - # CoolProp returns empty string for invalid fluid names - if not fluid_name: - raise ValueError(f"Fluid {name} not available. See ccp.fluid_list. ") - except RuntimeError: + # CoolProp raises RuntimeError (v7) or ValueError (v8) for unknown fluids, + # and returns an empty string for invalid names + except (RuntimeError, ValueError): + fluid_name = "" + if not fluid_name: raise ValueError(f"Fluid {name} not available. See ccp.fluid_list. ") return fluid_name diff --git a/ccp/tests/test_state.py b/ccp/tests/test_state.py index 285e5da..a9ee301 100644 --- a/ccp/tests/test_state.py +++ b/ccp/tests/test_state.py @@ -52,7 +52,7 @@ def test_eos(): ) assert state.p().units == "pascal" assert state.T().units == "kelvin" - assert state.p().magnitude == 100000 + assert_allclose(state.p().magnitude, 100000) assert state.T().magnitude == 300 assert_allclose(state.rhomass(), 0.6445687063978816, rtol=1e-6) @@ -61,7 +61,7 @@ def test_eos(): ) assert state.p().units == "pascal" assert state.T().units == "kelvin" - assert state.p().magnitude == 100000 + assert_allclose(state.p().magnitude, 100000) assert state.T().magnitude == 300 assert_allclose(state.rhomass(), 0.6442384800595821, rtol=1e-6) @@ -88,7 +88,7 @@ def test_eos_config(): state = State(p=100000, T=300, fluid={"Methane": 1 - 1e-15, "Ethane": 1e-15}) assert state.p().units == "pascal" assert state.T().units == "kelvin" - assert state.p().magnitude == 100000 + assert_allclose(state.p().magnitude, 100000) assert state.T().magnitude == 300 assert_allclose(state.rhomass(), 0.6445687063978816, rtol=1e-6) @@ -96,7 +96,7 @@ def test_eos_config(): state = State(p=100000, T=300, fluid={"Methane": 1 - 1e-15, "Ethane": 1e-15}) assert state.p().units == "pascal" assert state.T().units == "kelvin" - assert state.p().magnitude == 100000 + assert_allclose(state.p().magnitude, 100000) assert state.T().magnitude == 300 assert_allclose(state.rhomass(), 0.6442384800595821, rtol=1e-6) diff --git a/pyproject.toml b/pyproject.toml index 64d5ea5..c690e58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -112,7 +112,3 @@ dev = [ [tool.uv] package = true -# Dev/CI resolution constraint only (does not affect published metadata): -# CoolProp 8 changed the exception type raised for unknown fluids and the -# cubic-EOS roundoff, breaking three tests. Remove once ccp is adapted. -constraint-dependencies = ["coolprop<8"]