Add unit tests for Cube.coord_dims - #7198
Conversation
|
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)). |
|
Hi, the CLA is signed now - looking forward to the review. Thanks! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7198 +/- ##
=======================================
Coverage 90.18% 90.18%
=======================================
Files 91 91
Lines 25102 25102
Branches 4706 4706
=======================================
Hits 22638 22638
Misses 1685 1685
Partials 779 779 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ESadek-MO
left a comment
There was a problem hiding this comment.
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!
| # Dependencies for a hybrid-height derived coordinate ("altitude"). | ||
| delta = AuxCoord(points=np.array([0, 1]), long_name="delta", units="m") | ||
| sigma = AuxCoord(points=np.array([0, 1]), long_name="sigma") | ||
| orography = AuxCoord( | ||
| np.arange(12).reshape(3, 4), units="m", long_name="orography" | ||
| ) | ||
| cube.add_aux_coord(delta, 0) | ||
| cube.add_aux_coord(sigma, 0) | ||
| cube.add_aux_coord(orography, (1, 2)) | ||
| factory = HybridHeightFactory(delta=delta, sigma=sigma, orography=orography) | ||
| cube.add_aux_factory(factory) |
There was a problem hiding this comment.
Since this is only used in one test, it possibly makes sense to move this to the test itself.
Normally, I'd avoid making tests unreadable, but I think in this case it's a clear enough set-up that it should be okay. Alternatively, I could see an argument for making this its own fixture.
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
|
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:
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! |
|
Hi @ESadek-MO, just a gentle follow-up on the changes I pushed in 8d101a2 — the 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
left a comment
There was a problem hiding this comment.
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.
Description
Adds specific unit tests for
Cube.coord_dims, addressing #4552.Cube.coord_dimspreviously had no direct unit tests inlib/iris/tests/unit/cube/test_Cube.py(the existingCoord.cube_dims/CellMeasure.cube_dims/AncillaryVariable.cube_dimstests only mock-verify that those methods delegate toCube.coord_dims, without exercisingcoord_dimsitself).This adds a
Test_coord_dimsclass covering the seven scenarios listed in the issue, each exercising a distinct branch of the method:test_dim_coordtest_equivalent_coord_not_instancetest_no_match_raisestest_string_nametest_aux_coord_multiple_dimstest_aux_factorytest_aux_coord_single_dimCloses #4552.
Checklist
changelog/(follow-up commit)Testing
All 7 new tests pass, and the full
test_Cube.pysuite shows no regressions:ruff checkandruff format --checkboth pass with no warnings.