Skip to content

Add unit tests for Cube.coord_dims - #7198

Merged
ESadek-MO merged 5 commits into
SciTools:mainfrom
01luyicheng:add-cube-coord-dims-unit-tests
Aug 6, 2026
Merged

ESadek-MO merged 5 commits into
SciTools:mainfrom
01luyicheng:add-cube-coord-dims-unit-tests

Conversation

@01luyicheng

@01luyicheng 01luyicheng commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds specific unit tests for Cube.coord_dims, addressing #4552.

Cube.coord_dims previously had no direct unit tests in lib/iris/tests/unit/cube/test_Cube.py (the existing Coord.cube_dims / CellMeasure.cube_dims / AncillaryVariable.cube_dims tests only mock-verify that those methods delegate to Cube.coord_dims, without exercising coord_dims itself).

This adds a Test_coord_dims class covering the seven scenarios listed in the issue, each exercising a distinct branch of the method:

Scenario (from #4552) Test
coord on the cube test_dim_coord
coord not on the cube (but matches one that is) test_equivalent_coord_not_instance
coord not on the cube (and doesn't match one that is) test_no_match_raises
string test_string_name
coord on multiple dims test_aux_coord_multiple_dims
coord is aux factory test_aux_factory
coord is aux_coord test_aux_coord_single_dim

Closes #4552.

Checklist

  • Included a What's New entry — added in changelog/ (follow-up commit)
  • Incorporated type hints in any changed code — N/A (test-only; existing tests in this file do not use type hints)
  • Checked if tests need updating — this PR adds the tests
  • Checked if benchmarks need updating — N/A
  • Checked if documentation needs updating — N/A
  • Checked if dependencies need updating — N/A
  • Confirmed that the GitHub 'checks' on this PR are passing — pending CI

Testing

All 7 new tests pass, and the full test_Cube.py suite shows no regressions:

lib/iris/tests/unit/cube/test_Cube.py::Test_coord_dims ... 7 passed
lib/iris/tests/unit/cube/test_Cube.py ... 497 passed, 34 skipped

ruff check and ruff format --check both pass with no warnings.

Copilot AI review requested due to automatic review settings July 10, 2026 17:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@CLAassistant

CLAassistant commented Jul 10, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@stephenworsley

Copy link
Copy Markdown
Contributor

From @SciTools/peloton: Hi @01luyicheng, thanks for the PR, we'll get this reviewed soon, in the mean time, we just need you to sign the CLA (linked here #7198 (comment)).

@01luyicheng

Copy link
Copy Markdown
Contributor Author

Hi, the CLA is signed now - looking forward to the review. Thanks!

@ESadek-MO ESadek-MO self-assigned this Jul 23, 2026
@codecov

codecov Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.42%. Comparing base (c2ffc9b) to head (5ce7b9a).
⚠️ Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7198      +/-   ##
==========================================
+ Coverage   90.18%   90.42%   +0.23%     
==========================================
  Files          91       93       +2     
  Lines       25102    25812     +710     
  Branches     4706     4795      +89     
==========================================
+ Hits        22638    23340     +702     
- Misses       1685     1693       +8     
  Partials      779      779              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ESadek-MO ESadek-MO left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @01luyicheng, thanks so much for tackling this!

I've got a couple of comments; the only problems I've found thus far are readability concerns, the code itself all looks great!

Comment thread lib/iris/tests/unit/cube/test_Cube.py Outdated
Comment thread lib/iris/tests/unit/cube/test_Cube.py Outdated
Comment thread lib/iris/tests/unit/cube/test_Cube.py
Address review feedback from @ESadek-MO:
- Move hybrid-height set-up into the single test that uses it
- Group _setup into clear blocks: cube → DimCoords → AuxCoords → assigns
@01luyicheng

Copy link
Copy Markdown
Contributor Author

Hi @ESadek-MO,

Thanks so much for the review and the kind words! I've just pushed an update (commit 8d101a2) that addresses both points:

  1. Hybrid-height set-up moved: The delta/sigma/orography/factory construction was only used by test_aux_factory, so I've moved it into that test method rather than keeping it in the shared _setup (and dropped the now-unused self.factory assignment).
  2. _setup restructured: Reorganized into clearly separated, blank-line-delimited blocks — cube construction → DimCoords (and adds) → AuxCoords (and adds) → assignment to class variables — matching the order you suggested.

No test logic or assertions were changed. Let me know if you'd prefer the hybrid-height set-up extracted into its own fixture instead of inlined into the test; happy to switch it over.

Thanks again for your time!

@01luyicheng

Copy link
Copy Markdown
Contributor Author

Hi @ESadek-MO, just a gentle follow-up on the changes I pushed in 8d101a2 — the _setup is now broken into blank-line-delimited blocks (cube → DimCoords → AuxCoords → class-variable assignment) and the hybrid-height delta/sigma/orography/factory construction has been moved into test_aux_factory, since it's the only test using it. No assertions or test logic were changed, and Codecov is green.

I'm still happy to extract the hybrid-height set-up into a fixture if you'd prefer that over inlining it in the test — just say the word and I'll switch it over. No rush at all on my end; thanks again for the review!

@ESadek-MO ESadek-MO left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @01luyicheng, apologies it took a while to get back to you, resource was a little bit tight over the last couple of days.

Please could you put all the hybrid height set-up into a fixture? On discussing with the rest of the team, we think that having a fixture is the best practice due to PyTest's ability to isolate the failures. Apologies to change my mind there!

As an aside, can I confirm that this is AI assisted development? It has a certain amount of AI hallmarks, not least the large number of comments. That isn't a problem, we just like to be sure.

Address review feedback from @ESadek-MO on SciTools#7198: move the hybrid-height
construction (delta/sigma/orography, HybridHeightFactory, add_aux_factory)
out of the test body and into its own pytest fixture, so that set-up
failures can be isolated by PyTest.
@01luyicheng

Copy link
Copy Markdown
Contributor Author

Hi @ESadek-MO, just a gentle nudge — I've addressed the requested changes by moving the hybrid-height set-up into a dedicated fixture (commit 5ce7b9a). Could you please re-review when you have a moment? Happy to make further adjustments if needed. Thanks!

@ESadek-MO ESadek-MO left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with this, thanks @01luyicheng !

I think it was AI gen, but nothing problematic appears in the changes so happy to merge.

@ESadek-MO
ESadek-MO merged commit a73bc0f into SciTools:main Aug 6, 2026
22 checks passed
@scitools-ci scitools-ci Bot removed this from 🚴 Peloton Sep 4, 2026
stephenworsley added a commit that referenced this pull request Sep 18, 2026
* undo the whatsnew changes

* fix for doctest warnings

* Add unit tests for Cube.coord_dims (#7198)

* Add unit tests for Cube.coord_dims

* Add What's New changelog fragment for #4552

* Refactor Test_coord_dims._setup for readability

Address review feedback from @ESadek-MO:
- Move hybrid-height set-up into the single test that uses it
- Group _setup into clear blocks: cube → DimCoords → AuxCoords → assigns

* Move hybrid-height set-up into a dedicated fixture

Address review feedback from @ESadek-MO on #7198: move the hybrid-height
construction (delta/sigma/orography, HybridHeightFactory, add_aux_factory)
out of the test body and into its own pytest fixture, so that set-up
failures can be isolated by PyTest.

---------

Co-authored-by: 01luyicheng <01luyicheng@users.noreply.github.com>

* Bump the gha group across 1 directory with 9 updates (#7215)

Bumps the gha group with 9 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [actions/checkout](https://github.com/actions/checkout) | `7.0.0` | `7.0.1` |
| [actions/setup-python](https://github.com/actions/setup-python) | `6.3.0` | `7.0.0` |
| [lycheeverse/lychee-action](https://github.com/lycheeverse/lychee-action) | `2.8.0` | `2.9.0` |
| [scitools/workflows/.github/workflows/ci-manifest.yml](https://github.com/scitools/workflows) | `2026.06.0` | `2026.07.1` |
| [scitools/workflows/.github/workflows/ci-template-check.yml](https://github.com/scitools/workflows) | `2026.06.0` | `2026.07.1` |
| [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish) | `1.14.0` | `1.14.2` |
| [actions/labeler](https://github.com/actions/labeler) | `6.1.0` | `7.0.0` |
| [scitools/workflows/.github/workflows/refresh-lockfiles.yml](https://github.com/scitools/workflows) | `2026.06.0` | `2026.07.1` |
| [actions/stale](https://github.com/actions/stale) | `10.3.0` | `11.0.0` |



Updates `actions/checkout` from 7.0.0 to 7.0.1
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@9c091bb...3d3c42e)

Updates `actions/setup-python` from 6.3.0 to 7.0.0
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](actions/setup-python@ece7cb0...5fda3b9)

Updates `lycheeverse/lychee-action` from 2.8.0 to 2.9.0
- [Release notes](https://github.com/lycheeverse/lychee-action/releases)
- [Commits](lycheeverse/lychee-action@8646ba3...e747777)

Updates `scitools/workflows/.github/workflows/ci-manifest.yml` from 2026.06.0 to 2026.07.1
- [Release notes](https://github.com/scitools/workflows/releases)
- [Commits](SciTools/workflows@1f21414...7c41342)

Updates `scitools/workflows/.github/workflows/ci-template-check.yml` from 2026.06.0 to 2026.07.1
- [Release notes](https://github.com/scitools/workflows/releases)
- [Commits](SciTools/workflows@1f21414...7c41342)

Updates `pypa/gh-action-pypi-publish` from 1.14.0 to 1.14.2
- [Release notes](https://github.com/pypa/gh-action-pypi-publish/releases)
- [Commits](pypa/gh-action-pypi-publish@cef2210...dc37677)

Updates `actions/labeler` from 6.1.0 to 7.0.0
- [Release notes](https://github.com/actions/labeler/releases)
- [Commits](actions/labeler@f27b608...bf12e9b)

Updates `scitools/workflows/.github/workflows/refresh-lockfiles.yml` from 2026.06.0 to 2026.07.1
- [Release notes](https://github.com/scitools/workflows/releases)
- [Commits](SciTools/workflows@1f21414...7c41342)

Updates `actions/stale` from 10.3.0 to 11.0.0
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](actions/stale@eb5cf3a...4391f3d)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 7.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gha
- dependency-name: actions/labeler
  dependency-version: 7.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: gha
- dependency-name: actions/setup-python
  dependency-version: 7.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: gha
- dependency-name: actions/stale
  dependency-version: 10.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: gha
- dependency-name: lycheeverse/lychee-action
  dependency-version: 2.9.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: gha
- dependency-name: pypa/gh-action-pypi-publish
  dependency-version: 1.14.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: gha
- dependency-name: scitools/workflows/.github/workflows/ci-manifest.yml
  dependency-version: 2026.07.1
  dependency-type: direct:production
  dependency-group: gha
- dependency-name: scitools/workflows/.github/workflows/ci-template-check.yml
  dependency-version: 2026.07.1
  dependency-type: direct:production
  dependency-group: gha
- dependency-name: scitools/workflows/.github/workflows/refresh-lockfiles.yml
  dependency-version: 2026.07.1
  dependency-type: direct:production
  dependency-group: gha
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump the gha group across 1 directory with 3 updates (#7256)

Bumps the gha group with 3 updates in the / directory: [scitools/workflows/.github/workflows/ci-manifest.yml](https://github.com/scitools/workflows), [scitools/workflows/.github/workflows/ci-template-check.yml](https://github.com/scitools/workflows) and [scitools/workflows/.github/workflows/refresh-lockfiles.yml](https://github.com/scitools/workflows).


Updates `scitools/workflows/.github/workflows/ci-manifest.yml` from 2026.07.1 to 2026.08.1
- [Release notes](https://github.com/scitools/workflows/releases)
- [Commits](SciTools/workflows@7c41342...28aea7a)

Updates `scitools/workflows/.github/workflows/ci-template-check.yml` from 2026.07.1 to 2026.08.1
- [Release notes](https://github.com/scitools/workflows/releases)
- [Commits](SciTools/workflows@7c41342...28aea7a)

Updates `scitools/workflows/.github/workflows/refresh-lockfiles.yml` from 2026.07.1 to 2026.08.1
- [Release notes](https://github.com/scitools/workflows/releases)
- [Commits](SciTools/workflows@7c41342...28aea7a)

---
updated-dependencies:
- dependency-name: scitools/workflows/.github/workflows/ci-manifest.yml
  dependency-version: 2026.08.1
  dependency-type: direct:production
  dependency-group: gha
- dependency-name: scitools/workflows/.github/workflows/ci-template-check.yml
  dependency-version: 2026.08.1
  dependency-type: direct:production
  dependency-group: gha
- dependency-name: scitools/workflows/.github/workflows/refresh-lockfiles.yml
  dependency-version: 2026.08.1
  dependency-type: direct:production
  dependency-group: gha
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Fix TEST_DATA_DIR default behaviour (#7257)

* fix TEST_DATA_DIR default behaviour

* add whatsnew

* Add option for steps in Cube rolling windows (#7236)

* Add option for steps in Cube rolling windows

* Add changelog entry

* Fix bug with mesh indexing for start_index=1 (#7253)

* fix bug with mesh indexing for start_index=1

* add test

* add whatsnew

* add unit tests

* CI compatibility with PROJ 9.8 (#7254)

* CI compatibility with PROJ 9.8.

* review comments (#97)

---------

Co-authored-by: Elias <110238618+ESadek-MO@users.noreply.github.com>

* Update lock files plus test fixes (#7270)

* Updated environment lockfiles

* Temporary gallery test fix.

* Revert "Temporary gallery test fix."

This reverts commit 6403701.

* Skip Proj 9.8 incompatible gallery tests. Proven by 6403701.

* Modernise graphics tests.

* What's New entry.

---------

Co-authored-by: Lockfile bot <noreply@github.com>
Co-authored-by: Elias <110238618+ESadek-MO@users.noreply.github.com>

* DOC BLD: get scipy objects inventory from their static site (#7269)

* Move developers' conda yml to environment.yml (#7267)

* Move developers' conda yml to environment.yml

* Fix readthedocs.yml

* Add environment.yml to manifest

* Add code trial for encode/decode of lazy data.

* Some extra debug.

* Apply encode/decode to load/save shortcutting, and support lazy data.

* Small changes to support scalar character variables.

* Replace complex VariableEncoder constructor with a .from_var classmethod.

* Apply scalar adjustment whether lazy or real.

* Remove debug print.

* Extend get_cf_var to test dataset-shortcutting of strings and real/lazy data.

* Fix typo in tests.

* Remove temporary tests.

* With CoPilot: tests for handling of ncdata-style direct data transfers in '_lazy_stream_data'.

* Added changelog fragment.

* Review changes.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Henry Wright <henrywright@sky.com>
Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com>
Co-authored-by: 陆奕丞 <01luyicheng@gmail.com>
Co-authored-by: 01luyicheng <01luyicheng@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: stephenworsley <49274989+stephenworsley@users.noreply.github.com>
Co-authored-by: Andrew Creswick <89418171+mo-AndrewCreswick@users.noreply.github.com>
Co-authored-by: Elias <110238618+ESadek-MO@users.noreply.github.com>
Co-authored-by: Lockfile bot <noreply@github.com>
Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
pp-mo pushed a commit to pp-mo/iris that referenced this pull request Sep 22, 2026
* Add unit tests for Cube.coord_dims

* Add What's New changelog fragment for SciTools#4552

* Refactor Test_coord_dims._setup for readability

Address review feedback from @ESadek-MO:
- Move hybrid-height set-up into the single test that uses it
- Group _setup into clear blocks: cube → DimCoords → AuxCoords → assigns

* Move hybrid-height set-up into a dedicated fixture

Address review feedback from @ESadek-MO on SciTools#7198: move the hybrid-height
construction (delta/sigma/orography, HybridHeightFactory, add_aux_factory)
out of the test body and into its own pytest fixture, so that set-up
failures can be isolated by PyTest.

---------

Co-authored-by: 01luyicheng <01luyicheng@users.noreply.github.com>
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.

Specific unit testing of Cube.coord_dims

5 participants