Unit test coverage for cf.py - #7259
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7259 +/- ##
==========================================
+ Coverage 90.42% 90.68% +0.25%
==========================================
Files 93 93
Lines 25816 25816
Branches 4796 4796
==========================================
+ Hits 23344 23411 +67
+ Misses 1693 1650 -43
+ Partials 779 755 -24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Templating
This PR includes changes that may be worth sharing via templating. For each file listed below, please either:
- Action the suggestion via a pull request editing/adding the relevant file in the SciTools/.github
templates/directory. 1 - Raise an issue against the SciTools/.github repo for the above action if you really don't have 10mins spare right now. Include an assignee, to avoid it being forgotten.
- Dismiss the suggestion if the changes are not suitable for templating.
You will need to dismiss this review before this PR can be merged. Recommend the reviewer does this as their final action before merging, as this text will continually update as commits come in.
Template candidates
The following changed files are not currently templated, but their parent directories suggest they may be good candidates for a new template to be created:
Footnotes
-
Include this text in the PR body to avoid any notifications about applying the template changes back to the source repo!
@scitools-templating: please no update notification on: iris↩
| assert "temp" in cf_group.data_variables | ||
|
|
||
|
|
||
| class Test_translate__formula_terms_derived_bounds: |
There was a problem hiding this comment.
NOTE: I have not yet had time to validate this test class (formula terms are hard!).
There was a problem hiding this comment.
Done: a9d1ccc
I understand why the tests are written this way, and confirmed they provide 100% coverage.
BUT: I'm sorry to say that this area of the code is so difficult to understand that I've been unable to form a good model of what good 'conceptual coverage' should look like. I.e. the cases we would want to cover regardless of the chosen Iris implementation. I can pursue this further at the reviewer's request, but I can't judge myself whether it is worth it.
… multiple- cases. Extra tests needed for multiple cases only.
… once : moved to specific subclass tests.
…FVarWithDimensions.
Pp tests refactor for cf_reader_zarr branch
There was a problem hiding this comment.
Thanks for taking onboard the various tweaks which I proposed previously.
That obsoleted a lot of my pending review comments, which I've now removed.
So here, some remaining general points to think about.
I still need to take another look at the individual category tests + check I'm happy with what they do, so I might come back with some more small points.
Otherwise good!
| # | ||
| # This file is part of Iris and is released under the BSD license. | ||
| # See LICENSE in the root of the repository for full licensing details. | ||
| """Shared test catalog for CF variable identify() behaviour. |
There was a problem hiding this comment.
UPDATE Older comment, but I think it stands
I'm not really understanding this term "catalog" : I looked it up + I think the meaning is not very common usage,and rather ambiguous.
So AFAICT a "test catalog" can definitely be a thing, but I'm not sure about a "catalog test".
E.G. below, the IdentifyByAttributeCatalog docstring is
"""Catalog tests for CF variables identified via a single attribute."""
I'm not clear whether this means that it "catalogs tests", or that it "contains catalog tests".
I'm pretty sure it doesn't do the first one, and I'm still not terribly clear what the second one means -- is there such a thing as a "catalog test" + if so what is that?
Search responses only seem to riff on the idea of a "Test Catalog", which also clearly means different things in different places.
So, I'd suggest renaming this, and the classes in it.
Just something like "cf_utils" might make more sense?
I know when I've done this in the past, I've used the term "Mixin" for classes.
E.G. iris/tests/integration/fast_load/test_fast_load.py,
Mixin_FieldTest: # A mixin providing common facilities for fast-load testing
So, various of our older ones were called that, but to be fair that might only be because they originally used multiple inheritance (since unittest tests must all be in classess inheriting unittest.TestCase).
There was a problem hiding this comment.
Agreed. This was a hangover from an earlier implementation where there were a selection of tests for each module to import. Changed to Mixin.
|
|
||
| expected = {subject_name: self.CF_CLASS(subject_name, ref_subject)} | ||
| result = self.CF_CLASS.identify(vars_all) | ||
| assert expected == result |
There was a problem hiding this comment.
Tiny point
I find it more natural to always write "result == expected", read as "result equals expected".
It reads oddly to me the other way around.
I think this style can sometimes stem from translating unittest code, which goes "self.assertEqual(expected, result)" (though authors often missed this anyway!)
I suspect this was because the already-noisier syntax reads better when "expected" is a simple constant, e.g. assertEqual(1, my_long_named_thing)
There was a problem hiding this comment.
I don't think this is that small! I believe it's important for correct interpretation of PyTest output.
| ] | ||
|
|
||
|
|
||
| @pytest.fixture |
There was a problem hiding this comment.
Both of these fixtures just return a function : they don't establish a per-test context or build a fresh test object.
So I don't think making them fixtures is really useful.
Especially since most of the tests here are going to inherit from 'identify_catalogue' anyway.
So, I would just put these methods in there, and remove conftest.py altogether.
There was a problem hiding this comment.
Nice, this was another hangover from previous implementations.
Description
Ref #6977
Still lots left to do; pushing up as an advanced preview.
Disclosure: heavy use of Copilot for this one, but I have carefully reviewed the full output and made modifications where needed.
To-do
2026-08-27CFGroupcoverageCFReadercoverageCFVariablecoverageWhen I refer to full unit coverage I am talking about a dedicated test module delivering said coverage - instead of relying on incidental coverage that is accidentally provided by other unit tests.
Checklist
Important
The Iris core developers are here to help! If anything below is unclear, just post a comment asking for help 😊
(further reading)
Tip
Things you can trigger on this PR:
9999for this PR's number - to re-trigger the CLA check:https://cla-assistant.io/check/SciTools/iris?pullRequest=9999