From 080d0e8471942acf37d2818604b1a01687cedd83 Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Tue, 2 Sep 2025 14:00:16 +0200 Subject: [PATCH 1/4] Improve assert_conequal --- tests/conftest.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5399be72a..4c483c2ca 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -457,10 +457,16 @@ def assert_conequal(actual: linopy.Constraint, desired: linopy.Constraint): except AssertionError as e: raise AssertionError(f"{name} left-hand sides don't match:\n{e}") from e - try: - linopy.testing.assert_linequal(actual.rhs, desired.rhs) - except AssertionError as e: - raise AssertionError(f"{name} right-hand sides don't match:\n{e}") from e + if isinstance(actual.rhs, xr.DataArray): + try: + xr.testing.assert_equal(actual.rhs, desired.rhs) + except AssertionError as e: + raise AssertionError(f"{name} right-hand sides don't match:\n{e}") from e + else: + try: + linopy.testing.assert_linequal(actual.rhs, desired.rhs) + except AssertionError as e: + raise AssertionError(f"{name} right-hand sides don't match:\n{e}") from e try: xr.testing.assert_equal(actual.sign, desired.sign) From a8b748140a1edfb58c326c12efd552c70e604799 Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Tue, 2 Sep 2025 20:06:27 +0200 Subject: [PATCH 2/4] Improve assert_conequal and fix linopy dependency --- pyproject.toml | 2 +- tests/conftest.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8c846dc03..4624d3a00 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ dependencies = [ "pandas >= 2.0.0, < 3", # Optimization and data handling - "linopy >= 0.5.1, < 0.6.0", + "linopy >= 0.5.1, < 0.5.6", # Update and test regularly "netcdf4 >= 1.6.1, < 2", # Utilities diff --git a/tests/conftest.py b/tests/conftest.py index 4c483c2ca..fbab7a388 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -457,14 +457,14 @@ def assert_conequal(actual: linopy.Constraint, desired: linopy.Constraint): except AssertionError as e: raise AssertionError(f"{name} left-hand sides don't match:\n{e}") from e - if isinstance(actual.rhs, xr.DataArray): + if isinstance(actual.rhs, linopy.Constraint): try: - xr.testing.assert_equal(actual.rhs, desired.rhs) + linopy.testing.assert_linequal(actual.rhs, desired.rhs) except AssertionError as e: raise AssertionError(f"{name} right-hand sides don't match:\n{e}") from e else: try: - linopy.testing.assert_linequal(actual.rhs, desired.rhs) + xr.testing.assert_equal(actual.rhs, desired.rhs) except AssertionError as e: raise AssertionError(f"{name} right-hand sides don't match:\n{e}") from e From 19757efd1db25b74816db818a665c67790c5b83b Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Tue, 2 Sep 2025 21:25:37 +0200 Subject: [PATCH 3/4] Improve assert_conequal and fix linopy dependency --- CHANGELOG.md | 3 +++ tests/conftest.py | 21 +++++++-------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6232a61f7..94ea53017 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deprecated - For the classes `Sink`, `Source` and `SourceAndSink`: `.sink`, `.source` and `.prevent_simultaneous_sink_and_source` are deprecated in favor of the new arguments `inputs`, `outputs` and `prevent_simultaneous_flow_rates`. +### Fixed +- Fixed testing issue with new `linopy` version 0.5.6 + ## [2.1.5] - 2025-07-08 ### Fixed diff --git a/tests/conftest.py b/tests/conftest.py index fbab7a388..c8d2e5606 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -450,28 +450,21 @@ def basic_flow_system_linopy(timesteps_linopy) -> fx.FlowSystem: def assert_conequal(actual: linopy.Constraint, desired: linopy.Constraint): """Assert that two constraints are equal with detailed error messages.""" - name = actual.name try: linopy.testing.assert_linequal(actual.lhs, desired.lhs) except AssertionError as e: - raise AssertionError(f"{name} left-hand sides don't match:\n{e}") from e - - if isinstance(actual.rhs, linopy.Constraint): - try: - linopy.testing.assert_linequal(actual.rhs, desired.rhs) - except AssertionError as e: - raise AssertionError(f"{name} right-hand sides don't match:\n{e}") from e - else: - try: - xr.testing.assert_equal(actual.rhs, desired.rhs) - except AssertionError as e: - raise AssertionError(f"{name} right-hand sides don't match:\n{e}") from e + raise AssertionError(f"{actual.name} left-hand sides don't match:\n{e}") from e try: xr.testing.assert_equal(actual.sign, desired.sign) except AssertionError as e: - raise AssertionError(f"{name} signs don't match:\nActual: {actual.sign}\nExpected: {desired.sign}") from e + raise AssertionError(f"{actual.name} signs don't match:\n{e}") from e + + try: + xr.testing.assert_equal(actual.rhs, desired.rhs) + except AssertionError as e: + raise AssertionError(f"{actual.name} right-hand sides don't match:\n{e}") from e def assert_var_equal(actual: linopy.Variable, desired: linopy.Variable): From 6bfe8ef601a53b6a4e5bdf9aeebdb315d7752b58 Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Tue, 2 Sep 2025 21:30:28 +0200 Subject: [PATCH 4/4] Improce CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94ea53017..f689f5121 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - For the classes `Sink`, `Source` and `SourceAndSink`: `.sink`, `.source` and `.prevent_simultaneous_sink_and_source` are deprecated in favor of the new arguments `inputs`, `outputs` and `prevent_simultaneous_flow_rates`. ### Fixed -- Fixed testing issue with new `linopy` version 0.5.6 +- Fixed testing issue with new `linopy` version 0.5.6 [[#296](https://github.com/PyPSA/linopy/pull/296) by [@FBumann](https://github.com/FBumann)] ## [2.1.5] - 2025-07-08