Skip to content

test: use public API in assertions instead of internal .data#760

Merged
FabianHofmann merged 1 commit into
PyPSA:masterfrom
fluxopt:test/public-api-assertions
Jun 7, 2026
Merged

test: use public API in assertions instead of internal .data#760
FabianHofmann merged 1 commit into
PyPSA:masterfrom
fluxopt:test/public-api-assertions

Conversation

@FBumann
Copy link
Copy Markdown
Collaborator

@FBumann FBumann commented Jun 4, 2026

This is meant to harden the "public" vs internal api a bit more. It will allow to potentially improve/change the datamodel of linopy if needed in certain places, while being fully backwards compatible.

Note

The following content was generated by AI.

Summary

Switches test assertions from the internal .data accessor to the public .coords / .indexes / .sizes properties. These properties are thin pass-throughs to .data, so the assertions exercise identical data — this is a readability/encapsulation cleanup that stops tests from reaching through .data.

  • test_variable.pyvar.sizes, var.coords[...] (and base.coords when seeding add_variables)
  • test_linear_expression.pyresult.indexes[...], plus coord-building helpers and the HELPER_DIMS-cleanliness check
  • test_constraint.pycon.sizes[...] and the HELPER_DIMS intersection check

Genuine helper-dim checks

_factor size checks in test_quadratic_expression.py stay on the internal array, since no public accessor surfaces that helper dim. They now use .vars.sizes[FACTOR_DIM] — the _factor dim lives on vars, not coeffs (coeffs only carries _term). The existing .coeffs.dims / .const.dims factor checks are left as-is.

The HELPER_DIMS-intersection assertions deliberately stay on .coords (not .coord_dims): .coords is an unfiltered pass-through, so the check remains real, whereas .coord_dims filters helper dims and would make the assertion a tautology.

Testing

pytest test/test_variable.py test/test_linear_expression.py test/test_constraint.py test/test_quadratic_expression.py — 504 passed.

Switch test assertions from the internal `.data` accessor to the public
`.coords`/`.indexes`/`.sizes` properties (thin pass-throughs to `.data`,
so behaviour is identical).

Genuine `_factor` dimension checks in test_quadratic_expression stay on
the internal array, but now use `.vars.sizes[FACTOR_DIM]` — the `_factor`
helper dim lives on `vars`, not `coeffs`, and isn't surfaced by any
public accessor.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@FBumann FBumann requested a review from FabianHofmann June 4, 2026 20:08
@FBumann FBumann marked this pull request as ready for review June 5, 2026 06:30
@FabianHofmann FabianHofmann merged commit fdf613d into PyPSA:master Jun 7, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants