-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor cube testing objects/mocking with DummyCube
#113
base: main
Are you sure you want to change the base?
Conversation
Tweak skipped pressure test with DummyCube for future implementation.
return m_air_temp | ||
def air_temp_cube(lat_river_coord, lon_river_coord): | ||
# details copied from aiihca.paa1jan.subset file | ||
air_temp = DummyCube(30204, "air_temperature", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these codes have a specific meaning, or do you just need a distinct code for each cube type? If the former, it might benefit from using a reference dict
or similar rather than having magic numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codes are in the umpost/stashvar_cmip6.py
module & I've copied them across.
A reference/index dict or constants for common stash codes could certainly help...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty straightforward to me.
My main comment (which only just occurred to me, and clearly is an existing issue) is that a lot of the test assert
statements don't have an explanatory note after them, e.g.:
assert False, "Well this will obviously fail"
It's nice to get an explanation out of pytest
as to why a test failed, rather than having to dig into the test code itself to figure out what's going on. Up to you whether this is dealt with as part of this PR, or as a new issue.
Some of this is related to the process of retro-fitting testing & the way the code operates. Quite often, a function takes inputs, modifies a cube & returns None. Error messages could make it clearer if a value hasn't been set properly. This relates to another element: being unfamiliar with why steps are done, thus not knowing what meaningful error msg to provide (or in some cases, if the code is doing the right thing). There's also a future refactoring step where I suspect simplification could result in shrinking the code & tests. At this stage I'm mainly focusing on code coverage to assist with the rework steps. |
This closes #69.
This PR covers multiple elements to switch tests to using
DummyCube
:Mock
objs masquerading as cubes withDummyCube
mock.patch("umpost.um2netcdf.fix_latlon_coords")
inprocess()
testsmock.patch("umpost.um2netcdf.fix_level_coord")
inprocess()
testsAny comments welcome!